Skip to content

Commit 970de70

Browse files
committed
Dump transaction version as an unsigned integer in RPC/TxToUniv
Consensus-wise we already treat it as an unsigned integer (the only rules around it are in CSV/locktime handling), but changing the underlying data type means touching consensus code for a simple cleanup change, which isn't really worth it. See-also, rust-bitcoin/rust-bitcoin#299
1 parent e653eef commit 970de70

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/release-notes-16525.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RPC changes
2+
-----------
3+
4+
Exposed transaction version numbers are now treated as unsigned 32-bit integers
5+
instead of signed 32-bit integers. This matches their treatment in consensus
6+
logic. Versions greater than 2 continue to be non-standard (matching previous
7+
behavior of smaller than 1 or greater than 2 being non-standard).

src/core_write.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
179179
{
180180
entry.pushKV("txid", tx.GetHash().GetHex());
181181
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
182-
entry.pushKV("version", tx.nVersion);
182+
// Transaction version is actually unsigned in consensus checks, just signed in memory,
183+
// so cast to unsigned before giving it to the user.
184+
entry.pushKV("version", static_cast<int64_t>(static_cast<uint32_t>(tx.nVersion)));
183185
entry.pushKV("size", (int)::GetSerializeSize(tx, PROTOCOL_VERSION));
184186
entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR);
185187
entry.pushKV("weight", GetTransactionWeight(tx));

test/functional/rpc_rawtransaction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,12 @@ def run_test(self):
417417
####################################
418418

419419
# Test the minimum transaction version number that fits in a signed 32-bit integer.
420+
# As transaction version is unsigned, this should convert to its unsigned equivalent.
420421
tx = CTransaction()
421422
tx.nVersion = -0x80000000
422423
rawtx = ToHex(tx)
423424
decrawtx = self.nodes[0].decoderawtransaction(rawtx)
424-
assert_equal(decrawtx['version'], -0x80000000)
425+
assert_equal(decrawtx['version'], 0x80000000)
425426

426427
# Test the maximum transaction version number that fits in a signed 32-bit integer.
427428
tx = CTransaction()

0 commit comments

Comments
 (0)