mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-08 03:33:32 +01:00
rpc: call TestBlockValidity via miner interface
This commit is contained in:
@@ -339,6 +339,7 @@ static RPCHelpMan generateblock()
|
||||
}
|
||||
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
Mining& miner = EnsureMining(node);
|
||||
const CTxMemPool& mempool = EnsureMemPool(node);
|
||||
|
||||
std::vector<CTransactionRef> txs;
|
||||
@@ -389,8 +390,8 @@ static RPCHelpMan generateblock()
|
||||
LOCK(cs_main);
|
||||
|
||||
BlockValidationState state;
|
||||
if (!TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), false, false)) {
|
||||
throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("TestBlockValidity failed: %s", state.ToString()));
|
||||
if (!miner.testBlockValidity(state, block, /*check_merkle_root=*/false)) {
|
||||
throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("testBlockValidity failed: %s", state.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -664,6 +665,7 @@ static RPCHelpMan getblocktemplate()
|
||||
{
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
ChainstateManager& chainman = EnsureChainman(node);
|
||||
Mining& miner = EnsureMining(node);
|
||||
LOCK(cs_main);
|
||||
|
||||
std::string strMode = "template";
|
||||
@@ -706,11 +708,12 @@ static RPCHelpMan getblocktemplate()
|
||||
}
|
||||
|
||||
CBlockIndex* const pindexPrev = active_chain.Tip();
|
||||
// TestBlockValidity only supports blocks built on the current Tip
|
||||
if (block.hashPrevBlock != pindexPrev->GetBlockHash())
|
||||
// testBlockValidity only supports blocks built on the current Tip
|
||||
if (block.hashPrevBlock != pindexPrev->GetBlockHash()) {
|
||||
return "inconclusive-not-best-prevblk";
|
||||
}
|
||||
BlockValidationState state;
|
||||
TestBlockValidity(state, chainman.GetParams(), active_chainstate, block, pindexPrev, false, true);
|
||||
miner.testBlockValidity(state, block);
|
||||
return BIP22ValidationResult(state);
|
||||
}
|
||||
|
||||
@@ -726,7 +729,6 @@ static RPCHelpMan getblocktemplate()
|
||||
if (strMode != "template")
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
|
||||
|
||||
Mining& miner = EnsureMining(node);
|
||||
if (!miner.isTestChain()) {
|
||||
const CConnman& connman = EnsureConnman(node);
|
||||
if (connman.GetNodeCount(ConnectionDirection::Both) == 0) {
|
||||
|
||||
Reference in New Issue
Block a user