Skip to content

Commit 35d928c

Browse files
josibakejonatack
andcommitted
rpc: deprecate fee fields from mempool entries
Unless `-deprecatedrpc=fees` is passed, top level fee fields are no longer returned for mempool entries. Add instructions to field help on how to access deprecated fields, update help text for readability, and include units. This is important to help avoid any confusion as users move from deprecated fields to the fee fields object (credit: jonatack). This affects `getmempoolentry`, `getrawmempool`, `getmempoolancestors`, and `getmempooldescendants` Modify `test/functional/mempool_packages.py` and `test/functional/rpc_fundrawtransaction.py` tests to no longer use deprecated fields. Co-authored-by: jonatack <[email protected]>
1 parent 5adc5c0 commit 35d928c

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

src/rpc/blockchain.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -462,23 +462,23 @@ static RPCHelpMan getdifficulty()
462462
static std::vector<RPCResult> MempoolEntryDescription() { return {
463463
RPCResult{RPCResult::Type::NUM, "vsize", "virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted."},
464464
RPCResult{RPCResult::Type::NUM, "weight", "transaction weight as defined in BIP 141."},
465-
RPCResult{RPCResult::Type::STR_AMOUNT, "fee", "transaction fee in " + CURRENCY_UNIT + " (DEPRECATED)"},
466-
RPCResult{RPCResult::Type::STR_AMOUNT, "modifiedfee", "transaction fee with fee deltas used for mining priority (DEPRECATED)"},
465+
RPCResult{RPCResult::Type::STR_AMOUNT, "fee", "transaction fee, denominated in " + CURRENCY_UNIT + " (DEPRECATED, returned only if config option -deprecatedrpc=fees is passed)"},
466+
RPCResult{RPCResult::Type::STR_AMOUNT, "modifiedfee", "transaction fee with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT + " (DEPRECATED, returned only if config option -deprecatedrpc=fees is passed)"},
467467
RPCResult{RPCResult::Type::NUM_TIME, "time", "local time transaction entered pool in seconds since 1 Jan 1970 GMT"},
468468
RPCResult{RPCResult::Type::NUM, "height", "block height when transaction entered pool"},
469469
RPCResult{RPCResult::Type::NUM, "descendantcount", "number of in-mempool descendant transactions (including this one)"},
470470
RPCResult{RPCResult::Type::NUM, "descendantsize", "virtual transaction size of in-mempool descendants (including this one)"},
471-
RPCResult{RPCResult::Type::STR_AMOUNT, "descendantfees", "modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED)"},
471+
RPCResult{RPCResult::Type::STR_AMOUNT, "descendantfees", "transaction fees of in-mempool descendants (including this one) with fee deltas used for mining priority, denominated in " + CURRENCY_ATOM + "s (DEPRECATED, returned only if config option -deprecatedrpc=fees is passed)"},
472472
RPCResult{RPCResult::Type::NUM, "ancestorcount", "number of in-mempool ancestor transactions (including this one)"},
473473
RPCResult{RPCResult::Type::NUM, "ancestorsize", "virtual transaction size of in-mempool ancestors (including this one)"},
474-
RPCResult{RPCResult::Type::STR_AMOUNT, "ancestorfees", "modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED)"},
474+
RPCResult{RPCResult::Type::STR_AMOUNT, "ancestorfees", "transaction fees of in-mempool ancestors (including this one) with fee deltas used for mining priority, denominated in " + CURRENCY_ATOM + "s (DEPRECATED, returned only if config option -deprecatedrpc=fees is passed)"},
475475
RPCResult{RPCResult::Type::STR_HEX, "wtxid", "hash of serialized transaction, including witness data"},
476476
RPCResult{RPCResult::Type::OBJ, "fees", "",
477477
{
478-
RPCResult{RPCResult::Type::STR_AMOUNT, "base", "transaction fee in " + CURRENCY_UNIT},
479-
RPCResult{RPCResult::Type::STR_AMOUNT, "modified", "transaction fee with fee deltas used for mining priority in " + CURRENCY_UNIT},
480-
RPCResult{RPCResult::Type::STR_AMOUNT, "ancestor", "modified fees (see above) of in-mempool ancestors (including this one) in " + CURRENCY_UNIT},
481-
RPCResult{RPCResult::Type::STR_AMOUNT, "descendant", "modified fees (see above) of in-mempool descendants (including this one) in " + CURRENCY_UNIT},
478+
RPCResult{RPCResult::Type::STR_AMOUNT, "base", "transaction fee, denominated in " + CURRENCY_UNIT},
479+
RPCResult{RPCResult::Type::STR_AMOUNT, "modified", "transaction fee with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
480+
RPCResult{RPCResult::Type::STR_AMOUNT, "ancestor", "transaction fees of in-mempool ancestors (including this one) with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
481+
RPCResult{RPCResult::Type::STR_AMOUNT, "descendant", "transaction fees of in-mempool descendants (including this one) with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
482482
}},
483483
RPCResult{RPCResult::Type::ARR, "depends", "unconfirmed transactions used as inputs for this transaction",
484484
{RPCResult{RPCResult::Type::STR_HEX, "transactionid", "parent transaction id"}}},
@@ -498,19 +498,26 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
498498
fees.pushKV("ancestor", ValueFromAmount(e.GetModFeesWithAncestors()));
499499
fees.pushKV("descendant", ValueFromAmount(e.GetModFeesWithDescendants()));
500500
info.pushKV("fees", fees);
501-
502501
info.pushKV("vsize", (int)e.GetTxSize());
503502
info.pushKV("weight", (int)e.GetTxWeight());
504-
info.pushKV("fee", ValueFromAmount(e.GetFee()));
505-
info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee()));
503+
// TODO: top-level fee fields are deprecated. deprecated_fee_fields_enabled blocks should be removed in v24
504+
const bool deprecated_fee_fields_enabled{IsDeprecatedRPCEnabled("fees")};
505+
if (deprecated_fee_fields_enabled) {
506+
info.pushKV("fee", ValueFromAmount(e.GetFee()));
507+
info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee()));
508+
}
506509
info.pushKV("time", count_seconds(e.GetTime()));
507510
info.pushKV("height", (int)e.GetHeight());
508511
info.pushKV("descendantcount", e.GetCountWithDescendants());
509512
info.pushKV("descendantsize", e.GetSizeWithDescendants());
510-
info.pushKV("descendantfees", e.GetModFeesWithDescendants());
513+
if (deprecated_fee_fields_enabled) {
514+
info.pushKV("descendantfees", e.GetModFeesWithDescendants());
515+
}
511516
info.pushKV("ancestorcount", e.GetCountWithAncestors());
512517
info.pushKV("ancestorsize", e.GetSizeWithAncestors());
513-
info.pushKV("ancestorfees", e.GetModFeesWithAncestors());
518+
if (deprecated_fee_fields_enabled) {
519+
info.pushKV("ancestorfees", e.GetModFeesWithAncestors());
520+
}
514521
info.pushKV("wtxid", pool.vTxHashes[e.vTxHashesIdx].first.ToString());
515522
const CTransaction& tx = e.GetTx();
516523
std::set<std::string> setDepends;

test/functional/mempool_packages.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def run_test(self):
9191

9292
assert_equal(ancestor_vsize, sum([mempool[tx]['vsize'] for tx in mempool]))
9393
ancestor_count = MAX_ANCESTORS
94-
assert_equal(ancestor_fees, sum([mempool[tx]['fee'] for tx in mempool]))
94+
assert_equal(ancestor_fees, sum([mempool[tx]['fees']['base'] for tx in mempool]))
9595

9696
descendants = []
9797
ancestors = list(chain)
@@ -102,22 +102,19 @@ def run_test(self):
102102

103103
# Check that the descendant calculations are correct
104104
assert_equal(entry['descendantcount'], descendant_count)
105-
descendant_fees += entry['fee']
106-
assert_equal(entry['modifiedfee'], entry['fee'])
107-
assert_equal(entry['fees']['base'], entry['fee'])
108-
assert_equal(entry['fees']['modified'], entry['modifiedfee'])
109-
assert_equal(entry['descendantfees'], descendant_fees * COIN)
105+
descendant_fees += entry['fees']['base']
106+
assert_equal(entry['fees']['modified'], entry['fees']['base'])
110107
assert_equal(entry['fees']['descendant'], descendant_fees)
111108
descendant_vsize += entry['vsize']
112109
assert_equal(entry['descendantsize'], descendant_vsize)
113110
descendant_count += 1
114111

115112
# Check that ancestor calculations are correct
116113
assert_equal(entry['ancestorcount'], ancestor_count)
117-
assert_equal(entry['ancestorfees'], ancestor_fees * COIN)
114+
assert_equal(entry['fees']['ancestor'], ancestor_fees)
118115
assert_equal(entry['ancestorsize'], ancestor_vsize)
119116
ancestor_vsize -= entry['vsize']
120-
ancestor_fees -= entry['fee']
117+
ancestor_fees -= entry['fees']['base']
121118
ancestor_count -= 1
122119

123120
# Check that parent/child list is correct
@@ -168,9 +165,8 @@ def run_test(self):
168165
ancestor_fees = 0
169166
for x in chain:
170167
entry = self.nodes[0].getmempoolentry(x)
171-
ancestor_fees += entry['fee']
168+
ancestor_fees += entry['fees']['base']
172169
assert_equal(entry['fees']['ancestor'], ancestor_fees + Decimal('0.00001'))
173-
assert_equal(entry['ancestorfees'], ancestor_fees * COIN + 1000)
174170

175171
# Undo the prioritisetransaction for later tests
176172
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=-1000)
@@ -182,9 +178,8 @@ def run_test(self):
182178
descendant_fees = 0
183179
for x in reversed(chain):
184180
entry = self.nodes[0].getmempoolentry(x)
185-
descendant_fees += entry['fee']
181+
descendant_fees += entry['fees']['base']
186182
assert_equal(entry['fees']['descendant'], descendant_fees + Decimal('0.00001'))
187-
assert_equal(entry['descendantfees'], descendant_fees * COIN + 1000)
188183

189184
# Adding one more transaction on to the chain should fail.
190185
assert_raises_rpc_error(-26, "too-long-mempool-chain", chain_transaction, self.nodes[0], [txid], [vout], value, fee, 1)
@@ -205,11 +200,9 @@ def run_test(self):
205200
descendant_fees = 0
206201
for x in reversed(chain):
207202
entry = self.nodes[0].getmempoolentry(x)
208-
descendant_fees += entry['fee']
203+
descendant_fees += entry['fees']['base']
209204
if (x == chain[-1]):
210-
assert_equal(entry['modifiedfee'], entry['fee'] + Decimal("0.00002"))
211-
assert_equal(entry['fees']['modified'], entry['fee'] + Decimal("0.00002"))
212-
assert_equal(entry['descendantfees'], descendant_fees * COIN + 2000)
205+
assert_equal(entry['fees']['modified'], entry['fees']['base'] + Decimal("0.00002"))
213206
assert_equal(entry['fees']['descendant'], descendant_fees + Decimal("0.00002"))
214207

215208
# Check that node1's mempool is as expected (-> custom ancestor limit)

test/functional/rpc_fundrawtransaction.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def test_fee_p2pkh(self):
417417

418418
# Create same transaction over sendtoaddress.
419419
txId = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1.1)
420-
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
420+
signedFee = self.nodes[0].getmempoolentry(txId)['fees']['base']
421421

422422
# Compare fee.
423423
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -443,7 +443,7 @@ def test_fee_p2pkh_multi_out(self):
443443

444444
# Create same transaction over sendtoaddress.
445445
txId = self.nodes[0].sendmany("", outputs)
446-
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
446+
signedFee = self.nodes[0].getmempoolentry(txId)['fees']['base']
447447

448448
# Compare fee.
449449
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -470,7 +470,7 @@ def test_fee_p2sh(self):
470470

471471
# Create same transaction over sendtoaddress.
472472
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1)
473-
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
473+
signedFee = self.nodes[0].getmempoolentry(txId)['fees']['base']
474474

475475
# Compare fee.
476476
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -514,7 +514,7 @@ def test_fee_4of5(self):
514514

515515
# Create same transaction over sendtoaddress.
516516
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1)
517-
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
517+
signedFee = self.nodes[0].getmempoolentry(txId)['fees']['base']
518518

519519
# Compare fee.
520520
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -651,7 +651,7 @@ def test_many_inputs_fee(self):
651651

652652
# Create same transaction over sendtoaddress.
653653
txId = self.nodes[1].sendmany("", outputs)
654-
signedFee = self.nodes[1].getmempoolentry(txId)['fee']
654+
signedFee = self.nodes[1].getmempoolentry(txId)['fees']['base']
655655

656656
# Compare fee.
657657
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)

0 commit comments

Comments
 (0)