Skip to content

Commit 14b7612

Browse files
jbesraatnull
andcommitted
Add channel_id to SpendableOutputs event
This will make it possible to link between SpendableOuts and ChannelMonitor - change channel_id to option so we dont break upgrade - remove unused channel_id - document channel_id - extract channel id dynamically to pass test - use contains to check channel_id in test as the events are not ordered - update docs framing - specify ldk version channel_id will be introduced in Co-authored-by: Elias Rohrer <[email protected]> Update lightning/src/events/mod.rs Co-authored-by: Elias Rohrer <[email protected]>
1 parent d4ad826 commit 14b7612

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

lightning/src/chain/channelmonitor.rs

+2-1
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

+9-2
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ pub enum Event {
673673
SpendableOutputs {
674674
/// The outputs which you should store as spendable by you.
675675
outputs: Vec<SpendableOutputDescriptor>,
676+
/// The `channel_id` indicating which channel the spendable outputs belong to.
677+
///
678+
/// This will always be `Some` for events generated by LDK versions 0.0.117 and above.
679+
channel_id: Option<[u8; 32]>,
676680
},
677681
/// This event is generated when a payment has been successfully forwarded through us and a
678682
/// forwarding fee earned.
@@ -958,10 +962,11 @@ impl Writeable for Event {
958962
// Note that we now ignore these on the read end as we'll re-generate them in
959963
// ChannelManager, we write them here only for backwards compatibility.
960964
},
961-
&Event::SpendableOutputs { ref outputs } => {
965+
&Event::SpendableOutputs { ref outputs, channel_id } => {
962966
5u8.write(writer)?;
963967
write_tlv_fields!(writer, {
964968
(0, WithoutLength(outputs), required),
969+
(1, channel_id, option),
965970
});
966971
},
967972
&Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat, expected_outbound_amount_msat, intercept_id } => {
@@ -1230,10 +1235,12 @@ impl MaybeReadable for Event {
12301235
5u8 => {
12311236
let f = || {
12321237
let mut outputs = WithoutLength(Vec::new());
1238+
let mut channel_id: Option<[u8; 32]> = None;
12331239
read_tlv_fields!(reader, {
12341240
(0, outputs, required),
1241+
(1, channel_id, option),
12351242
});
1236-
Ok(Some(Event::SpendableOutputs { outputs: outputs.0 }))
1243+
Ok(Some(Event::SpendableOutputs { outputs: outputs.0, channel_id }))
12371244
};
12381245
f()
12391246
},

lightning/src/ln/functional_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4302,7 +4302,7 @@ macro_rules! check_spendable_outputs {
43024302
let secp_ctx = Secp256k1::new();
43034303
for event in events.drain(..) {
43044304
match event {
4305-
Event::SpendableOutputs { mut outputs } => {
4305+
Event::SpendableOutputs { mut outputs, channel_id: _ } => {
43064306
for outp in outputs.drain(..) {
43074307
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());
43084308
all_outputs.push(outp);

lightning/src/ln/monitor_tests.rs

+3-2
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

+4-2
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)