bdk_electrum
: Handle negative heights properly
#1837
+94
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This fixes a problem with
bdk_electrum
making bogustransaction_get_merkle
calls to the Electrum server.In electrum, heights returned alongside txs may be 0 or -1. 0 means the tx is unconfirmed. -1 means the tx is unconfirmed and spends an unconfirmed tx.
Previously, the codebase assumed that heights cannot be negative and used a
i32 as usize
cast (which would lead to the casted height being 18446744073709551615). Then the codebase will try to calltransaction_get_merkle
with the overflowed height.Notes to the reviewers
The test introduced in this PR does not fail with the old codebase. What ends up happening is that
transaction_get_merke
will be called with the overflow height and the Electrum server will return with "merkle not found".To see the failure, you can change the
height as usize
casts to use.try_into().expect()
then you will see a panic.These changes should be applied as
1.0.1
and1.1.1
fixes.Changelog notice
bdk_electrum
handling of negative spk-history height.Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingBugfixes:
* [ ] This pull request breaks the existing API* [ ] I'm linking the issue being fixed by this PR