Skip to content

Commit dd17aa4

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 3333b6d commit dd17aa4

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,
@@ -8814,7 +8814,7 @@ where
88148814
pub fn transactions_confirmed<NS: Deref, L: Deref>(
88158815
&mut self, block_hash: &BlockHash, height: u32, txdata: &TransactionData,
88168816
chain_hash: ChainHash, node_signer: &NS, user_config: &UserConfig, logger: &L
8817-
) -> Result<(Option<msgs::ChannelReady>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8817+
) -> Result<(Option<FundingConfirmedMessage>, Option<msgs::AnnouncementSignatures>), ClosureReason>
88188818
where
88198819
NS::Target: NodeSigner,
88208820
L::Target: Logger
@@ -8875,7 +8875,7 @@ where
88758875
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
88768876
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
88778877
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
8878-
msgs = (Some(channel_ready), announcement_sigs);
8878+
msgs = (Some(FundingConfirmedMessage::Establishment(channel_ready)), announcement_sigs);
88798879
}
88808880
}
88818881
for inp in tx.input.iter() {
@@ -8904,7 +8904,7 @@ where
89048904
pub fn best_block_updated<NS: Deref, L: Deref>(
89058905
&mut self, height: u32, highest_header_time: u32, chain_hash: ChainHash,
89068906
node_signer: &NS, user_config: &UserConfig, logger: &L
8907-
) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8907+
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
89088908
where
89098909
NS::Target: NodeSigner,
89108910
L::Target: Logger
@@ -8916,7 +8916,7 @@ where
89168916
fn do_best_block_updated<NS: Deref, L: Deref>(
89178917
&mut self, height: u32, highest_header_time: u32,
89188918
chain_node_signer: Option<(ChainHash, &NS, &UserConfig)>, logger: &L
8919-
) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
8919+
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
89208920
where
89218921
NS::Target: NodeSigner,
89228922
L::Target: Logger
@@ -8945,7 +8945,7 @@ where
89458945
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
89468946
} else { None };
89478947
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
8948-
return Ok((Some(channel_ready), timed_out_htlcs, announcement_sigs));
8948+
return Ok((Some(FundingConfirmedMessage::Establishment(channel_ready)), timed_out_htlcs, announcement_sigs));
89498949
}
89508950

89518951
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
@@ -11962,6 +11962,10 @@ where
1196211962
}
1196311963
}
1196411964

11965+
pub(super) enum FundingConfirmedMessage {
11966+
Establishment(msgs::ChannelReady),
11967+
}
11968+
1196511969
impl<
1196611970
M: Deref,
1196711971
T: Deref,
@@ -11988,7 +11992,7 @@ where
1198811992
/// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by
1198911993
/// the function.
1199011994
#[rustfmt::skip]
11991-
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
11995+
fn do_chain_event<FN: Fn(&mut FundedChannel<SP>) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
1199211996
(&self, height_opt: Option<u32>, f: FN) {
1199311997
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
1199411998
// during initialization prior to the chain_monitor being fully configured in some cases.
@@ -12009,27 +12013,30 @@ where
1200912013
None => true,
1201012014
Some(funded_channel) => {
1201112015
let res = f(funded_channel);
12012-
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
12016+
if let Ok((funding_confirmed_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
1201312017
for (source, payment_hash) in timed_out_pending_htlcs.drain(..) {
1201412018
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
1201512019
let data = self.get_htlc_inbound_temp_fail_data(reason);
1201612020
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
1201712021
HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context.channel_id() }));
1201812022
}
1201912023
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12020-
if let Some(channel_ready) = channel_ready_opt {
12021-
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12022-
if funded_channel.context.is_usable() {
12023-
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
12024-
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12025-
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12026-
node_id: funded_channel.context.get_counterparty_node_id(),
12027-
msg,
12028-
});
12024+
match funding_confirmed_opt {
12025+
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12026+
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12027+
if funded_channel.context.is_usable() {
12028+
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context.channel_id());
12029+
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12030+
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12031+
node_id: funded_channel.context.get_counterparty_node_id(),
12032+
msg,
12033+
});
12034+
}
12035+
} else {
12036+
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
1202912037
}
12030-
} else {
12031-
log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context.channel_id());
12032-
}
12038+
},
12039+
None => {},
1203312040
}
1203412041

1203512042
{

0 commit comments

Comments
 (0)