Skip to content

fix: avoid panic for invalid chain tip height - #592

Open
Chibey-max wants to merge 2 commits into
bitcoindevkit:masterfrom
Chibey-max:fix/invalid-chain-tip-height
Open

Chibey-max wants to merge 2 commits into
bitcoindevkit:masterfrom
Chibey-max:fix/invalid-chain-tip-height

Conversation

@Chibey-max

@Chibey-max Chibey-max commented Oct 9, 2026 •

Copy link
Copy Markdown

Closes #550

Description

Fixes a panic in transaction creation when the wallet chain tip height cannot be represented as a block-based locktime. The raw chain height remains available for coinbase maturity and UTXO filtering, while fee-sniping locktime falls back to LockTime::ZERO when conversion is not possible.

Notes to the reviewers

The regression test uses an out-of-range chain tip height and verifies that transaction creation does not panic and produces a zero locktime. This change does not add a new public error variant.

Before submitting

@github-project-automation github-project-automation Bot moved this to Triage in BDK Wallet Oct 9, 2026
@Chibey-max
Chibey-max marked this pull request as ready for review October 9, 2026 11:46
@Chibey-max
Chibey-max requested a review from a team as a code owner October 9, 2026 11:46
@Jennycj

Jennycj commented Oct 14, 2026

Copy link
Copy Markdown

Thanks for working on this @Chibey-max!
cACK 5e7a1bf

I tested it locally. The new regression test panics on master with invalid height and passes on this branch, so the out-of-range chain tip no longer crashes create_tx.

One concern: considering that a tip above 500M probably points to an error from the chain source, would it not be better to return a CreateTxError variant (e.g. InvalidChainTipHeight) rather than defaulting the locktime to 0 for this specific scenario?

@Chibey-max

Copy link
Copy Markdown
Author

Thanks for working on this @Chibey-max! cACK 5e7a1bf

I tested it locally. The new regression test panics on master with invalid height and passes on this branch, so the out-of-range chain tip no longer crashes create_tx.

One concern: considering that a tip above 500M probably points to an error from the chain source, would it not be better to return a CreateTxError variant (e.g. InvalidChainTipHeight) rather than defaulting the locktime to 0 for this specific scenario?

@Jennycj Thanks for testing this and confirming the regression behavior. I agree that returning a dedicated CreateTxError would make an invalid chain tip more explicit than silently falling back to locktime zero. I initially used zero to preserve transaction creation without a panic, but I’m happy to update the implementation to return an InvalidChainTipHeight error and adjust the regression test accordingly.

@Chibey-max

Copy link
Copy Markdown
Author

Thanks for working on this @Chibey-max! cACK 5e7a1bf
I tested it locally. The new regression test panics on master with invalid height and passes on this branch, so the out-of-range chain tip no longer crashes create_tx.
One concern: considering that a tip above 500M probably points to an error from the chain source, would it not be better to return a CreateTxError variant (e.g. InvalidChainTipHeight) rather than defaulting the locktime to 0 for this specific scenario?

@Jennycj Thanks for testing this and confirming the regression behavior. I agree that returning a dedicated CreateTxError would make an invalid chain tip more explicit than silently falling back to locktime zero. I initially used zero to preserve transaction creation without a panic, but I’m happy to update the implementation to return an InvalidChainTipHeight error and adjust the regression test accordingly.

Thanks for testing and for the suggestion. I agree that returning an explicit error is clearer than silently falling back to locktime zero. I updated the PR to add CreateTxError::InvalidChainTipHeight and changed the regression test to assert that error. The update is in commit 233b728.

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.87%. Comparing base (91d3f8e) to head (71f2d9d).

Files with missing lines Patch % Lines
src/wallet/error.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #592      +/-   ##
==========================================
- Coverage   81.87%   81.87%   -0.01%     
==========================================
  Files          25       25              
  Lines        6291     6294       +3     
  Branches      302      302              
==========================================
+ Hits         5151     5153       +2     
- Misses       1035     1036       +1     
  Partials      105      105              
Flag Coverage Δ
rust 81.87% <88.88%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thunderbiscuit

thunderbiscuit commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

@Chibey-max please rebase to pick up the latest commits on master! Note that your commits are also not PGP-signed, which is a requirement for this library. Thanks!

@Chibey-max
Chibey-max force-pushed the fix/invalid-chain-tip-height branch from 233b728 to 71f2d9d Compare November 9, 2026 20:25
@Chibey-max

Copy link
Copy Markdown
Author

@Chibey-max please rebase to pick up the latest commits on master! Note that your commits are also not PGP-signed, which is a requirement for this library. Thanks!

Thanks !!. I rebased onto the latest master and rewrote both PR commits with GPG signatures. The regression test still passes locally.

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

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

create_tx panics when chain tip height is not a valid locktime height

3 participants