Skip to content

Commit 2f6c2fb

Browse files
committed
Generalize do_chain_event signature for splicing
When processing confirmed transactions and updates to the best block, ChannelManager may be instructed to send a channel_ready message when a channel's funding transaction has confirmed and has met the required number of confirmations. A similar action is needed for sending splice_locked once splice transaction has confirmed with required number of confirmations. Generalize do_chain_event signature to allow for either scenario.
1 parent 5688166 commit 2f6c2fb

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::ln::msgs;
4040
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
4141
use crate::ln::script::{self, ShutdownScript};
4242
use crate::ln::channel_state::{ChannelShutdownState, CounterpartyForwardingInfo, InboundHTLCDetails, InboundHTLCStateDetails, OutboundHTLCDetails, OutboundHTLCStateDetails};
43-
use crate::ln::channelmanager::{self, OpenChannelMessage, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentClaimDetails, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
43+
use crate::ln::channelmanager::{self, FundingConfirmedMessage, OpenChannelMessage, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentClaimDetails, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
4444
use crate::ln::chan_utils::{
4545
CounterpartyCommitmentSecrets, HTLCOutputInCommitment, htlc_success_tx_weight,
4646
htlc_timeout_tx_weight, ChannelPublicKeys, CommitmentTransaction,
@@ -8417,7 +8417,7 @@ impl<SP: Deref> FundedChannel<SP> where
84178417
pub fn transactions_confirmed<NS: Deref, L: Deref>(
84188418
&mut self, block_hash: &BlockHash, height: u32, txdata: &TransactionData,
84198419
chain_hash: ChainHash, node_signer: &NS, user_config: &UserConfig, logger: &L
8420-
) -> Result<(Option<msgs::ChannelReady>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8420+
) -> Result<(Option<FundingConfirmedMessage>, Option<msgs::AnnouncementSignatures>), ClosureReason>
84218421
where
84228422
NS::Target: NodeSigner,
84238423
L::Target: Logger
@@ -8478,7 +8478,7 @@ impl<SP: Deref> FundedChannel<SP> where
84788478
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
84798479
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
84808480
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
8481-
msgs = (Some(channel_ready), announcement_sigs);
8481+
msgs = (Some(FundingConfirmedMessage::Establishment(channel_ready)), announcement_sigs);
84828482
}
84838483
}
84848484
for inp in tx.input.iter() {
@@ -8506,7 +8506,7 @@ impl<SP: Deref> FundedChannel<SP> where
85068506
pub fn best_block_updated<NS: Deref, L: Deref>(
85078507
&mut self, height: u32, highest_header_time: u32, chain_hash: ChainHash,
85088508
node_signer: &NS, user_config: &UserConfig, logger: &L
8509-
) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8509+
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
85108510
where
85118511
NS::Target: NodeSigner,
85128512
L::Target: Logger
@@ -8517,7 +8517,7 @@ impl<SP: Deref> FundedChannel<SP> where
85178517
fn do_best_block_updated<NS: Deref, L: Deref>(
85188518
&mut self, height: u32, highest_header_time: u32,
85198519
chain_node_signer: Option<(ChainHash, &NS, &UserConfig)>, logger: &L
8520-
) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8520+
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
85218521
where
85228522
NS::Target: NodeSigner,
85238523
L::Target: Logger
@@ -8546,7 +8546,7 @@ impl<SP: Deref> FundedChannel<SP> where
85468546
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
85478547
} else { None };
85488548
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
8549-
return Ok((Some(channel_ready), timed_out_htlcs, announcement_sigs));
8549+
return Ok((Some(FundingConfirmedMessage::Establishment(channel_ready)), timed_out_htlcs, announcement_sigs));
85508550
}
85518551

85528552
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||

lightning/src/ln/channelmanager.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11701,6 +11701,10 @@ where
1170111701
}
1170211702
}
1170311703

11704+
pub(super) enum FundingConfirmedMessage {
11705+
Establishment(msgs::ChannelReady),
11706+
}
11707+
1170411708
impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
1170511709
where
1170611710
M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
@@ -11716,7 +11720,7 @@ where
1171611720
/// Calls a function which handles an on-chain event (blocks dis/connected, transactions
1171711721
/// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by
1171811722
/// the function.
11719-
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
11723+
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
1172011724
(&self, height_opt: Option<u32>, f: FN) {
1172111725
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
1172211726
// during initialization prior to the chain_monitor being fully configured in some cases.
@@ -11737,27 +11741,30 @@ where
1173711741
None => true,
1173811742
Some(funded_channel) => {
1173911743
let res = f(funded_channel);
11740-
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
11744+
if let Ok((funding_confirmed_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
1174111745
for (source, payment_hash) in timed_out_pending_htlcs.drain(..) {
1174211746
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
1174311747
let data = self.get_htlc_inbound_temp_fail_data(reason);
1174411748
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
1174511749
HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context.channel_id() }));
1174611750
}
1174711751
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
11748-
if let Some(channel_ready) = channel_ready_opt {
11749-
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
11750-
if funded_channel.context.is_usable() {
11751-
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
11752-
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
11753-
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
11754-
node_id: funded_channel.context.get_counterparty_node_id(),
11755-
msg,
11756-
});
11752+
match funding_confirmed_opt {
11753+
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
11754+
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
11755+
if funded_channel.context.is_usable() {
11756+
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
11757+
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
11758+
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
11759+
node_id: funded_channel.context.get_counterparty_node_id(),
11760+
msg,
11761+
});
11762+
}
11763+
} else {
11764+
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
1175711765
}
11758-
} else {
11759-
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
11760-
}
11766+
},
11767+
None => {},
1176111768
}
1176211769

1176311770
{

0 commit comments

Comments
 (0)