Skip to content

Commit 6a55dcc

Browse files
committed
Avoid unwrap'ing channel_parameters in to_counterparty signing
Previously, `StaticPaymentOutputDescriptor`s did not include `channel_parameters` for the signer. As a result, when going to spend old `StaticPaymentOutputDescriptor`s, `InMemorySigner::sign_counterparty_payment_input` may be called with `channel_parameters` set to `None`. This should be fine, but in fa2a2ef we started relying on it (indirectly via `channel_features`) for signing. This caused an `unwrap` when spending old output descriptors. This is fixed here by simply avoiding the unwrap and assuming old `StaticPaymentOutputDescriptor`s represent non-anchor channels.
1 parent 20f287f commit 6a55dcc

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lightning/src/sign/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,14 +947,20 @@ impl InMemorySigner {
947947
if spend_tx.input[input_idx].previous_output != descriptor.outpoint.into_bitcoin_outpoint() { return Err(()); }
948948

949949
let remotepubkey = bitcoin::PublicKey::new(self.pubkeys().payment_point);
950-
let witness_script = if self.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
950+
// We cannot always assume that `channel_parameters` is set, so can't just call
951+
// `self.channel_parameters()` or anything that relies on it
952+
let supports_anchors_zero_fee_htlc_tx = self.channel_parameters.as_ref()
953+
.map(|params| params.channel_type_features.supports_anchors_zero_fee_htlc_tx())
954+
.unwrap_or(false);
955+
956+
let witness_script = if supports_anchors_zero_fee_htlc_tx {
951957
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&remotepubkey.inner)
952958
} else {
953959
Script::new_p2pkh(&remotepubkey.pubkey_hash())
954960
};
955961
let sighash = hash_to_message!(&sighash::SighashCache::new(spend_tx).segwit_signature_hash(input_idx, &witness_script, descriptor.output.value, EcdsaSighashType::All).unwrap()[..]);
956962
let remotesig = sign_with_aux_rand(secp_ctx, &sighash, &self.payment_key, &self);
957-
let payment_script = if self.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
963+
let payment_script = if supports_anchors_zero_fee_htlc_tx {
958964
witness_script.to_v0_p2wsh()
959965
} else {
960966
Script::new_v0_p2wpkh(&remotepubkey.wpubkey_hash().unwrap())
@@ -965,7 +971,7 @@ impl InMemorySigner {
965971
let mut witness = Vec::with_capacity(2);
966972
witness.push(remotesig.serialize_der().to_vec());
967973
witness[0].push(EcdsaSighashType::All as u8);
968-
if self.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
974+
if supports_anchors_zero_fee_htlc_tx {
969975
witness.push(witness_script.to_bytes());
970976
} else {
971977
witness.push(remotepubkey.to_bytes());

0 commit comments

Comments
 (0)