Skip to content

Commit bb13acb

Browse files
committed
Add ChannelContext::get_funding_spk
1 parent e711b26 commit bb13acb

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

lightning/src/ln/channel.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::ln::channel_state::{ChannelShutdownState, CounterpartyForwardingInfo,
4040
use crate::ln::channelmanager::{self, OpenChannelMessage, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentClaimDetails, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
4141
use crate::ln::chan_utils::{
4242
CounterpartyCommitmentSecrets, TxCreationKeys, HTLCOutputInCommitment, htlc_success_tx_weight,
43-
htlc_timeout_tx_weight, make_funding_redeemscript, ChannelPublicKeys, CommitmentTransaction,
43+
htlc_timeout_tx_weight, ChannelPublicKeys, CommitmentTransaction,
4444
HolderCommitmentTransaction, ChannelTransactionParameters,
4545
CounterpartyChannelTransactionParameters, MAX_HTLCS,
4646
get_commitment_transaction_number_obscure_factor,
@@ -1823,7 +1823,7 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
18231823
return Err(ChannelError::close("Failed to advance holder commitment point".to_owned()));
18241824
}
18251825

1826-
let funding_txo_script = context.get_funding_redeemscript().to_p2wsh();
1826+
let funding_txo_script = context.get_funding_spk();
18271827
let funding_txo = context.get_funding_txo().unwrap();
18281828
let obscure_factor = get_commitment_transaction_number_obscure_factor(&context.get_holder_pubkeys().payment_point, &context.get_counterparty_pubkeys().payment_point, context.is_outbound());
18291829
let shutdown_script = context.shutdown_scriptpubkey.clone().map(|script| script.into_inner());
@@ -1973,7 +1973,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
19731973
let transaction_number = self.unfunded_context.transaction_number();
19741974

19751975
let mut output_index = None;
1976-
let expected_spk = self.context.get_funding_redeemscript().to_p2wsh();
1976+
let expected_spk = self.context.get_funding_spk();
19771977
for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
19781978
if outp.script_pubkey() == &expected_spk && outp.value() == self.context.get_value_satoshis() {
19791979
if output_index.is_some() {
@@ -3390,11 +3390,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
33903390
TxCreationKeys::derive_new(&self.secp_ctx, &self.counterparty_cur_commitment_point.unwrap(), &counterparty_pubkeys.delayed_payment_basepoint, &counterparty_pubkeys.htlc_basepoint, revocation_basepoint, htlc_basepoint)
33913391
}
33923392

3393-
/// Gets the redeemscript for the funding transaction output (ie the funding transaction output
3394-
/// pays to get_funding_redeemscript().to_p2wsh()).
3395-
/// Panics if called before accept_channel/InboundV1Channel::new
3396-
pub fn get_funding_redeemscript(&self) -> ScriptBuf {
3397-
make_funding_redeemscript(&self.get_holder_pubkeys().funding_pubkey, self.counterparty_funding_pubkey())
3393+
pub fn get_funding_spk(&self) -> ScriptBuf {
3394+
self.holder_signer.as_ref().get_funding_spk()
33983395
}
33993396

34003397
fn counterparty_funding_pubkey(&self) -> &PublicKey {
@@ -7471,7 +7468,7 @@ impl<SP: Deref> FundedChannel<SP> where
74717468
if self.context.funding_tx_confirmation_height == 0 {
74727469
if tx.compute_txid() == funding_txo.txid {
74737470
let txo_idx = funding_txo.index as usize;
7474-
if txo_idx >= tx.output.len() || tx.output[txo_idx].script_pubkey != self.context.get_funding_redeemscript().to_p2wsh() ||
7471+
if txo_idx >= tx.output.len() || tx.output[txo_idx].script_pubkey != self.context.get_funding_spk() ||
74757472
tx.output[txo_idx].value.to_sat() != self.context.channel_value_satoshis {
74767473
if self.context.is_outbound() {
74777474
// If we generated the funding transaction and it doesn't match what it
@@ -8167,7 +8164,7 @@ impl<SP: Deref> FundedChannel<SP> where
81678164

81688165
log_trace!(logger, "Signed remote commitment tx {} (txid {}) with redeemscript {} -> {} in channel {}",
81698166
encode::serialize_hex(&commitment_stats.tx.trust().built_transaction().transaction),
8170-
&counterparty_commitment_txid, encode::serialize_hex(&self.context.get_funding_redeemscript()),
8167+
&counterparty_commitment_txid, encode::serialize_hex(&self.context.get_funding_spk()),
81718168
log_bytes!(signature.serialize_compact()[..]), &self.context.channel_id());
81728169

81738170
for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(htlcs) {
@@ -9126,7 +9123,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
91269123
is_initiator: false,
91279124
inputs_to_contribute: funding_inputs,
91289125
outputs_to_contribute: Vec::new(),
9129-
expected_remote_shared_funding_output: Some((context.get_funding_redeemscript().to_p2wsh(), context.channel_value_satoshis)),
9126+
expected_remote_shared_funding_output: Some((context.get_funding_spk(), context.channel_value_satoshis)),
91309127
}
91319128
).map_err(|_| ChannelError::Close((
91329129
"V2 channel rejected due to sender error".into(),
@@ -10515,7 +10512,7 @@ mod tests {
1051510512
node_a_chan.context.holder_dust_limit_satoshis = 1560;
1051610513

1051710514
// Node A --> Node B: funding created
10518-
let output_script = node_a_chan.context.get_funding_redeemscript();
10515+
let output_script = node_a_chan.context.get_funding_spk();
1051910516
let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
1052010517
value: Amount::from_sat(10000000), script_pubkey: output_script.clone(),
1052110518
}]};
@@ -10645,7 +10642,7 @@ mod tests {
1064510642
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
1064610643

1064710644
// Node A --> Node B: funding created
10648-
let output_script = node_a_chan.context.get_funding_redeemscript();
10645+
let output_script = node_a_chan.context.get_funding_spk();
1064910646
let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
1065010647
value: Amount::from_sat(10000000), script_pubkey: output_script.clone(),
1065110648
}]};
@@ -10834,7 +10831,7 @@ mod tests {
1083410831
node_a_chan.context.holder_dust_limit_satoshis = 1560;
1083510832

1083610833
// Node A --> Node B: funding created
10837-
let output_script = node_a_chan.context.get_funding_redeemscript();
10834+
let output_script = node_a_chan.context.get_funding_spk();
1083810835
let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
1083910836
value: Amount::from_sat(10000000), script_pubkey: output_script.clone(),
1084010837
}]};
@@ -10904,7 +10901,7 @@ mod tests {
1090410901
).unwrap();
1090510902
outbound_chan.accept_channel(&inbound_chan.get_accept_channel_message(&&logger).unwrap(), &config.channel_handshake_limits, &features).unwrap();
1090610903
let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
10907-
value: Amount::from_sat(10000000), script_pubkey: outbound_chan.context.get_funding_redeemscript(),
10904+
value: Amount::from_sat(10000000), script_pubkey: outbound_chan.context.get_funding_spk(),
1090810905
}]};
1090910906
let funding_outpoint = OutPoint{ txid: tx.compute_txid(), index: 0 };
1091010907
let funding_created = outbound_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap().unwrap();
@@ -11118,7 +11115,7 @@ mod tests {
1111811115
};
1111911116
let trusted_tx = commitment_tx.trust();
1112011117
let unsigned_tx = trusted_tx.built_transaction();
11121-
let redeemscript = chan.context.get_funding_redeemscript();
11118+
let redeemscript = chan_utils::make_funding_redeemscript(&chan.context.get_holder_pubkeys().funding_pubkey, chan.context.counterparty_funding_pubkey());
1112211119
let counterparty_signature = Signature::from_der(&<Vec<u8>>::from_hex($counterparty_sig_hex).unwrap()[..]).unwrap();
1112311120
let sighash = unsigned_tx.get_sighash_all(&redeemscript, chan.context.channel_value_satoshis);
1112411121
log_trace!(logger, "unsigned_tx = {}", serialize(&unsigned_tx.transaction).as_hex());
@@ -12021,7 +12018,7 @@ mod tests {
1202112018
).unwrap();
1202212019

1202312020
// Fund the channel with a batch funding transaction.
12024-
let output_script = node_a_chan.context.get_funding_redeemscript();
12021+
let output_script = node_a_chan.context.get_funding_spk();
1202512022
let tx = Transaction {
1202612023
version: Version::ONE,
1202712024
lock_time: LockTime::ZERO,

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5275,7 +5275,7 @@ where
52755275
is_batch_funding,
52765276
|chan| {
52775277
let mut output_index = None;
5278-
let expected_spk = chan.context.get_funding_redeemscript().to_p2wsh();
5278+
let expected_spk = chan.context.get_funding_spk();
52795279
let outpoint = match &funding {
52805280
FundingType::Checked(tx) => {
52815281
for (idx, outp) in tx.output.iter().enumerate() {
@@ -8023,7 +8023,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
80238023
match phase.get_mut().as_unfunded_outbound_v1_mut() {
80248024
Some(chan) => {
80258025
try_chan_phase_entry!(self, peer_state, chan.accept_channel(msg, &self.default_configuration.channel_handshake_limits, &peer_state.latest_features), phase);
8026-
(chan.context.get_value_satoshis(), chan.context.get_funding_redeemscript().to_p2wsh(), chan.context.get_user_id())
8026+
(chan.context.get_value_satoshis(), chan.context.get_funding_spk(), chan.context.get_user_id())
80278027
},
80288028
None => {
80298029
return Err(MsgHandleErrInternal::send_err_msg_no_close(format!("Got an unexpected accept_channel message from peer with counterparty_node_id {}", counterparty_node_id), msg.common_fields.temporary_channel_id));

0 commit comments

Comments
 (0)