Skip to content

Commit f4d7525

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 30ab411 commit f4d7525

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

lightning/src/ln/channel.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ use crate::ln::channel_state::{
5050
OutboundHTLCDetails, OutboundHTLCStateDetails,
5151
};
5252
use crate::ln::channelmanager::{
53-
self, HTLCFailureMsg, HTLCSource, OpenChannelMessage, PaymentClaimDetails, PendingHTLCInfo,
54-
PendingHTLCStatus, RAACommitmentOrder, SentHTLCId, BREAKDOWN_TIMEOUT,
55-
MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
53+
self, FundingConfirmedMessage, HTLCFailureMsg, HTLCSource, OpenChannelMessage,
54+
PaymentClaimDetails, PendingHTLCInfo, PendingHTLCStatus, RAACommitmentOrder, SentHTLCId,
55+
BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
5656
};
5757
use crate::ln::interactivetxs::{
5858
calculate_change_output_value, get_output_weight, AbortReason, HandleTxCompleteResult,
@@ -5735,7 +5735,7 @@ impl FailHTLCMessageName for msgs::UpdateFailMalformedHTLC {
57355735
}
57365736

57375737
type BestBlockUpdatedRes = (
5738-
Option<msgs::ChannelReady>,
5738+
Option<FundingConfirmedMessage>,
57395739
Vec<(HTLCSource, PaymentHash)>,
57405740
Option<msgs::AnnouncementSignatures>,
57415741
);
@@ -8858,7 +8858,7 @@ where
88588858
pub fn transactions_confirmed<NS: Deref, L: Deref>(
88598859
&mut self, block_hash: &BlockHash, height: u32, txdata: &TransactionData,
88608860
chain_hash: ChainHash, node_signer: &NS, user_config: &UserConfig, logger: &L
8861-
) -> Result<(Option<msgs::ChannelReady>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8861+
) -> Result<(Option<FundingConfirmedMessage>, Option<msgs::AnnouncementSignatures>), ClosureReason>
88628862
where
88638863
NS::Target: NodeSigner,
88648864
L::Target: Logger
@@ -8919,7 +8919,7 @@ where
89198919
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
89208920
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
89218921
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
8922-
msgs = (Some(channel_ready), announcement_sigs);
8922+
msgs = (Some(FundingConfirmedMessage::Establishment(channel_ready)), announcement_sigs);
89238923
}
89248924
}
89258925
for inp in tx.input.iter() {
@@ -8964,7 +8964,7 @@ where
89648964
fn do_best_block_updated<NS: Deref, L: Deref>(
89658965
&mut self, height: u32, highest_header_time: u32,
89668966
chain_node_signer: Option<(ChainHash, &NS, &UserConfig)>, logger: &L
8967-
) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8967+
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
89688968
where
89698969
NS::Target: NodeSigner,
89708970
L::Target: Logger
@@ -8993,7 +8993,7 @@ where
89938993
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
89948994
} else { None };
89958995
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
8996-
return Ok((Some(channel_ready), timed_out_htlcs, announcement_sigs));
8996+
return Ok((Some(FundingConfirmedMessage::Establishment(channel_ready)), timed_out_htlcs, announcement_sigs));
89978997
}
89988998

89998999
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
@@ -12118,6 +12118,10 @@ where
1211812118
}
1211912119
}
1212012120

12121+
pub(super) enum FundingConfirmedMessage {
12122+
Establishment(msgs::ChannelReady),
12123+
}
12124+
1212112125
impl<
1212212126
M: Deref,
1212312127
T: Deref,
@@ -12144,7 +12148,7 @@ where
1214412148
/// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by
1214512149
/// the function.
1214612150
#[rustfmt::skip]
12147-
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
12151+
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
1214812152
(&self, height_opt: Option<u32>, f: FN) {
1214912153
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
1215012154
// during initialization prior to the chain_monitor being fully configured in some cases.
@@ -12165,27 +12169,30 @@ where
1216512169
None => true,
1216612170
Some(funded_channel) => {
1216712171
let res = f(funded_channel);
12168-
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
12172+
if let Ok((funding_confirmed_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
1216912173
for (source, payment_hash) in timed_out_pending_htlcs.drain(..) {
1217012174
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
1217112175
let data = self.get_htlc_inbound_temp_fail_data(reason);
1217212176
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
1217312177
HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context.channel_id() }));
1217412178
}
1217512179
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12176-
if let Some(channel_ready) = channel_ready_opt {
12177-
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12178-
if funded_channel.context.is_usable() {
12179-
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
12180-
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12181-
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12182-
node_id: funded_channel.context.get_counterparty_node_id(),
12183-
msg,
12184-
});
12180+
match funding_confirmed_opt {
12181+
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12182+
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12183+
if funded_channel.context.is_usable() {
12184+
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
12185+
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12186+
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12187+
node_id: funded_channel.context.get_counterparty_node_id(),
12188+
msg,
12189+
});
12190+
}
12191+
} else {
12192+
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
1218512193
}
12186-
} else {
12187-
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
12188-
}
12194+
},
12195+
None => {},
1218912196
}
1219012197

1219112198
{

0 commit comments

Comments
 (0)