Skip to content

Commit e9be7e2

Browse files
authored
Merge pull request #2511 from jbesraa/add-channel-id-to-spendableoutputs-event
Add channel_id to SpendableOutputs event
2 parents 0b196eb + 14b7612 commit e9be7e2

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3365,7 +3365,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33653365
OnchainEvent::MaturingOutput { descriptor } => {
33663366
log_debug!(logger, "Descriptor {} has got enough confirmations to be passed upstream", log_spendable!(descriptor));
33673367
self.pending_events.push(Event::SpendableOutputs {
3368-
outputs: vec![descriptor]
3368+
outputs: vec![descriptor],
3369+
channel_id: Some(self.funding_info.0.to_channel_id()),
33693370
});
33703371
self.spendable_txids_confirmed.push(entry.txid);
33713372
},

lightning/src/events/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,10 @@ pub enum Event {
715715
SpendableOutputs {
716716
/// The outputs which you should store as spendable by you.
717717
outputs: Vec<SpendableOutputDescriptor>,
718+
/// The `channel_id` indicating which channel the spendable outputs belong to.
719+
///
720+
/// This will always be `Some` for events generated by LDK versions 0.0.117 and above.
721+
channel_id: Option<[u8; 32]>,
718722
},
719723
/// This event is generated when a payment has been successfully forwarded through us and a
720724
/// forwarding fee earned.
@@ -1000,10 +1004,11 @@ impl Writeable for Event {
10001004
// Note that we now ignore these on the read end as we'll re-generate them in
10011005
// ChannelManager, we write them here only for backwards compatibility.
10021006
},
1003-
&Event::SpendableOutputs { ref outputs } => {
1007+
&Event::SpendableOutputs { ref outputs, channel_id } => {
10041008
5u8.write(writer)?;
10051009
write_tlv_fields!(writer, {
10061010
(0, WithoutLength(outputs), required),
1011+
(1, channel_id, option),
10071012
});
10081013
},
10091014
&Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat, expected_outbound_amount_msat, intercept_id } => {
@@ -1274,10 +1279,12 @@ impl MaybeReadable for Event {
12741279
5u8 => {
12751280
let f = || {
12761281
let mut outputs = WithoutLength(Vec::new());
1282+
let mut channel_id: Option<[u8; 32]> = None;
12771283
read_tlv_fields!(reader, {
12781284
(0, outputs, required),
1285+
(1, channel_id, option),
12791286
});
1280-
Ok(Some(Event::SpendableOutputs { outputs: outputs.0 }))
1287+
Ok(Some(Event::SpendableOutputs { outputs: outputs.0, channel_id }))
12811288
};
12821289
f()
12831290
},

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4303,7 +4303,7 @@ macro_rules! check_spendable_outputs {
43034303
let secp_ctx = Secp256k1::new();
43044304
for event in events.drain(..) {
43054305
match event {
4306-
Event::SpendableOutputs { mut outputs } => {
4306+
Event::SpendableOutputs { mut outputs, channel_id: _ } => {
43074307
for outp in outputs.drain(..) {
43084308
txn.push($keysinterface.backing.spend_spendable_outputs(&[&outp], Vec::new(), Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, None, &secp_ctx).unwrap());
43094309
all_outputs.push(outp);

lightning/src/ln/monitor_tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn chanmon_fail_from_stale_commitment() {
9595
fn test_spendable_output<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, spendable_tx: &Transaction) {
9696
let mut spendable = node.chain_monitor.chain_monitor.get_and_clear_pending_events();
9797
assert_eq!(spendable.len(), 1);
98-
if let Event::SpendableOutputs { outputs } = spendable.pop().unwrap() {
98+
if let Event::SpendableOutputs { outputs, .. } = spendable.pop().unwrap() {
9999
assert_eq!(outputs.len(), 1);
100100
let spend_tx = node.keys_manager.backing.spend_spendable_outputs(&[&outputs[0]], Vec::new(),
101101
Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, None, &Secp256k1::new()).unwrap();
@@ -2228,8 +2228,9 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
22282228
let spendable_output_events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
22292229
assert_eq!(spendable_output_events.len(), 2);
22302230
for (idx, event) in spendable_output_events.iter().enumerate() {
2231-
if let Event::SpendableOutputs { outputs } = event {
2231+
if let Event::SpendableOutputs { outputs, channel_id } = event {
22322232
assert_eq!(outputs.len(), 1);
2233+
assert!(vec![chan_b.2, chan_a.2].contains(&channel_id.unwrap()));
22332234
let spend_tx = nodes[0].keys_manager.backing.spend_spendable_outputs(
22342235
&[&outputs[0]], Vec::new(), Script::new_op_return(&[]), 253, None, &Secp256k1::new(),
22352236
).unwrap();

lightning/src/ln/reorg_tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,9 @@ fn do_test_to_remote_after_local_detection(style: ConnectStyle) {
578578

579579
let mut node_a_spendable = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
580580
assert_eq!(node_a_spendable.len(), 1);
581-
if let Event::SpendableOutputs { outputs } = node_a_spendable.pop().unwrap() {
581+
if let Event::SpendableOutputs { outputs, channel_id } = node_a_spendable.pop().unwrap() {
582582
assert_eq!(outputs.len(), 1);
583+
assert_eq!(channel_id, Some(chan_id));
583584
let spend_tx = nodes[0].keys_manager.backing.spend_spendable_outputs(&[&outputs[0]], Vec::new(),
584585
Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, None, &Secp256k1::new()).unwrap();
585586
check_spends!(spend_tx, remote_txn_b[0]);
@@ -598,8 +599,9 @@ fn do_test_to_remote_after_local_detection(style: ConnectStyle) {
598599

599600
let mut node_b_spendable = nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events();
600601
assert_eq!(node_b_spendable.len(), 1);
601-
if let Event::SpendableOutputs { outputs } = node_b_spendable.pop().unwrap() {
602+
if let Event::SpendableOutputs { outputs, channel_id } = node_b_spendable.pop().unwrap() {
602603
assert_eq!(outputs.len(), 1);
604+
assert_eq!(channel_id, Some(chan_id));
603605
let spend_tx = nodes[1].keys_manager.backing.spend_spendable_outputs(&[&outputs[0]], Vec::new(),
604606
Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, None, &Secp256k1::new()).unwrap();
605607
check_spends!(spend_tx, remote_txn_a[0]);

0 commit comments

Comments
 (0)