Skip to content

Commit 52acbac

Browse files
committed
Add prev_ouput to NegotiatedTxInput for SIGHASH_ALL & key-spend checks
In a following commit, We'll use the contained scriptPubKeys to validate P2WPKH and P2TR key path spends and to assist in checking that signatures in provided holder witnesses use SIGHASH_ALL to prevent funds being frozen or held ransom.
1 parent 2a7d713 commit 52acbac

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,14 @@ pub(crate) struct NegotiatedTxInput {
210210
txin: TxIn,
211211
// The weight of the input including an estimate of its witness weight.
212212
weight: Weight,
213+
prev_output: TxOut,
213214
}
214215

215216
impl_writeable_tlv_based!(NegotiatedTxInput, {
216217
(1, serial_id, required),
217218
(3, txin, required),
218219
(5, weight, required),
220+
(7, prev_output, required),
219221
});
220222

221223
impl_writeable_tlv_based!(ConstructedTransaction, {
@@ -1362,6 +1364,13 @@ impl InputOwned {
13621364
InputOwned::Shared(shared) => estimate_input_weight(&shared.prev_output),
13631365
}
13641366
}
1367+
1368+
fn into_tx_in_with_prev_output(self) -> (TxIn, TxOut) {
1369+
match self {
1370+
InputOwned::Single(single) => (single.input, single.prev_output),
1371+
InputOwned::Shared(shared) => (shared.input, shared.prev_output),
1372+
}
1373+
}
13651374
}
13661375

13671376
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -1533,7 +1542,8 @@ impl InteractiveTxInput {
15331542

15341543
fn into_negotiated_input(self) -> NegotiatedTxInput {
15351544
let weight = self.input.estimate_input_weight();
1536-
NegotiatedTxInput { serial_id: self.serial_id, txin: self.input.into_tx_in(), weight }
1545+
let (txin, prev_output) = self.input.into_tx_in_with_prev_output();
1546+
NegotiatedTxInput { serial_id: self.serial_id, txin, weight, prev_output }
15371547
}
15381548
}
15391549

0 commit comments

Comments
 (0)