Skip to content

Commit 6d78c3f

Browse files
committed
WIP: Add FundingNeeded event for splicing
Rather than requiring the user to pass FundingTxInputs when initiating a splice, generate a FundingNeeded event once the channel has become quiescent. This simplifies error handling and UTXO / change address clean-up by consolidating it in SpliceFailed event handling. Later, this event will be used for opportunistic contributions (i.e., when the counterparty wins quiescence or initiates), dual-funding, and RBF.
1 parent 02ec3f7 commit 6d78c3f

File tree

6 files changed

+830
-470
lines changed

6 files changed

+830
-470
lines changed

lightning/src/events/bump_transaction/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use bitcoin::secp256k1::ecdsa::Signature;
5050
use bitcoin::secp256k1::{PublicKey, Secp256k1};
5151
use bitcoin::transaction::Version;
5252
use bitcoin::{
53-
OutPoint, Psbt, PubkeyHash, ScriptBuf, Sequence, Transaction, TxIn, TxOut, WPubkeyHash, Witness,
53+
FeeRate, OutPoint, Psbt, PubkeyHash, ScriptBuf, Sequence, Transaction, TxIn, TxOut, WPubkeyHash, Witness,
5454
};
5555

5656
/// A descriptor used to sign for a commitment transaction's anchor output.
@@ -270,6 +270,12 @@ pub struct Input {
270270
pub satisfaction_weight: u64,
271271
}
272272

273+
impl_writeable_tlv_based!(Input, {
274+
(1, outpoint, required),
275+
(3, previous_utxo, required),
276+
(5, satisfaction_weight, required),
277+
});
278+
273279
/// An unspent transaction output that is available to spend resulting from a successful
274280
/// [`CoinSelection`] attempt.
275281
#[derive(Clone, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]

lightning/src/events/bump_transaction/sync.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ use core::task;
1515

1616
use crate::chain::chaininterface::BroadcasterInterface;
1717
use crate::chain::ClaimId;
18+
use crate::ln::funding::FundingTxInput;
1819
use crate::prelude::*;
1920
use crate::sign::SignerProvider;
2021
use crate::util::async_poll::{dummy_waker, AsyncResult, MaybeSend, MaybeSync};
2122
use crate::util::logger::Logger;
2223

23-
use bitcoin::{Psbt, ScriptBuf, Transaction, TxOut};
24+
use bitcoin::{FeeRate, Psbt, ScriptBuf, Transaction, TxOut};
2425

2526
use super::BumpTransactionEvent;
2627
use super::{

lightning/src/events/mod.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::blinded_path::payment::{
2525
use crate::chain::transaction;
2626
use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
2727
use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
28+
use crate::ln::funding::FundingTemplate;
2829
use crate::ln::types::ChannelId;
2930
use crate::ln::{msgs, LocalHTLCFailureReason};
3031
use crate::offers::invoice::Bolt12Invoice;
@@ -1816,6 +1817,28 @@ pub enum Event {
18161817
/// [`ChannelManager::respond_to_static_invoice_request`]: crate::ln::channelmanager::ChannelManager::respond_to_static_invoice_request
18171818
invoice_request: InvoiceRequest,
18181819
},
1820+
///
1821+
FundingNeeded {
1822+
/// The `channel_id` of the channel which you'll need to pass back into
1823+
/// [`ChannelManager::funding_contributed`].
1824+
///
1825+
/// [`ChannelManager::funding_contributed`]: crate::ln::channelmanager::ChannelManager::funding_contributed
1826+
channel_id: ChannelId,
1827+
/// The counterparty's `node_id`, which you'll need to pass back into
1828+
/// [`ChannelManager::funding_contributed`].
1829+
///
1830+
/// [`ChannelManager::funding_contributed`]: crate::ln::channelmanager::ChannelManager::funding_contributed
1831+
counterparty_node_id: PublicKey,
1832+
/// The `user_channel_id` value passed in for outbound channels, or for inbound channels if
1833+
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1834+
/// `user_channel_id` will be randomized for inbound channels.
1835+
///
1836+
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1837+
user_channel_id: u128,
1838+
1839+
///
1840+
funding_template: FundingTemplate,
1841+
},
18191842
/// Indicates that a channel funding transaction constructed interactively is ready to be
18201843
/// signed. This event will only be triggered if at least one input was contributed.
18211844
///
@@ -2347,6 +2370,20 @@ impl Writeable for Event {
23472370
(13, *contributed_outputs, optional_vec),
23482371
});
23492372
},
2373+
&Event::FundingNeeded {
2374+
ref channel_id,
2375+
ref user_channel_id,
2376+
ref counterparty_node_id,
2377+
ref funding_template,
2378+
} => {
2379+
54u8.write(writer)?;
2380+
write_tlv_fields!(writer, {
2381+
(1, channel_id, required),
2382+
(3, user_channel_id, required),
2383+
(5, counterparty_node_id, required),
2384+
(7, funding_template, required),
2385+
});
2386+
},
23502387
// Note that, going forward, all new events must only write data inside of
23512388
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
23522389
// data via `write_tlv_fields`.
@@ -2978,6 +3015,24 @@ impl MaybeReadable for Event {
29783015
};
29793016
f()
29803017
},
3018+
54u8 => {
3019+
let mut f = || {
3020+
_init_and_read_len_prefixed_tlv_fields!(reader, {
3021+
(1, channel_id, required),
3022+
(3, user_channel_id, required),
3023+
(5, counterparty_node_id, required),
3024+
(7, funding_template, required),
3025+
});
3026+
3027+
Ok(Some(Event::FundingNeeded {
3028+
channel_id: channel_id.0.unwrap(),
3029+
user_channel_id: user_channel_id.0.unwrap(),
3030+
counterparty_node_id: counterparty_node_id.0.unwrap(),
3031+
funding_template: funding_template.0.unwrap(),
3032+
}))
3033+
};
3034+
f()
3035+
},
29813036
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
29823037
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
29833038
// reads.

0 commit comments

Comments
 (0)