Skip to content

Fix/rellocktime error#404

Open
AmosOO7 wants to merge 1 commit intobitcoindevkit:masterfrom
AmosOO7:fix/rellocktime-error
Open

Fix/rellocktime error#404
AmosOO7 wants to merge 1 commit intobitcoindevkit:masterfrom
AmosOO7:fix/rellocktime-error

Conversation

@AmosOO7
Copy link

@AmosOO7 AmosOO7 commented Mar 13, 2026

Summary

This PR fixes a panic that occurred when the descriptor! DSL macro was invoked with an out-of-range relative locktime value. Prior to this change, older(<value>) used .expect("valid \RelLockTime`")onRelLockTime::from_consensus(), which panicked if the supplied value did not fit within the 24-bit consensus limit. The new implementation returns a proper error instead, bringing the macro in line with usual Result`-based
error handling elsewhere in the library.

Changes

  • Added DescriptorError::RelLockTime(miniscript::RelLockTimeError) variant plus Display and From impls.
  • Updated dsl.rs older rule to match on the result of RelLockTime::from_consensus() and propagate errors.
  • Added comprehensive tests in tests/test_rellocktime_issue.rs:
    • valid common and boundary values
    • invalid values now return an error, not panic
    • demonstration of proper error handling
  • Updated documentation/comments and improved test coverage.

No public API changes were made; the fix affects only the macro and error enum.

Testing

All existing tests (cargo test) continue to pass. Added a new test_rellocktime_issue.rs test file exercising the DSL macro directly, and ran full descriptor and wallet test suites to ensure there are no
regressions. All tests currently succeed.

Review Notes

  • RelLockTimeError already provides a helpful Display implementation courtesy of the miniscript crate; the error variant simply wraps it.
  • The fix is small and isolated; it should be straightforward to backport to earlier releases if needed.

Checklist

Bugfixes:

  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Related issue

Closes #403


Thanks for the review! This is a small but important stability fix that prevents unexpected panics when using the DSL macros programmatically.

@luisschwab
Copy link
Member

@AmosOO7 you need to squash these two commits

The `descriptor!` DSL previously used `.expect("valid \`RelLockTime\`")` when converting an integer into `miniscript::RelLockTime`, causing a panic
for out-of-range values (e.g. values with the high bit set).

This change matches on `RelLockTime::from_consensus(...)` and returns `DescriptorError::RelLockTime(...)` for invalid values, so callers can
handle errors cleanly instead of crashing.

Includes new tests verifying valid/invalid values and ensuring the macro no longer panics.

Ran cargo fmt and cargo clippy, and just p
@AmosOO7 AmosOO7 force-pushed the fix/rellocktime-error branch from 3fc4208 to 0d20401 Compare March 13, 2026 13:47
@AmosOO7
Copy link
Author

AmosOO7 commented Mar 13, 2026

Done, thanks @luisschwab

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.76%. Comparing base (92e683b) to head (0d20401).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/descriptor/error.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #404      +/-   ##
==========================================
- Coverage   79.77%   79.76%   -0.02%     
==========================================
  Files          24       24              
  Lines        5266     5283      +17     
  Branches      241      241              
==========================================
+ Hits         4201     4214      +13     
- Misses        988      992       +4     
  Partials       77       77              
Flag Coverage Δ
rust 79.76% <0.00%> (-0.02%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@ValuedMammal ValuedMammal moved this to In Progress in BDK Wallet Mar 13, 2026
@ValuedMammal ValuedMammal added the bug Something isn't working label Mar 13, 2026
@ValuedMammal ValuedMammal added this to the Wallet 3.0.0 milestone Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Bug: panic in DSL macro when using invalid RelLockTime value

3 participants