Skip to content

Commit 9e22835

Browse files
committed
rpc: getTransactionsUpdated via miner interface
1 parent 64ebb0f commit 9e22835

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/interfaces/mining.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class Mining
4141
*/
4242
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool = true) = 0;
4343

44+
//! Return the number of transaction updates in the mempool,
45+
//! used to decide whether to make a new block template.
46+
virtual unsigned int getTransactionsUpdated() = 0;
47+
4448
/**
4549
* Check a block is completely valid from start to finish.
4650
* Only works on top of our current best block.

src/node/interfaces.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,11 @@ class MinerImpl : public Mining
855855
return tip->GetBlockHash();
856856
}
857857

858+
unsigned int getTransactionsUpdated() override
859+
{
860+
return context()->mempool->GetTransactionsUpdated();
861+
}
862+
858863
bool testBlockValidity(BlockValidationState& state, const CBlock& block, bool check_merkle_root) override
859864
{
860865
LOCK(::cs_main);

src/rpc/mining.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,6 @@ static RPCHelpMan getblocktemplate()
738738
}
739739

740740
static unsigned int nTransactionsUpdatedLast;
741-
const CTxMemPool& mempool = EnsureMemPool(node);
742741

743742
if (!lpval.isNull())
744743
{
@@ -774,7 +773,7 @@ static RPCHelpMan getblocktemplate()
774773
{
775774
// Timeout: Check transactions for update
776775
// without holding the mempool lock to avoid deadlocks
777-
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
776+
if (miner.getTransactionsUpdated() != nTransactionsUpdatedLastLP)
778777
break;
779778
checktxtime += std::chrono::seconds(10);
780779
}
@@ -804,13 +803,13 @@ static RPCHelpMan getblocktemplate()
804803
static int64_t time_start;
805804
static std::unique_ptr<CBlockTemplate> pblocktemplate;
806805
if (!pindexPrev || pindexPrev->GetBlockHash() != miner.getTipHash() ||
807-
(mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - time_start > 5))
806+
(miner.getTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - time_start > 5))
808807
{
809808
// Clear pindexPrev so future calls make a new block, despite any failures from here on
810809
pindexPrev = nullptr;
811810

812811
// Store the pindexBest used before createNewBlock, to avoid races
813-
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
812+
nTransactionsUpdatedLast = miner.getTransactionsUpdated();
814813
CBlockIndex* pindexPrevNew = chainman.m_blockman.LookupBlockIndex(miner.getTipHash());
815814
time_start = GetTime();
816815

0 commit comments

Comments
 (0)