Skip to content

Commit db06e2d

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 217a5b0 commit db06e2d

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,
@@ -8536,7 +8536,7 @@ impl<SP: Deref> FundedChannel<SP> where
85368536
pub fn transactions_confirmed<NS: Deref, L: Deref>(
85378537
&mut self, block_hash: &BlockHash, height: u32, txdata: &TransactionData,
85388538
chain_hash: ChainHash, node_signer: &NS, user_config: &UserConfig, logger: &L
8539-
) -> Result<(Option<msgs::ChannelReady>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8539+
) -> Result<(Option<FundingConfirmedMessage>, Option<msgs::AnnouncementSignatures>), ClosureReason>
85408540
where
85418541
NS::Target: NodeSigner,
85428542
L::Target: Logger
@@ -8597,7 +8597,7 @@ impl<SP: Deref> FundedChannel<SP> where
85978597
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
85988598
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
85998599
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
8600-
msgs = (Some(channel_ready), announcement_sigs);
8600+
msgs = (Some(FundingConfirmedMessage::Establishment(channel_ready)), announcement_sigs);
86018601
}
86028602
}
86038603
for inp in tx.input.iter() {
@@ -8625,7 +8625,7 @@ impl<SP: Deref> FundedChannel<SP> where
86258625
pub fn best_block_updated<NS: Deref, L: Deref>(
86268626
&mut self, height: u32, highest_header_time: u32, chain_hash: ChainHash,
86278627
node_signer: &NS, user_config: &UserConfig, logger: &L
8628-
) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8628+
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
86298629
where
86308630
NS::Target: NodeSigner,
86318631
L::Target: Logger
@@ -8636,7 +8636,7 @@ impl<SP: Deref> FundedChannel<SP> where
86368636
fn do_best_block_updated<NS: Deref, L: Deref>(
86378637
&mut self, height: u32, highest_header_time: u32,
86388638
chain_node_signer: Option<(ChainHash, &NS, &UserConfig)>, logger: &L
8639-
) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8639+
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
86408640
where
86418641
NS::Target: NodeSigner,
86428642
L::Target: Logger
@@ -8665,7 +8665,7 @@ impl<SP: Deref> FundedChannel<SP> where
86658665
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
86668666
} else { None };
86678667
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
8668-
return Ok((Some(channel_ready), timed_out_htlcs, announcement_sigs));
8668+
return Ok((Some(FundingConfirmedMessage::Establishment(channel_ready)), timed_out_htlcs, announcement_sigs));
86698669
}
86708670

86718671
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
@@ -11953,6 +11953,10 @@ where
1195311953
}
1195411954
}
1195511955

11956+
pub(super) enum FundingConfirmedMessage {
11957+
Establishment(msgs::ChannelReady),
11958+
}
11959+
1195611960
impl<
1195711961
M: Deref,
1195811962
T: Deref,
@@ -11979,7 +11983,7 @@ where
1197911983
/// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by
1198011984
/// the function.
1198111985
#[rustfmt::skip]
11982-
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
11986+
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
1198311987
(&self, height_opt: Option<u32>, f: FN) {
1198411988
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
1198511989
// during initialization prior to the chain_monitor being fully configured in some cases.
@@ -12000,27 +12004,30 @@ where
1200012004
None => true,
1200112005
Some(funded_channel) => {
1200212006
let res = f(funded_channel);
12003-
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
12007+
if let Ok((funding_confirmed_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
1200412008
for (source, payment_hash) in timed_out_pending_htlcs.drain(..) {
1200512009
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
1200612010
let data = self.get_htlc_inbound_temp_fail_data(reason);
1200712011
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
1200812012
HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context.channel_id() }));
1200912013
}
1201012014
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12011-
if let Some(channel_ready) = channel_ready_opt {
12012-
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12013-
if funded_channel.context.is_usable() {
12014-
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
12015-
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12016-
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12017-
node_id: funded_channel.context.get_counterparty_node_id(),
12018-
msg,
12019-
});
12015+
match funding_confirmed_opt {
12016+
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12017+
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12018+
if funded_channel.context.is_usable() {
12019+
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
12020+
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12021+
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12022+
node_id: funded_channel.context.get_counterparty_node_id(),
12023+
msg,
12024+
});
12025+
}
12026+
} else {
12027+
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
1202012028
}
12021-
} else {
12022-
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
12023-
}
12029+
},
12030+
None => {},
1202412031
}
1202512032

1202612033
{

0 commit comments

Comments
 (0)