Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TestEnv::wait_until_electrum_sees_block to be more concrete. #1640

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

evanlinjin
Copy link
Member

Description

Before, the signature of TestEnv::wait_until_electrum_sees_block only took in a delay: Duration input. It was not clear which block we were waiting for exactly. This PR adds 2 inputs to this method: a block_height target, and an optional block_hash method. Just having the block_height method waits until Electrs sees a block at that height, and all spk histories are up to date to that block. If the caller also includes a block_hash, we wait until Electrs sees a block at the given height, also has that block hash.

We also introduce a new method: TestEnv::wait_until_electrum_tip_syncs_with_bitcoind. The method name is self-explanatory.

Notes to the reviewers

It's a breaking change for bdk_testenv. The API now makes more sense.

Changelog notice

  • Change TestEnv::wait_until_electrum_sees_block to have a height target, and an optional block hash target.
  • Add TestEnv::wait_until_electrum_tip_syncs_with_bitcoind.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@evanlinjin evanlinjin force-pushed the fix/wait_until_electrum_sees_block branch from 85b35be to 4684a43 Compare October 4, 2024 21:24
Add inputs `block_height` and `block_hash` so that it is more concrete
what exactly we are waiting for.

Introduce `TestEnv::wait_until_electrum_tip_syncs_with_bitcoind`.
@evanlinjin evanlinjin force-pushed the fix/wait_until_electrum_sees_block branch from 4684a43 to ce565ac Compare October 4, 2024 21:26
@evanlinjin evanlinjin marked this pull request as ready for review October 4, 2024 21:26
@evanlinjin evanlinjin self-assigned this Oct 4, 2024
@evanlinjin evanlinjin added the api A breaking API change label Oct 4, 2024
Comment on lines +198 to +204
// NOTE: There is a reason why we use the subscribe endpoint specifically. You may think
// just polling Electrs via Electrum for a block header at height `block_height` and
// checking whether `block_hash` matches is enough. However, having the header polling call
// up to date does not necessarily mean the spk histories are up to date. On the other hand,
// getting a notification for a new block tip does mean that the confirmed spk histories
// are up to date up to and including the new notified tip. This is all due to the internal
// workings of Electrs.
Copy link
Member Author

Choose a reason for hiding this comment

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

I may need to word this better.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about:

// NOTE: We use the subscribe endpoint because polling Electrs for a block header at 
// `block_height` and verifying the `block_hash` does not ensure that the spk histories 
// are current. In contrast, getting a notification for a new block tip ensures that the
// confirmed spk histories are current, including the new notified tip. This is a result of
// the internal workings of Electrs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

2 participants