Skip to content

tests: wait for nodes to reach the chain tip after mining - #1163

Open
randomlogin wants to merge 1 commit into
lightningdevkit:mainfrom
randomlogin:cbf-prep-tests
Open

randomlogin wants to merge 1 commit into
lightningdevkit:mainfrom
randomlogin:cbf-prep-tests

Conversation

@randomlogin

Copy link
Copy Markdown
Contributor

This is a prerequisite PR for compact block filter node chain source.
Contrary to all other chain sources, CBF chain source in tests is different from the node who mines blocks. That means we need to ensure the tx from chain source has been broadcast. In the same fashion we ensure that after the block has mined we received it from the mining node.

Tests assumed that a node observes a freshly mined block as soon as sync_wallets returns.

Make generate_blocks_and_wait and premine_and_distribute_funds return the new chain height, add wait_for_node_tip to poll until a node reports at least that height (syncing on every try, for pull-based sources), and use it after mining in the tests.

Other changes:

  • Let exponential_backoff_poll return None instead of panicking when it runs out of tries, and expect at the call sites.
  • Return a Result from the on-chain tx type assertions, so a failure is reported at the call site.
  • Wait for the sweep transaction to reach the mempool before mining it, and wait for the transaction before mining in
    unified_send_receive_bip21_uri, so the blocks are guaranteed to include it.
  • In lsps2_client_trusts_lsp, wait for the client's tip, which the assertions inspect, rather than the payer's.

This is a prerequisite PR for compact block filter node.
Contrary to all other chain sources, CBF chain source in tests is
different from the node who mines blocks. That means we need to ensure
the tx from chain source has been broadcast. In the same fashion we
ensure that after the block has mined we received it from the mining
node.

Tests assumed that a node observes a freshly mined block as soon as
`sync_wallets` returns.

Make `generate_blocks_and_wait` and `premine_and_distribute_funds`
return the new chain height, add `wait_for_node_tip` to poll until a node
reports at least that height (syncing on every try, for pull-based
sources), and use it after mining in the tests.

Other changes:
- Let `exponential_backoff_poll` return `None` instead of panicking when
it runs out of tries, and `expect` at the call sites.
- Return a `Result` from the on-chain tx type assertions, so a failure is
reported at the call site.
- Wait for the sweep transaction to reach the mempool before mining it,
and wait for the transaction before mining in
`unified_send_receive_bip21_uri`, so the blocks are guaranteed to
include it.
- In `lsps2_client_trusts_lsp`, wait for the client's tip, which the
assertions inspect, rather than the payer's.

Co-authored-by: febyeji <yeji.han@sf.snu.ac.kr>
@ldk-reviews-bot

ldk-reviews-bot commented Oct 13, 2026 •

Copy link
Copy Markdown

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh. a bit confused why we need these changes, can you expand?

CBF chain source in tests is different from the node who mines blocks

How is 'different'? Why would we ever be synced to a new tip before we synced..?

Comment thread tests/common/mod.rs
let new_height =
generate_blocks_and_wait(bitcoind, electrsd, blocks_to_go as usize).await;
wait_for_node_tip(node, new_height).await.expect("node hasn't synced to the tip");
wait_for_node_tip(peer_node, new_height)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused: why would we ever reach the new tip before we synced our wallets?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chain source might have not received the block propagation. We wait for the chain source tip to be the latest block we've just mined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that the wallet might not know about the new block despite we've just mined it. It might have not propagated to us.

Comment thread tests/common/mod.rs
}
assert!(tries < 20, "Reached max tries.");
if tries >= 20 {
return None;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this None value represent? If we didn't succeed in the given number of tries, we should give up, no? That's what this tries value is for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to change the location of occurred error from exponential_backoff_poll to the real caller, when we do unwrap.

None does not carry any other meaning except did not succeed in waiting.

Motivation is that when you run tests you want the exact location where something went wrong.

@randomlogin

randomlogin commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Tbh. a bit confused why we need these changes, can you expand?

CBF chain source in tests is different from the node who mines blocks

How is 'different'? Why would we ever be synced to a new tip before we synced..?

Mining node and the chain source node can be different nodes (I am speaking about CBF node).

We need to wait for propagation of both tx when we broadcast tx from the chain source to the mining node and of a block from a mining node to the chain source.

That means that after we mine something we need to wait for the tip of our chain source tip to be the latest block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants