From 54aaa7883cb61d414627248e5e410180bfd8fa67 Mon Sep 17 00:00:00 2001 From: Daniel Edgecumbe Date: Thu, 7 Sep 2017 01:52:17 +0100 Subject: RPC: add weight to mempool entry output --- src/rpc/blockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index bfb6ab6a21..a74003149d 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -374,6 +374,7 @@ static std::string EntryDescriptionString() 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" " \"size\" : n, (numeric) (DEPRECATED) same as vsize. Only returned if bitcoind is started with -deprecatedrpc=size\n" " size will be completely removed in v0.20.\n" + " \"weight\" : n, (numeric) transaction weight as defined in BIP 141.\n" " \"fee\" : n, (numeric) transaction fee in " + CURRENCY_UNIT + " (DEPRECATED)\n" " \"modifiedfee\" : n, (numeric) transaction fee with fee deltas used for mining priority (DEPRECATED)\n" " \"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 info.pushKV("vsize", (int)e.GetTxSize()); if (IsDeprecatedRPCEnabled("size")) info.pushKV("size", (int)e.GetTxSize()); + info.pushKV("weight", (int)e.GetTxWeight()); info.pushKV("fee", ValueFromAmount(e.GetFee())); info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee())); info.pushKV("time", e.GetTime()); -- cgit v1.2.3 From 9c9cc2bd201afc7d519778cfcdeba5c81faa49f4 Mon Sep 17 00:00:00 2001 From: Daniel Edgecumbe Date: Fri, 8 Sep 2017 20:20:00 +0100 Subject: qa: Add RPC tests for weight in mempool entry --- test/functional/feature_segwit.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/functional/feature_segwit.py b/test/functional/feature_segwit.py index d47065d1cb..b9db618575 100755 --- a/test/functional/feature_segwit.py +++ b/test/functional/feature_segwit.py @@ -226,6 +226,16 @@ class SegWitTest(BitcoinTestFramework): assert tx.wit.is_null() # This should not be a segwit input assert txid1 in self.nodes[0].getrawmempool() + tx1_hex = self.nodes[0].gettransaction(txid1)['hex'] + tx1 = FromHex(CTransaction(), tx1_hex) + + # Check that wtxid is properly reported in mempool entry (txid1) + assert_equal(int(self.nodes[0].getmempoolentry(txid1)["wtxid"], 16), tx1.calc_sha256(True)) + + # Check that weight and vsize are properly reported in mempool entry (txid1) + assert_equal(self.nodes[0].getmempoolentry(txid1)["vsize"], (self.nodes[0].getmempoolentry(txid1)["weight"] + 3) // 4) + assert_equal(self.nodes[0].getmempoolentry(txid1)["weight"], len(tx1.serialize_without_witness())*3 + len(tx1.serialize_with_witness())) + # Now create tx2, which will spend from txid1. tx = CTransaction() tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b'')) @@ -235,6 +245,13 @@ class SegWitTest(BitcoinTestFramework): tx = FromHex(CTransaction(), tx2_hex) assert not tx.wit.is_null() + # Check that wtxid is properly reported in mempool entry (txid2) + assert_equal(int(self.nodes[0].getmempoolentry(txid2)["wtxid"], 16), tx.calc_sha256(True)) + + # Check that weight and vsize are properly reported in mempool entry (txid2) + assert_equal(self.nodes[0].getmempoolentry(txid2)["vsize"], (self.nodes[0].getmempoolentry(txid2)["weight"] + 3) // 4) + assert_equal(self.nodes[0].getmempoolentry(txid2)["weight"], len(tx.serialize_without_witness())*3 + len(tx.serialize_with_witness())) + # Now create tx3, which will spend from txid2 tx = CTransaction() tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b"")) @@ -251,9 +268,13 @@ class SegWitTest(BitcoinTestFramework): assert txid2 in template_txids assert txid3 in template_txids - # Check that wtxid is properly reported in mempool entry + # Check that wtxid is properly reported in mempool entry (txid3) assert_equal(int(self.nodes[0].getmempoolentry(txid3)["wtxid"], 16), tx.calc_sha256(True)) + # Check that weight and vsize are properly reported in mempool entry (txid3) + assert_equal(self.nodes[0].getmempoolentry(txid3)["vsize"], (self.nodes[0].getmempoolentry(txid3)["weight"] + 3) // 4) + assert_equal(self.nodes[0].getmempoolentry(txid3)["weight"], len(tx.serialize_without_witness())*3 + len(tx.serialize_with_witness())) + # Mine a block to clear the gbt cache again. self.nodes[0].generate(1) -- cgit v1.2.3 From 17d178fb9463c195c822614eb0245188e52f8371 Mon Sep 17 00:00:00 2001 From: fanquake Date: Mon, 19 Aug 2019 11:39:34 +0800 Subject: doc: add release-notes for getmempoolentry weight field addition --- doc/release-notes-16647.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 doc/release-notes-16647.md diff --git a/doc/release-notes-16647.md b/doc/release-notes-16647.md new file mode 100644 index 0000000000..7e5539cb0d --- /dev/null +++ b/doc/release-notes-16647.md @@ -0,0 +1,3 @@ +RPC changes +----------- +`getmempoolentry` now provides a `weight` field containing the transaction weight as defined in BIP 141. -- cgit v1.2.3