Skip to content

Commit 381edf3

Browse files
committed
Verify channel-monitor processes blocks with skipped best_block
1 parent b5e9594 commit 381edf3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,6 +4080,37 @@ fn test_channel_ready_without_best_block_updated() {
40804080
nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_channel_ready);
40814081
}
40824082

4083+
#[test]
4084+
fn test_channel_monitor_skipping_current_best_block() {
4085+
let chanmon_cfgs = create_chanmon_cfgs(2);
4086+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
4087+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
4088+
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
4089+
4090+
// Let ChannelManager get ahead of chainmonitor by 1 block.
4091+
// This is to emulate race-condition where newly added channel-monitor skips processing 1 block.
4092+
let height_1 = nodes[0].best_block_info().1 + 1;
4093+
let mut block_1 = create_dummy_block(nodes[0].best_block_hash(), height_1, Vec::new());
4094+
4095+
nodes[0].blocks.lock().unwrap().push((block_1.clone(), height_1));
4096+
nodes[0].node.block_connected(&block_1, height_1);
4097+
4098+
// Create channel, and it gets added to chainmonitor in funding_created.
4099+
let funding_tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 1_000_000, 0);
4100+
4101+
// Now channel-monitor in chain-monitor doesn't know about block_1, but it's best_block is block_1,
4102+
// since that was populated by channel-manager.
4103+
// Later on, subsequent blocks are connected to both channel_manager and chainmonitor.
4104+
// Hence, channel-monitor skipped block_1, directly tries to process_chain_data with subsequent blocks.
4105+
*nodes[0].connect_style.borrow_mut() = ConnectStyle::BestBlockFirst;
4106+
confirm_transaction_at(&nodes[0], &funding_tx, nodes[0].best_block_info().1 + 1);
4107+
connect_blocks(&nodes[0], CHAN_CONFIRM_DEPTH);
4108+
4109+
// Ensure nodes[0] generates a channel_ready after the transactions_confirmed
4110+
let as_channel_ready = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id());
4111+
nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_channel_ready);
4112+
}
4113+
40834114
#[test]
40844115
fn test_drop_messages_peer_disconnect_dual_htlc() {
40854116
// Test that we can handle reconnecting when both sides of a channel have pending

0 commit comments

Comments
 (0)