mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Merge pull request #2511 from jbesraa/add-channel-id-to-spendableoutputs-event
Add channel_id to SpendableOutputs event
This commit is contained in:
commit
e9be7e272f
5 changed files with 19 additions and 8 deletions
|
@ -3365,7 +3365,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
|
|||
OnchainEvent::MaturingOutput { descriptor } => {
|
||||
log_debug!(logger, "Descriptor {} has got enough confirmations to be passed upstream", log_spendable!(descriptor));
|
||||
self.pending_events.push(Event::SpendableOutputs {
|
||||
outputs: vec![descriptor]
|
||||
outputs: vec![descriptor],
|
||||
channel_id: Some(self.funding_info.0.to_channel_id()),
|
||||
});
|
||||
self.spendable_txids_confirmed.push(entry.txid);
|
||||
},
|
||||
|
|
|
@ -715,6 +715,10 @@ pub enum Event {
|
|||
SpendableOutputs {
|
||||
/// The outputs which you should store as spendable by you.
|
||||
outputs: Vec<SpendableOutputDescriptor>,
|
||||
/// The `channel_id` indicating which channel the spendable outputs belong to.
|
||||
///
|
||||
/// This will always be `Some` for events generated by LDK versions 0.0.117 and above.
|
||||
channel_id: Option<[u8; 32]>,
|
||||
},
|
||||
/// This event is generated when a payment has been successfully forwarded through us and a
|
||||
/// forwarding fee earned.
|
||||
|
@ -1000,10 +1004,11 @@ impl Writeable for Event {
|
|||
// Note that we now ignore these on the read end as we'll re-generate them in
|
||||
// ChannelManager, we write them here only for backwards compatibility.
|
||||
},
|
||||
&Event::SpendableOutputs { ref outputs } => {
|
||||
&Event::SpendableOutputs { ref outputs, channel_id } => {
|
||||
5u8.write(writer)?;
|
||||
write_tlv_fields!(writer, {
|
||||
(0, WithoutLength(outputs), required),
|
||||
(1, channel_id, option),
|
||||
});
|
||||
},
|
||||
&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 {
|
|||
5u8 => {
|
||||
let f = || {
|
||||
let mut outputs = WithoutLength(Vec::new());
|
||||
let mut channel_id: Option<[u8; 32]> = None;
|
||||
read_tlv_fields!(reader, {
|
||||
(0, outputs, required),
|
||||
(1, channel_id, option),
|
||||
});
|
||||
Ok(Some(Event::SpendableOutputs { outputs: outputs.0 }))
|
||||
Ok(Some(Event::SpendableOutputs { outputs: outputs.0, channel_id }))
|
||||
};
|
||||
f()
|
||||
},
|
||||
|
|
|
@ -4303,7 +4303,7 @@ macro_rules! check_spendable_outputs {
|
|||
let secp_ctx = Secp256k1::new();
|
||||
for event in events.drain(..) {
|
||||
match event {
|
||||
Event::SpendableOutputs { mut outputs } => {
|
||||
Event::SpendableOutputs { mut outputs, channel_id: _ } => {
|
||||
for outp in outputs.drain(..) {
|
||||
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());
|
||||
all_outputs.push(outp);
|
||||
|
|
|
@ -95,7 +95,7 @@ fn chanmon_fail_from_stale_commitment() {
|
|||
fn test_spendable_output<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, spendable_tx: &Transaction) {
|
||||
let mut spendable = node.chain_monitor.chain_monitor.get_and_clear_pending_events();
|
||||
assert_eq!(spendable.len(), 1);
|
||||
if let Event::SpendableOutputs { outputs } = spendable.pop().unwrap() {
|
||||
if let Event::SpendableOutputs { outputs, .. } = spendable.pop().unwrap() {
|
||||
assert_eq!(outputs.len(), 1);
|
||||
let spend_tx = node.keys_manager.backing.spend_spendable_outputs(&[&outputs[0]], Vec::new(),
|
||||
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() {
|
|||
let spendable_output_events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
|
||||
assert_eq!(spendable_output_events.len(), 2);
|
||||
for (idx, event) in spendable_output_events.iter().enumerate() {
|
||||
if let Event::SpendableOutputs { outputs } = event {
|
||||
if let Event::SpendableOutputs { outputs, channel_id } = event {
|
||||
assert_eq!(outputs.len(), 1);
|
||||
assert!(vec![chan_b.2, chan_a.2].contains(&channel_id.unwrap()));
|
||||
let spend_tx = nodes[0].keys_manager.backing.spend_spendable_outputs(
|
||||
&[&outputs[0]], Vec::new(), Script::new_op_return(&[]), 253, None, &Secp256k1::new(),
|
||||
).unwrap();
|
||||
|
|
|
@ -578,8 +578,9 @@ fn do_test_to_remote_after_local_detection(style: ConnectStyle) {
|
|||
|
||||
let mut node_a_spendable = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
|
||||
assert_eq!(node_a_spendable.len(), 1);
|
||||
if let Event::SpendableOutputs { outputs } = node_a_spendable.pop().unwrap() {
|
||||
if let Event::SpendableOutputs { outputs, channel_id } = node_a_spendable.pop().unwrap() {
|
||||
assert_eq!(outputs.len(), 1);
|
||||
assert_eq!(channel_id, Some(chan_id));
|
||||
let spend_tx = nodes[0].keys_manager.backing.spend_spendable_outputs(&[&outputs[0]], Vec::new(),
|
||||
Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, None, &Secp256k1::new()).unwrap();
|
||||
check_spends!(spend_tx, remote_txn_b[0]);
|
||||
|
@ -598,8 +599,9 @@ fn do_test_to_remote_after_local_detection(style: ConnectStyle) {
|
|||
|
||||
let mut node_b_spendable = nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events();
|
||||
assert_eq!(node_b_spendable.len(), 1);
|
||||
if let Event::SpendableOutputs { outputs } = node_b_spendable.pop().unwrap() {
|
||||
if let Event::SpendableOutputs { outputs, channel_id } = node_b_spendable.pop().unwrap() {
|
||||
assert_eq!(outputs.len(), 1);
|
||||
assert_eq!(channel_id, Some(chan_id));
|
||||
let spend_tx = nodes[1].keys_manager.backing.spend_spendable_outputs(&[&outputs[0]], Vec::new(),
|
||||
Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, None, &Secp256k1::new()).unwrap();
|
||||
check_spends!(spend_tx, remote_txn_a[0]);
|
||||
|
|
Loading…
Add table
Reference in a new issue