Skip to content

Commit 3582726

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 f7e2f0c commit 3582726

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
@@ -38,7 +38,7 @@ use crate::ln::msgs;
3838
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
3939
use crate::ln::script::{self, ShutdownScript};
4040
use crate::ln::channel_state::{ChannelShutdownState, CounterpartyForwardingInfo, InboundHTLCDetails, InboundHTLCStateDetails, OutboundHTLCDetails, OutboundHTLCStateDetails};
41-
use crate::ln::channelmanager::{self, OpenChannelMessage, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentClaimDetails, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
41+
use crate::ln::channelmanager::{self, FundingConfirmedMessage, OpenChannelMessage, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentClaimDetails, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
4242
use crate::ln::chan_utils::{
4343
CounterpartyCommitmentSecrets, HTLCOutputInCommitment, htlc_success_tx_weight,
4444
htlc_timeout_tx_weight, ChannelPublicKeys, CommitmentTransaction,
@@ -8156,7 +8156,7 @@ impl<SP: Deref> FundedChannel<SP> where
81568156
pub fn transactions_confirmed<NS: Deref, L: Deref>(
81578157
&mut self, block_hash: &BlockHash, height: u32, txdata: &TransactionData,
81588158
chain_hash: ChainHash, node_signer: &NS, user_config: &UserConfig, logger: &L
8159-
) -> Result<(Option<msgs::ChannelReady>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8159+
) -> Result<(Option<FundingConfirmedMessage>, Option<msgs::AnnouncementSignatures>), ClosureReason>
81608160
where
81618161
NS::Target: NodeSigner,
81628162
L::Target: Logger
@@ -8236,7 +8236,7 @@ impl<SP: Deref> FundedChannel<SP> where
82368236
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
82378237
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
82388238
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
8239-
return Ok((Some(channel_ready), announcement_sigs));
8239+
return Ok((Some(FundingConfirmedMessage::Establishment(channel_ready)), announcement_sigs));
82408240
}
82418241
}
82428242

@@ -8257,7 +8257,7 @@ impl<SP: Deref> FundedChannel<SP> where
82578257
pub fn best_block_updated<NS: Deref, L: Deref>(
82588258
&mut self, height: u32, highest_header_time: u32, chain_hash: ChainHash,
82598259
node_signer: &NS, user_config: &UserConfig, logger: &L
8260-
) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8260+
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
82618261
where
82628262
NS::Target: NodeSigner,
82638263
L::Target: Logger
@@ -8268,7 +8268,7 @@ impl<SP: Deref> FundedChannel<SP> where
82688268
fn do_best_block_updated<NS: Deref, L: Deref>(
82698269
&mut self, height: u32, highest_header_time: u32,
82708270
chain_node_signer: Option<(ChainHash, &NS, &UserConfig)>, logger: &L
8271-
) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8271+
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
82728272
where
82738273
NS::Target: NodeSigner,
82748274
L::Target: Logger
@@ -8297,7 +8297,7 @@ impl<SP: Deref> FundedChannel<SP> where
82978297
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
82988298
} else { None };
82998299
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
8300-
return Ok((Some(channel_ready), timed_out_htlcs, announcement_sigs));
8300+
return Ok((Some(FundingConfirmedMessage::Establishment(channel_ready)), timed_out_htlcs, announcement_sigs));
83018301
}
83028302

83038303
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
@@ -11662,6 +11662,10 @@ where
1166211662
}
1166311663
}
1166411664

11665+
pub(super) enum FundingConfirmedMessage {
11666+
Establishment(msgs::ChannelReady),
11667+
}
11668+
1166511669
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>
1166611670
where
1166711671
M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
@@ -11677,7 +11681,7 @@ where
1167711681
/// Calls a function which handles an on-chain event (blocks dis/connected, transactions
1167811682
/// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by
1167911683
/// the function.
11680-
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
11684+
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
1168111685
(&self, height_opt: Option<u32>, f: FN) {
1168211686
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
1168311687
// during initialization prior to the chain_monitor being fully configured in some cases.
@@ -11698,27 +11702,30 @@ where
1169811702
None => true,
1169911703
Some(funded_channel) => {
1170011704
let res = f(funded_channel);
11701-
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
11705+
if let Ok((funding_confirmed_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
1170211706
for (source, payment_hash) in timed_out_pending_htlcs.drain(..) {
1170311707
let failure_code = 0x1000|14; /* expiry_too_soon */
1170411708
let data = self.get_htlc_inbound_temp_fail_data(failure_code);
1170511709
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(failure_code, data),
1170611710
HTLCDestination::NextHopChannel { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context.channel_id() }));
1170711711
}
1170811712
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
11709-
if let Some(channel_ready) = channel_ready_opt {
11710-
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
11711-
if funded_channel.context.is_usable() {
11712-
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
11713-
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
11714-
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
11715-
node_id: funded_channel.context.get_counterparty_node_id(),
11716-
msg,
11717-
});
11713+
match funding_confirmed_opt {
11714+
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
11715+
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
11716+
if funded_channel.context.is_usable() {
11717+
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
11718+
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
11719+
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
11720+
node_id: funded_channel.context.get_counterparty_node_id(),
11721+
msg,
11722+
});
11723+
}
11724+
} else {
11725+
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
1171811726
}
11719-
} else {
11720-
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
11721-
}
11727+
},
11728+
None => {}
1172211729
}
1172311730

1172411731
{

0 commit comments

Comments
 (0)