Remove getTransactionsUpdated() from mining interface

It's unnecessary to expose it via this interface.
This commit is contained in:
Sjors Provoost 2024-10-31 11:58:18 -07:00
parent bfc4e029d4
commit 9a47852d88
No known key found for this signature in database
GPG key ID: 57FF9BDBCC301009
4 changed files with 4 additions and 13 deletions

View file

@ -102,10 +102,6 @@ public:
*/ */
virtual bool processNewBlock(const std::shared_ptr<const CBlock>& block, bool* new_block) = 0; virtual bool processNewBlock(const std::shared_ptr<const CBlock>& block, bool* new_block) = 0;
//! Return the number of transaction updates in the mempool,
//! used to decide whether to make a new block template.
virtual unsigned int getTransactionsUpdated() = 0;
//! Get internal node context. Useful for RPC and testing, //! Get internal node context. Useful for RPC and testing,
//! but not accessible across processes. //! but not accessible across processes.
virtual node::NodeContext* context() { return nullptr; } virtual node::NodeContext* context() { return nullptr; }

View file

@ -19,7 +19,6 @@ interface Mining $Proxy.wrap("interfaces::Mining") {
waitTipChanged @3 (context :Proxy.Context, currentTip: Data, timeout: Float64) -> (result: Common.BlockRef); waitTipChanged @3 (context :Proxy.Context, currentTip: Data, timeout: Float64) -> (result: Common.BlockRef);
createNewBlock @4 (options: BlockCreateOptions) -> (result: BlockTemplate); createNewBlock @4 (options: BlockCreateOptions) -> (result: BlockTemplate);
processNewBlock @5 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool); processNewBlock @5 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool);
getTransactionsUpdated @6 (context :Proxy.Context) -> (result: UInt32);
} }
interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") { interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {

View file

@ -984,11 +984,6 @@ public:
return chainman().ProcessNewBlock(block, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/new_block); return chainman().ProcessNewBlock(block, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/new_block);
} }
unsigned int getTransactionsUpdated() override
{
return context()->mempool->GetTransactionsUpdated();
}
std::unique_ptr<BlockTemplate> createNewBlock(const BlockCreateOptions& options) override std::unique_ptr<BlockTemplate> createNewBlock(const BlockCreateOptions& options) override
{ {
BlockAssembler::Options assemble_options{options}; BlockAssembler::Options assemble_options{options};

View file

@ -743,6 +743,7 @@ static RPCHelpMan getblocktemplate()
} }
static unsigned int nTransactionsUpdatedLast; static unsigned int nTransactionsUpdatedLast;
const CTxMemPool& mempool = EnsureMemPool(node);
if (!lpval.isNull()) if (!lpval.isNull())
{ {
@ -773,7 +774,7 @@ static RPCHelpMan getblocktemplate()
tip = miner.waitTipChanged(hashWatchedChain, checktxtime).hash; tip = miner.waitTipChanged(hashWatchedChain, checktxtime).hash;
// Timeout: Check transactions for update // Timeout: Check transactions for update
// without holding the mempool lock to avoid deadlocks // without holding the mempool lock to avoid deadlocks
if (miner.getTransactionsUpdated() != nTransactionsUpdatedLastLP) if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
break; break;
checktxtime = std::chrono::seconds(10); checktxtime = std::chrono::seconds(10);
} }
@ -804,13 +805,13 @@ static RPCHelpMan getblocktemplate()
static int64_t time_start; static int64_t time_start;
static std::unique_ptr<BlockTemplate> block_template; static std::unique_ptr<BlockTemplate> block_template;
if (!pindexPrev || pindexPrev->GetBlockHash() != tip || if (!pindexPrev || pindexPrev->GetBlockHash() != tip ||
(miner.getTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - time_start > 5)) (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - time_start > 5))
{ {
// Clear pindexPrev so future calls make a new block, despite any failures from here on // Clear pindexPrev so future calls make a new block, despite any failures from here on
pindexPrev = nullptr; pindexPrev = nullptr;
// Store the pindexBest used before createNewBlock, to avoid races // Store the pindexBest used before createNewBlock, to avoid races
nTransactionsUpdatedLast = miner.getTransactionsUpdated(); nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
CBlockIndex* pindexPrevNew = chainman.m_blockman.LookupBlockIndex(tip); CBlockIndex* pindexPrevNew = chainman.m_blockman.LookupBlockIndex(tip);
time_start = GetTime(); time_start = GetTime();