Fix vsize to account for sigops/datacarriercost#263
Open
kwsantiago wants to merge 11 commits intobitcoinknots:29.x-knotsfrom
Open
Fix vsize to account for sigops/datacarriercost#263kwsantiago wants to merge 11 commits intobitcoinknots:29.x-knotsfrom
kwsantiago wants to merge 11 commits intobitcoinknots:29.x-knotsfrom
Conversation
dacce1a to
7eaf139
Compare
luke-jr
reviewed
Feb 25, 2026
…traTxWeight to int64, extract FindTxUndo helper
…istency, cleanups
7eaf139 to
8f0e998
Compare
b36d848 to
c51afd6
Compare
Poll perf buffer before getblock verbosity 2, which now triggers utxocache:add via GetPolicyVirtualTransactionSize's temporary CCoinsViewCache.
There was a problem hiding this comment.
Pull request overview
This PR fixes the virtual transaction size (vsize) field in various RPC outputs and the Qt GUI to account for policy settings -bytespersigop and -datacarriercost (sigop weight and datacarrier cost), which previously weren't reflected in the reported vsize. For confirmed transactions, policy vsize is computed from block undo data; for unconfirmed transactions, it comes from the mempool entry; and for bitcoin-tx (where prevout context is unavailable), vsize is omitted entirely.
Changes:
- Introduces
node::GetPolicyVirtualTransactionSize()andnode::FindTxUndo()helper functions, along with newvector<Coin>-based overloads ofDatacarrierBytes()andCalculateExtraTxWeight(), to compute policy-adjusted vsize from prevout data. - Updates
TxToUniv()and all relevant RPC endpoints (getrawtransaction,getrawmempool,getblock,rest /tx/,signrawtransactionwithkey,signrawtransactionwithwallet,gettransaction) and the Qt GUI to pass and display the policy-adjusted vsize, with sentinel valuesPOLICY_VSIZE_DEFAULT(fallback to weight-based) andPOLICY_VSIZE_OMIT(suppress the field). - Omits vsize from
bitcoin-txJSON output (since no UTXO context is available), updates the RPC documentation to mark vsize as optional, and adjusts test infrastructure (including stripping vsize in test comparisons and fixing a USDT tracepoint timing issue).
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/core_io.h |
Adds POLICY_VSIZE_DEFAULT and POLICY_VSIZE_OMIT constants; updates TxToUniv signature |
src/core_write.cpp |
Implements conditional vsize output in TxToUniv based on policy_vsize sentinel values |
src/node/transaction.h |
Declares FindTxUndo and GetPolicyVirtualTransactionSize functions |
src/node/transaction.cpp |
Implements FindTxUndo and GetPolicyVirtualTransactionSize using prevout data and policy globals |
src/policy/policy.h |
Adds vector<Coin> overloads for DatacarrierBytes and CalculateExtraTxWeight; changes return type to int64_t |
src/policy/policy.cpp |
Implements the new vector-based overloads; changes return type from int32_t to int64_t |
src/interfaces/chain.h |
Adds getPolicyVirtualTransactionSize to Chain interface |
src/node/interfaces.cpp |
Implements Chain::getPolicyVirtualTransactionSize via mempool lookup and node:: helper |
src/interfaces/wallet.h |
Adds getPolicyVirtualTransactionSize to Wallet interface |
src/wallet/interfaces.cpp |
Delegates wallet's getPolicyVirtualTransactionSize to chain interface |
src/rpc/rawtransaction.cpp |
Updates getrawtransaction, signrawtransactionwithkey, DecodeTxDoc, and TxToJSON for policy vsize |
src/rpc/rawtransaction_util.h |
Updates SignTransactionResultToJSON signature with policy_vsize parameter |
src/rpc/rawtransaction_util.cpp |
Uses policy_vsize in feerate calculation for SignTransactionResultToJSON |
src/rpc/mempool.cpp |
Passes mempool entry's GetTxSize() as policy_vsize in MempoolTxsToJSON |
src/rpc/blockchain.cpp |
Computes policy vsize from undo data in blockToJSON |
src/rest.cpp |
Adds policy vsize lookup (undo data + mempool fallback) for rest_tx JSON response |
src/wallet/rpc/transactions.cpp |
Uses mempool-based policy vsize in gettransaction decoded output |
src/wallet/rpc/spend.cpp |
Computes policy vsize for signrawtransactionwithwallet |
src/qt/transactiondesc.cpp |
Uses policy vsize (with fallback) in Qt transaction details |
src/bitcoin-tx.cpp |
Passes POLICY_VSIZE_OMIT to suppress vsize output |
src/validation.cpp |
Changes extra_weight type from int32_t to int64_t |
test/util/test_runner.py |
Adds strip_vsize_line to handle vsize removal in bitcoin-tx JSON tests |
test/functional/interface_usdt_utxocache.py |
Moves perf buffer poll before getblock to avoid spurious tracepoints |
test/functional/feature_segwit.py |
Defensively handles optional vsize in decoderawtransaction output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #62
Accounts for
-bytespersigopand-datacarriercostpolicy settings when reporting vsize ingetrawtransaction,getrawmempool,rest /tx/,signrawtransactionwithkey,signrawtransactionwithwallet,wallet/gettransaction, and the Qt GUI. Omits vsize frombitcoin-txoutput where UTXO context is unavailable.For confirmed transactions, policy vsize is computed from block undo data. For unconfirmed transactions, it comes from the mempool entry.