Skip to content

Commit 982fd2b

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 60fb2f4 commit 982fd2b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 16 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, {
@@ -1358,6 +1360,13 @@ impl InputOwned {
13581360
InputOwned::Shared(shared) => estimate_input_weight(&shared.prev_output),
13591361
}
13601362
}
1363+
1364+
fn prev_output(&self) -> &TxOut {
1365+
match self {
1366+
InputOwned::Single(single) => &single.prev_output,
1367+
InputOwned::Shared(shared) => &shared.prev_output,
1368+
}
1369+
}
13611370
}
13621371

13631372
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -1529,7 +1538,13 @@ impl InteractiveTxInput {
15291538

15301539
fn into_negotiated_input(self) -> NegotiatedTxInput {
15311540
let weight = self.input.estimate_input_weight();
1532-
NegotiatedTxInput { serial_id: self.serial_id, txin: self.input.into_tx_in(), weight }
1541+
let prev_output = self.input.prev_output().clone();
1542+
NegotiatedTxInput {
1543+
serial_id: self.serial_id,
1544+
txin: self.input.into_tx_in(),
1545+
weight,
1546+
prev_output,
1547+
}
15331548
}
15341549
}
15351550

0 commit comments

Comments
 (0)