Skip to content

Commit 70b12af

Browse files
author
MarcoFalke
committed
Merge #16647: rpc: add weight to getmempoolentry output
17d178f doc: add release-notes for getmempoolentry weight field addition (fanquake) 9c9cc2b qa: Add RPC tests for weight in mempool entry (Daniel Edgecumbe) 54aaa78 RPC: add weight to mempool entry output (Daniel Edgecumbe) Pull request description: Rebase of #14649 (which itself was a rebase of #11256). Squash the two test related commits, and swapped out `size` usage for `vsize`. Added a commit with release notes. ACKs for top commit: emilengler: Concept ACK 17d178f instagibbs: utACK bitcoin/bitcoin@17d178f meshcollider: utACK 17d178f Tree-SHA512: 1d354c9837e0ad0afa40325de9329b9e62688d5eab4d9e1cf9b46d8ae29d08f42d903ab37a41751c2ea8f9034231b21095881b1f5d911cb542b8b06bc85dc7cd
2 parents e00ecb3 + 17d178f commit 70b12af

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

doc/release-notes-16647.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RPC changes
2+
-----------
3+
`getmempoolentry` now provides a `weight` field containing the transaction weight as defined in BIP 141.

src/rpc/blockchain.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ static std::string EntryDescriptionString()
374374
return " \"vsize\" : n, (numeric) virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted.\n"
375375
" \"size\" : n, (numeric) (DEPRECATED) same as vsize. Only returned if bitcoind is started with -deprecatedrpc=size\n"
376376
" size will be completely removed in v0.20.\n"
377+
" \"weight\" : n, (numeric) transaction weight as defined in BIP 141.\n"
377378
" \"fee\" : n, (numeric) transaction fee in " + CURRENCY_UNIT + " (DEPRECATED)\n"
378379
" \"modifiedfee\" : n, (numeric) transaction fee with fee deltas used for mining priority (DEPRECATED)\n"
379380
" \"time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n"
@@ -413,6 +414,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
413414

414415
info.pushKV("vsize", (int)e.GetTxSize());
415416
if (IsDeprecatedRPCEnabled("size")) info.pushKV("size", (int)e.GetTxSize());
417+
info.pushKV("weight", (int)e.GetTxWeight());
416418
info.pushKV("fee", ValueFromAmount(e.GetFee()));
417419
info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee()));
418420
info.pushKV("time", e.GetTime());

test/functional/feature_segwit.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,16 @@ def run_test(self):
226226
assert tx.wit.is_null() # This should not be a segwit input
227227
assert txid1 in self.nodes[0].getrawmempool()
228228

229+
tx1_hex = self.nodes[0].gettransaction(txid1)['hex']
230+
tx1 = FromHex(CTransaction(), tx1_hex)
231+
232+
# Check that wtxid is properly reported in mempool entry (txid1)
233+
assert_equal(int(self.nodes[0].getmempoolentry(txid1)["wtxid"], 16), tx1.calc_sha256(True))
234+
235+
# Check that weight and vsize are properly reported in mempool entry (txid1)
236+
assert_equal(self.nodes[0].getmempoolentry(txid1)["vsize"], (self.nodes[0].getmempoolentry(txid1)["weight"] + 3) // 4)
237+
assert_equal(self.nodes[0].getmempoolentry(txid1)["weight"], len(tx1.serialize_without_witness())*3 + len(tx1.serialize_with_witness()))
238+
229239
# Now create tx2, which will spend from txid1.
230240
tx = CTransaction()
231241
tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b''))
@@ -235,6 +245,13 @@ def run_test(self):
235245
tx = FromHex(CTransaction(), tx2_hex)
236246
assert not tx.wit.is_null()
237247

248+
# Check that wtxid is properly reported in mempool entry (txid2)
249+
assert_equal(int(self.nodes[0].getmempoolentry(txid2)["wtxid"], 16), tx.calc_sha256(True))
250+
251+
# Check that weight and vsize are properly reported in mempool entry (txid2)
252+
assert_equal(self.nodes[0].getmempoolentry(txid2)["vsize"], (self.nodes[0].getmempoolentry(txid2)["weight"] + 3) // 4)
253+
assert_equal(self.nodes[0].getmempoolentry(txid2)["weight"], len(tx.serialize_without_witness())*3 + len(tx.serialize_with_witness()))
254+
238255
# Now create tx3, which will spend from txid2
239256
tx = CTransaction()
240257
tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b""))
@@ -251,9 +268,13 @@ def run_test(self):
251268
assert txid2 in template_txids
252269
assert txid3 in template_txids
253270

254-
# Check that wtxid is properly reported in mempool entry
271+
# Check that wtxid is properly reported in mempool entry (txid3)
255272
assert_equal(int(self.nodes[0].getmempoolentry(txid3)["wtxid"], 16), tx.calc_sha256(True))
256273

274+
# Check that weight and vsize are properly reported in mempool entry (txid3)
275+
assert_equal(self.nodes[0].getmempoolentry(txid3)["vsize"], (self.nodes[0].getmempoolentry(txid3)["weight"] + 3) // 4)
276+
assert_equal(self.nodes[0].getmempoolentry(txid3)["weight"], len(tx.serialize_without_witness())*3 + len(tx.serialize_with_witness()))
277+
257278
# Mine a block to clear the gbt cache again.
258279
self.nodes[0].generate(1)
259280

0 commit comments

Comments
 (0)