Skip to content

Fix vsize to account for sigops/datacarriercost#263

Open
kwsantiago wants to merge 11 commits intobitcoinknots:29.x-knotsfrom
privkeyio:fix-vsize-sigops-datacarrier
Open

Fix vsize to account for sigops/datacarriercost#263
kwsantiago wants to merge 11 commits intobitcoinknots:29.x-knotsfrom
privkeyio:fix-vsize-sigops-datacarrier

Conversation

@kwsantiago
Copy link

Fixes #62

Accounts for -bytespersigop and -datacarriercost policy settings when reporting vsize in getrawtransaction, getrawmempool, rest /tx/, signrawtransactionwithkey, signrawtransactionwithwallet, wallet/gettransaction, and the Qt GUI. Omits vsize from bitcoin-tx output 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.

@kwsantiago kwsantiago force-pushed the fix-vsize-sigops-datacarrier branch 2 times, most recently from dacce1a to 7eaf139 Compare February 21, 2026 23:29
@kwsantiago kwsantiago force-pushed the fix-vsize-sigops-datacarrier branch from 7eaf139 to 8f0e998 Compare February 25, 2026 22:14
@kwsantiago kwsantiago requested a review from luke-jr February 25, 2026 22:16
@kwsantiago kwsantiago force-pushed the fix-vsize-sigops-datacarrier branch from b36d848 to c51afd6 Compare February 26, 2026 15:27
Poll perf buffer before getblock verbosity 2, which now
triggers utxocache:add via GetPolicyVirtualTransactionSize's
temporary CCoinsViewCache.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() and node::FindTxUndo() helper functions, along with new vector<Coin>-based overloads of DatacarrierBytes() and CalculateExtraTxWeight(), 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 values POLICY_VSIZE_DEFAULT (fallback to weight-based) and POLICY_VSIZE_OMIT (suppress the field).
  • Omits vsize from bitcoin-tx JSON 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.

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.

VSize fails to account for sigops/datacarriercost in many instances

3 participants