mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
rpc: getTransactionsUpdated via miner interface
This commit is contained in:
@@ -41,6 +41,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool = true) = 0;
|
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool = true) = 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check a block is completely valid from start to finish.
|
* Check a block is completely valid from start to finish.
|
||||||
* Only works on top of our current best block.
|
* Only works on top of our current best block.
|
||||||
|
|||||||
@@ -855,6 +855,11 @@ public:
|
|||||||
return tip->GetBlockHash();
|
return tip->GetBlockHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int getTransactionsUpdated() override
|
||||||
|
{
|
||||||
|
return context()->mempool->GetTransactionsUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
bool testBlockValidity(BlockValidationState& state, const CBlock& block, bool check_merkle_root) override
|
bool testBlockValidity(BlockValidationState& state, const CBlock& block, bool check_merkle_root) override
|
||||||
{
|
{
|
||||||
LOCK(::cs_main);
|
LOCK(::cs_main);
|
||||||
|
|||||||
@@ -738,7 +738,6 @@ static RPCHelpMan getblocktemplate()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int nTransactionsUpdatedLast;
|
static unsigned int nTransactionsUpdatedLast;
|
||||||
const CTxMemPool& mempool = EnsureMemPool(node);
|
|
||||||
|
|
||||||
if (!lpval.isNull())
|
if (!lpval.isNull())
|
||||||
{
|
{
|
||||||
@@ -774,7 +773,7 @@ static RPCHelpMan getblocktemplate()
|
|||||||
{
|
{
|
||||||
// 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 (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
|
if (miner.getTransactionsUpdated() != nTransactionsUpdatedLastLP)
|
||||||
break;
|
break;
|
||||||
checktxtime += std::chrono::seconds(10);
|
checktxtime += std::chrono::seconds(10);
|
||||||
}
|
}
|
||||||
@@ -804,13 +803,13 @@ static RPCHelpMan getblocktemplate()
|
|||||||
static int64_t time_start;
|
static int64_t time_start;
|
||||||
static std::unique_ptr<CBlockTemplate> pblocktemplate;
|
static std::unique_ptr<CBlockTemplate> pblocktemplate;
|
||||||
if (!pindexPrev || pindexPrev->GetBlockHash() != miner.getTipHash() ||
|
if (!pindexPrev || pindexPrev->GetBlockHash() != miner.getTipHash() ||
|
||||||
(mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - time_start > 5))
|
(miner.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 = mempool.GetTransactionsUpdated();
|
nTransactionsUpdatedLast = miner.getTransactionsUpdated();
|
||||||
CBlockIndex* pindexPrevNew = chainman.m_blockman.LookupBlockIndex(miner.getTipHash());
|
CBlockIndex* pindexPrevNew = chainman.m_blockman.LookupBlockIndex(miner.getTipHash());
|
||||||
time_start = GetTime();
|
time_start = GetTime();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user