Skip to content

Treat PSBT version as a minimum and auto-bump for CSV#85

Open
ANAMASGARD wants to merge 1 commit into
bitcoindevkit:masterfrom
ANAMASGARD:fix/issue-59-min-tx-version
Open

Treat PSBT version as a minimum and auto-bump for CSV#85
ANAMASGARD wants to merge 1 commit into
bitcoindevkit:masterfrom
ANAMASGARD:fix/issue-59-min-tx-version

Conversation

@ANAMASGARD

Copy link
Copy Markdown

Closes #59

Description

This PR fixes #59 by treating the transaction version in PsbtParams as a minimum version instead of an exact version.

Previously, transaction creation could fail when a selected input or anti-fee-sniping strategy required transaction version 2, but the caller requested version 1.

Now, the transaction version is automatically raised when required.

This PR:

  • Renames PsbtParams::version to PsbtParams::min_version.
  • Preserves the caller’s requested version when no feature requires a higher version.
  • Raises the transaction version to Version::TWO when a selected input requires CSV.
  • Raises the transaction version to Version::TWO when anti-fee-sniping selects the nSequence path.
  • Preserves caller-provided versions higher than version 2.
  • Removes AntiFeeSnipingError::UnsupportedVersion.
  • Updates the documentation and changelog.
  • Adds regression tests for the new behavior.

Notes to the reviewers

min_version is treated only as a lower bound.

For example:

  • min_version: Version::ONE with no CSV input remains version 1.
  • min_version: Version::ONE with a CSV input becomes version 2.
  • A version higher than 2 is not downgraded.
  • The anti-fee-sniping nLockTime path does not unnecessarily raise the version.
  • The anti-fee-sniping nSequence path raises the version to 2 when required.

The AFS sequence-path regression test uses a deterministic RNG so it does not depend on random branch selection.

Changelog notice

  • Rename PsbtParams::version to PsbtParams::min_version.
  • Automatically raise the transaction version for CSV inputs and the AFS nSequence path.
  • Remove the unsupported-version AFS error path.

Verification

The following checks passed:

cargo fmt --all -- --check
cargo test --all-features
cargo clippy --all-targets --all-features -- -D warnings
cargo check
cargo test --doc --all-features
RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps
git diff --check

cargo check --no-default-features currently fails inside miniscript because neither its std nor no-std feature is enabled. This appears to be an existing dependency-feature configuration issue and is unrelated to this change.

Before submitting

  • I followed the contribution guidelines.
  • This PR breaks the existing API.

Rename PsbtParams::version to PsbtParams::min_version and treat it as a lower bound. Selected inputs with relative timelocks (CSV) or AFS sequence-path selection now automatically raise the transaction version to Version::TWO. Remove the UnsupportedVersion error path.
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.

Remove CreatePsbtError::UnsupportedVersion variant

1 participant