Skip to content

Commit 2279899

Browse files
committed
Don't pass a latest-block-time to Channel unless we have one
When calling `Channel::best_block_updated` we pass it the timestamp of the block we're connecting so that it can track the highest timestamp it has seen. However, in some cases, we don't actually have a timestamp to pass, which `Channel::best_block_updated` will happily ignore as it always takes the `max` of its existing value. Thus, we really should pass a `None` to ensure the API is understandable, which we do here.
1 parent fea0bee commit 2279899

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

lightning/src/ln/channel.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10550,8 +10550,8 @@ where
1055010550
/// May return some HTLCs (and their payment_hash) which have timed out and should be failed
1055110551
/// back.
1055210552
pub fn best_block_updated<NS: Deref, L: Deref>(
10553-
&mut self, height: u32, highest_header_time: u32, chain_hash: ChainHash, node_signer: &NS,
10554-
user_config: &UserConfig, logger: &L,
10553+
&mut self, height: u32, highest_header_time: Option<u32>, chain_hash: ChainHash,
10554+
node_signer: &NS, user_config: &UserConfig, logger: &L,
1055510555
) -> Result<BestBlockUpdatedRes, ClosureReason>
1055610556
where
1055710557
NS::Target: NodeSigner,
@@ -10567,7 +10567,7 @@ where
1056710567

1056810568
#[rustfmt::skip]
1056910569
fn do_best_block_updated<NS: Deref, L: Deref>(
10570-
&mut self, height: u32, highest_header_time: u32,
10570+
&mut self, height: u32, highest_header_time: Option<u32>,
1057110571
chain_node_signer: Option<(ChainHash, &NS, &UserConfig)>, logger: &L
1057210572
) -> Result<(Option<FundingConfirmedMessage>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
1057310573
where
@@ -10591,7 +10591,9 @@ where
1059110591
}
1059210592
});
1059310593

10594-
self.context.update_time_counter = cmp::max(self.context.update_time_counter, highest_header_time);
10594+
if let Some(time) = highest_header_time {
10595+
self.context.update_time_counter = cmp::max(self.context.update_time_counter, time);
10596+
}
1059510597

1059610598
// Check if the funding transaction was unconfirmed
1059710599
let funding_tx_confirmations = self.funding.get_funding_tx_confirmations(height);
@@ -10747,12 +10749,9 @@ where
1074710749
// We handle the funding disconnection by calling best_block_updated with a height one
1074810750
// below where our funding was connected, implying a reorg back to conf_height - 1.
1074910751
let reorg_height = funding.funding_tx_confirmation_height - 1;
10750-
// We use the time field to bump the current time we set on channel updates if its
10751-
// larger. If we don't know that time has moved forward, we can just set it to the last
10752-
// time we saw and it will be ignored.
10753-
let best_time = self.context.update_time_counter;
1075410752

10755-
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
10753+
let signer_config = None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>;
10754+
match self.do_best_block_updated(reorg_height, None, signer_config, logger) {
1075610755
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
1075710756
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
1075810757
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");

lightning/src/ln/channelmanager.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13302,7 +13302,7 @@ where
1330213302
self.do_chain_event(Some(fork_point.height), |channel| {
1330313303
channel.best_block_updated(
1330413304
fork_point.height,
13305-
0,
13305+
None,
1330613306
self.chain_hash,
1330713307
&self.node_signer,
1330813308
&self.config.read().unwrap(),
@@ -13352,7 +13352,17 @@ where
1335213352
let last_best_block_height = self.best_block.read().unwrap().height;
1335313353
if height < last_best_block_height {
1335413354
let timestamp = self.highest_seen_timestamp.load(Ordering::Acquire);
13355-
self.do_chain_event(Some(last_best_block_height), |channel| channel.best_block_updated(last_best_block_height, timestamp as u32, self.chain_hash, &self.node_signer, &self.config.read().unwrap(), &&WithChannelContext::from(&self.logger, &channel.context, None)));
13355+
let do_update = |channel: &mut FundedChannel<SP>| {
13356+
channel.best_block_updated(
13357+
last_best_block_height,
13358+
Some(timestamp as u32),
13359+
self.chain_hash,
13360+
&self.node_signer,
13361+
&self.config.read().unwrap(),
13362+
&&WithChannelContext::from(&self.logger, &channel.context, None),
13363+
)
13364+
};
13365+
self.do_chain_event(Some(last_best_block_height), do_update);
1335613366
}
1335713367
}
1335813368

@@ -13412,7 +13422,14 @@ where
1341213422
}
1341313423
}
1341413424

13415-
channel.best_block_updated(height, header.time, self.chain_hash, &self.node_signer, &self.config.read().unwrap(), &&WithChannelContext::from(&self.logger, &channel.context, None))
13425+
channel.best_block_updated(
13426+
height,
13427+
Some(header.time),
13428+
self.chain_hash,
13429+
&self.node_signer,
13430+
&self.config.read().unwrap(),
13431+
&&WithChannelContext::from(&self.logger, &channel.context, None),
13432+
)
1341613433
});
1341713434

1341813435
macro_rules! max_time {

0 commit comments

Comments
 (0)