Skip to content

Commit 2af3413

Browse files
authored
Merge pull request #1363 from TheBlueMatt/2022-03-tx-conf-ordering-lock-delay
Generate a funding_locked on relevant transactions_confirmed calls
2 parents c244c78 + ea76942 commit 2af3413

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5505,6 +5505,12 @@ where
55055505
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
55065506
self.do_chain_event(Some(height), |channel| channel.transactions_confirmed(&block_hash, height, txdata, self.genesis_hash.clone(), self.get_our_node_id(), &self.logger)
55075507
.map(|(a, b)| (a, Vec::new(), b)));
5508+
5509+
let last_best_block_height = self.best_block.read().unwrap().height();
5510+
if height < last_best_block_height {
5511+
let timestamp = self.highest_seen_timestamp.load(Ordering::Acquire);
5512+
self.do_chain_event(Some(last_best_block_height), |channel| channel.best_block_updated(last_best_block_height, timestamp as u32, self.genesis_hash.clone(), self.get_our_node_id(), &self.logger));
5513+
}
55085514
}
55095515

55105516
fn best_block_updated(&self, header: &BlockHeader, height: u32) {

lightning/src/ln/functional_tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3940,6 +3940,32 @@ fn test_funding_peer_disconnect() {
39403940
assert!(found_announcement);
39413941
}
39423942

3943+
#[test]
3944+
fn test_funding_locked_without_best_block_updated() {
3945+
// Previously, if we were offline when a funding transaction was locked in, and then we came
3946+
// back online, calling best_block_updated once followed by transactions_confirmed, we'd not
3947+
// generate a funding_locked until a later best_block_updated. This tests that we generate the
3948+
// funding_locked immediately instead.
3949+
let chanmon_cfgs = create_chanmon_cfgs(2);
3950+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
3951+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
3952+
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
3953+
*nodes[0].connect_style.borrow_mut() = ConnectStyle::BestBlockFirstSkippingBlocks;
3954+
3955+
let funding_tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
3956+
3957+
let conf_height = nodes[0].best_block_info().1 + 1;
3958+
connect_blocks(&nodes[0], CHAN_CONFIRM_DEPTH);
3959+
let block_txn = [funding_tx];
3960+
let conf_txn: Vec<_> = block_txn.iter().enumerate().collect();
3961+
let conf_block_header = nodes[0].get_block_header(conf_height);
3962+
nodes[0].node.transactions_confirmed(&conf_block_header, &conf_txn[..], conf_height);
3963+
3964+
// Ensure nodes[0] generates a funding_locked after the transactions_confirmed
3965+
let as_funding_locked = get_event_msg!(nodes[0], MessageSendEvent::SendFundingLocked, nodes[1].node.get_our_node_id());
3966+
nodes[1].node.handle_funding_locked(&nodes[0].node.get_our_node_id(), &as_funding_locked);
3967+
}
3968+
39433969
#[test]
39443970
fn test_drop_messages_peer_disconnect_dual_htlc() {
39453971
// Test that we can handle reconnecting when both sides of a channel have pending

0 commit comments

Comments
 (0)