@@ -305,6 +305,8 @@ static std::vector<RPCResult> MempoolEntryDescription()
305
305
RPCResult{RPCResult::Type::NUM, " weight" , " transaction weight as defined in BIP 141." },
306
306
RPCResult{RPCResult::Type::NUM_TIME, " time" , " local time transaction entered pool in seconds since 1 Jan 1970 GMT" },
307
307
RPCResult{RPCResult::Type::NUM, " height" , " block height when transaction entered pool" },
308
+ RPCResult{RPCResult::Type::NUM, " startingpriority" , " Priority when transaction entered pool" },
309
+ RPCResult{RPCResult::Type::NUM, " currentpriority" , " Transaction priority now" },
308
310
RPCResult{RPCResult::Type::NUM, " descendantcount" , " number of in-mempool descendant transactions (including this one)" },
309
311
RPCResult{RPCResult::Type::NUM, " descendantsize" , " virtual transaction size of in-mempool descendants (including this one)" },
310
312
RPCResult{RPCResult::Type::NUM, " ancestorcount" , " number of in-mempool ancestor transactions (including this one)" },
@@ -326,14 +328,16 @@ static std::vector<RPCResult> MempoolEntryDescription()
326
328
};
327
329
}
328
330
329
- static void entryToJSON (const CTxMemPool& pool, UniValue& info, const CTxMemPoolEntry& e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
331
+ static void entryToJSON (const CTxMemPool& pool, UniValue& info, const CTxMemPoolEntry& e, const int next_block_height ) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
330
332
{
331
333
AssertLockHeld (pool.cs );
332
334
333
335
info.pushKV (" vsize" , (int )e.GetTxSize ());
334
336
info.pushKV (" weight" , (int )e.GetTxWeight ());
335
337
info.pushKV (" time" , count_seconds (e.GetTime ()));
336
338
info.pushKV (" height" , (int )e.GetHeight ());
339
+ info.pushKV (" startingpriority" , e.GetStartingPriority ());
340
+ info.pushKV (" currentpriority" , e.GetPriority (next_block_height));
337
341
info.pushKV (" descendantcount" , e.GetCountWithDescendants ());
338
342
info.pushKV (" descendantsize" , e.GetSizeWithDescendants ());
339
343
info.pushKV (" ancestorcount" , e.GetCountWithAncestors ());
@@ -383,17 +387,22 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
383
387
info.pushKV (" unbroadcast" , pool.IsUnbroadcastTx (tx.GetHash ()));
384
388
}
385
389
386
- UniValue MempoolToJSON (const CTxMemPool& pool, bool verbose, bool include_mempool_sequence)
390
+ UniValue MempoolToJSON (ChainstateManager &chainman, const CTxMemPool& pool, bool verbose, bool include_mempool_sequence)
387
391
{
388
392
if (verbose) {
389
393
if (include_mempool_sequence) {
390
394
throw JSONRPCError (RPC_INVALID_PARAMETER, " Verbose results cannot contain mempool sequence values." );
391
395
}
396
+ LOCK (::cs_main);
397
+ const CChain& active_chain = chainman.ActiveChain ();
398
+ const int next_block_height = active_chain.Height () + 1 ;
392
399
LOCK (pool.cs );
400
+ // TODO: Release cs_main after mempool.cs acquired
401
+
393
402
UniValue o (UniValue::VOBJ);
394
403
for (const CTxMemPoolEntry& e : pool.entryAll ()) {
395
404
UniValue info (UniValue::VOBJ);
396
- entryToJSON (pool, info, e);
405
+ entryToJSON (pool, info, e, next_block_height );
397
406
// Mempool has unique entries so there is no advantage in using
398
407
// UniValue::pushKV, which checks if the key already exists in O(N).
399
408
// UniValue::pushKVEnd is used instead which currently is O(1).
@@ -466,7 +475,9 @@ static RPCHelpMan getrawmempool()
466
475
include_mempool_sequence = request.params [1 ].get_bool ();
467
476
}
468
477
469
- return MempoolToJSON (EnsureAnyMemPool (request.context ), fVerbose , include_mempool_sequence);
478
+ NodeContext& node = EnsureAnyNodeContext (request.context );
479
+ ChainstateManager& chainman = EnsureChainman (node);
480
+ return MempoolToJSON (chainman, EnsureAnyMemPool (request.context ), fVerbose , include_mempool_sequence);
470
481
},
471
482
};
472
483
}
@@ -502,7 +513,12 @@ static RPCHelpMan getmempoolancestors()
502
513
uint256 hash = ParseHashV (request.params [0 ], " parameter 1" );
503
514
504
515
const CTxMemPool& mempool = EnsureAnyMemPool (request.context );
516
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
517
+ LOCK (::cs_main);
518
+ const CChain& active_chain = chainman.ActiveChain ();
519
+ const int next_block_height = active_chain.Height () + 1 ;
505
520
LOCK (mempool.cs );
521
+ // TODO: Release cs_main after mempool.cs acquired
506
522
507
523
const auto entry{mempool.GetEntry (Txid::FromUint256 (hash))};
508
524
if (entry == nullptr ) {
@@ -523,7 +539,7 @@ static RPCHelpMan getmempoolancestors()
523
539
const CTxMemPoolEntry &e = *ancestorIt;
524
540
const uint256& _hash = e.GetTx ().GetHash ();
525
541
UniValue info (UniValue::VOBJ);
526
- entryToJSON (mempool, info, e);
542
+ entryToJSON (mempool, info, e, next_block_height );
527
543
o.pushKV (_hash.ToString (), std::move (info));
528
544
}
529
545
return o;
@@ -563,7 +579,12 @@ static RPCHelpMan getmempooldescendants()
563
579
uint256 hash = ParseHashV (request.params [0 ], " parameter 1" );
564
580
565
581
const CTxMemPool& mempool = EnsureAnyMemPool (request.context );
582
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
583
+ LOCK (::cs_main);
584
+ const CChain& active_chain = chainman.ActiveChain ();
585
+ const int next_block_height = active_chain.Height () + 1 ;
566
586
LOCK (mempool.cs );
587
+ // TODO: Release cs_main after mempool.cs acquired
567
588
568
589
const auto it{mempool.GetIter (hash)};
569
590
if (!it) {
@@ -588,7 +609,7 @@ static RPCHelpMan getmempooldescendants()
588
609
const CTxMemPoolEntry &e = *descendantIt;
589
610
const uint256& _hash = e.GetTx ().GetHash ();
590
611
UniValue info (UniValue::VOBJ);
591
- entryToJSON (mempool, info, e);
612
+ entryToJSON (mempool, info, e, next_block_height );
592
613
o.pushKV (_hash.ToString (), std::move (info));
593
614
}
594
615
return o;
@@ -615,15 +636,20 @@ static RPCHelpMan getmempoolentry()
615
636
uint256 hash = ParseHashV (request.params [0 ], " parameter 1" );
616
637
617
638
const CTxMemPool& mempool = EnsureAnyMemPool (request.context );
639
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
640
+ LOCK (::cs_main);
641
+ const CChain& active_chain = chainman.ActiveChain ();
642
+ const int next_block_height = active_chain.Height () + 1 ;
618
643
LOCK (mempool.cs );
644
+ // TODO: Release cs_main after mempool.cs acquired
619
645
620
646
const auto entry{mempool.GetEntry (Txid::FromUint256 (hash))};
621
647
if (entry == nullptr ) {
622
648
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Transaction not in mempool" );
623
649
}
624
650
625
651
UniValue info (UniValue::VOBJ);
626
- entryToJSON (mempool, info, *entry);
652
+ entryToJSON (mempool, info, *entry, next_block_height );
627
653
return info;
628
654
},
629
655
};
0 commit comments