Skip to content

Commit

Permalink
Remove getTransactionsUpdated() from mining interface
Browse files Browse the repository at this point in the history
bitcoin#31003 proposes a waitFeesChanged() method which uses this method in its implementation.

It's unnecessary to expose it via this interface.
  • Loading branch information
Sjors committed Dec 16, 2024
1 parent 3b2de2c commit 9a5c774
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/interfaces/mining.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ class Mining
*/
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,
//! but not accessible across processes.
virtual node::NodeContext* context() { return nullptr; }
Expand Down
1 change: 0 additions & 1 deletion src/ipc/capnp/mining.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface Mining $Proxy.wrap("interfaces::Mining") {
waitTipChanged @3 (context :Proxy.Context, currentTip: Data, timeout: Float64) -> (result: Common.BlockRef);
createNewBlock @4 (scriptPubKey: Data, options: BlockCreateOptions) -> (result: BlockTemplate);
processNewBlock @5 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool);
getTransactionsUpdated @6 (context :Proxy.Context) -> (result: UInt32);
}

interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
Expand Down
5 changes: 0 additions & 5 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,11 +986,6 @@ class MinerImpl : public Mining
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 CScript& script_pub_key, const BlockCreateOptions& options) override
{
BlockAssembler::Options assemble_options{options};
Expand Down
7 changes: 4 additions & 3 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ static RPCHelpMan getblocktemplate()
}

static unsigned int nTransactionsUpdatedLast;
const CTxMemPool& mempool = EnsureMemPool(node);

if (!lpval.isNull())
{
Expand Down Expand Up @@ -773,7 +774,7 @@ static RPCHelpMan getblocktemplate()
tip = miner.waitTipChanged(hashWatchedChain, checktxtime).hash;
// Timeout: Check transactions for update
// without holding the mempool lock to avoid deadlocks
if (miner.getTransactionsUpdated() != nTransactionsUpdatedLastLP)
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
break;
checktxtime = std::chrono::seconds(10);
}
Expand Down Expand Up @@ -804,13 +805,13 @@ static RPCHelpMan getblocktemplate()
static int64_t time_start;
static std::unique_ptr<BlockTemplate> block_template;
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
pindexPrev = nullptr;

// Store the pindexBest used before createNewBlock, to avoid races
nTransactionsUpdatedLast = miner.getTransactionsUpdated();
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
CBlockIndex* pindexPrevNew = chainman.m_blockman.LookupBlockIndex(tip);
time_start = GetTime();

Expand Down

0 comments on commit 9a5c774

Please sign in to comment.