Skip to content

Commit 4b47d3c

Browse files
committed
Fix to_remote output redeemscript when anchors enabled
1 parent 2bf39a6 commit 4b47d3c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,17 @@ pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, conte
608608
}
609609
}
610610

611+
/// Gets the witnessScript for the to_remote output when anchors are enabled.
612+
#[inline]
613+
pub(crate) fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> Script {
614+
Builder::new()
615+
.push_slice(&payment_point.serialize()[..])
616+
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
617+
.push_int(1)
618+
.push_opcode(opcodes::all::OP_CSV)
619+
.into_script()
620+
}
621+
611622
/// Gets the witnessScript for an anchor output from the funding public key.
612623
/// The witness in the spending input must be:
613624
/// <BIP 143 funding_signature>
@@ -1130,7 +1141,11 @@ impl CommitmentTransaction {
11301141
let mut txouts: Vec<(TxOut, Option<&mut HTLCOutputInCommitment>)> = Vec::new();
11311142

11321143
if to_countersignatory_value_sat > 0 {
1133-
let script = script_for_p2wpkh(&countersignatory_pubkeys.payment_point);
1144+
let script = if opt_anchors {
1145+
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_v0_p2wsh()
1146+
} else {
1147+
script_for_p2wpkh(&countersignatory_pubkeys.payment_point)
1148+
};
11341149
txouts.push((
11351150
TxOut {
11361151
script_pubkey: script.clone(),

0 commit comments

Comments
 (0)