wallet: enforce max_tx_weight for preset inputs #36393

pull gjija wants to merge 1 commits into bitcoin:master from gjija:wallet-preset-input-weight-limit changing 2 files +14 −3
  1. gjija commented at 2:47 PM on September 30, 2026: none

    fundrawtransaction was not respecting max_tx_weight in one case.

    If the provided inputs were already enough to fund the transaction, coin selection returned early. The final weight check then used the standard 400,000 WU ceiling instead of the requested max_tx_weight.

    I reproduced this with 10 legacy inputs and max_tx_weight=4000. Funding succeeded even though the transaction was 6,168 WU after signing. Same result with both add_inputs=false and add_inputs=true.

    The fix is to use the configured max weight in the final check.

    For signed transactions, it checks the actual transaction weight. For unsigned transactions, it checks the estimated signed weight.

    I added a regression test for both add_inputs settings:

    • 4000 WU must fail
    • 8000 WU must fund successfully
    • after signing, the transaction must still be within the limit

    The test fails before the fix and passes after it.

    Tested on macOS arm64:

    • wallet_fundrawtransaction.py
    • wallet_send.py
    • wallet_v3_txs.py
    • live regtest reproduction

    All passed.

  2. wallet: enforce max_tx_weight for preset inputs
    Preset inputs can cover the target without passing coin selection's maximum
    weight checks. The final guard used MAX_STANDARD_TX_WEIGHT rather than the
    validated configured maximum.
    
    Use the configured maximum in the final guard for signed weights and unsigned
    signed-weight estimates. Add a regression covering both add_inputs settings
    with a rejecting lower limit and an accepting higher limit.
    904f565306
  3. DrahtBot added the label Wallet on Sep 30, 2026
  4. DrahtBot commented at 2:47 PM on September 30, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK jcastros

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. gjija marked this as ready for review on Sep 30, 2026
  6. jcastros commented at 6:18 PM on October 3, 2026: none

    I tested 904f565306.

    fundrawtransaction with 10 legacy inputs and max_tx_weight=4000 comes back "Transaction too large". On the parent, e0f16ef9a489, the same call goes through, and after signing the weight is 6,168 WU. I saw that with add_inputs true and with it false.

    wallet_fundrawtransaction.py passes on this commit. With the old check restored it dies at the new assertion.

    A v3 child made only from preset inputs is still funded when it's over the 1000 vbyte TRUC limit. Mine spent an unconfirmed v3 parent plus those legacy coins, and testmempoolaccept rejected it. On e0f16ef9a489 it gets funded too, so this commit didn't cause it. Should this final check enforce that cap as well, or do you want it as a follow-up?

    ACK 904f565306

  7. gjija commented at 7:34 PM on October 4, 2026: none

    @jcastros

    Thanks for testing. I’d keep the TRUC child-limit fix as a follow-up, since it reproduces on the parent too. This PR is focused on honoring max_tx_weight when the preset inputs are sufficient.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-10-11 11:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me