Skip to content

Commit

Permalink
refactor: testBlockValidity make out argument last
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjors committed Jun 26, 2024
1 parent 83a9bef commit 75ce763
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/interfaces/mining.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Mining
* @returns a block template
*/
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool = true) = 0;

/**
* Processes new block. A valid new block is automatically relayed to peers.
*
Expand All @@ -63,12 +64,12 @@ class Mining
* Only works on top of our current best block.
* Does not check proof-of-work.
*
* @param[out] state details of why a block failed to validate
* @param[in] block the block to validate
* @param[in] check_merkle_root call CheckMerkleRoot()
* @param[out] state details of why a block failed to validate
* @returns false if any of the checks fail
*/
virtual bool testBlockValidity(BlockValidationState& state, const CBlock& block, bool check_merkle_root = true) = 0;
virtual bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) = 0;

//! Get internal node context. Useful for RPC and testing,
//! but not accessible across processes.
Expand Down
2 changes: 1 addition & 1 deletion src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ class MinerImpl : public Mining
return context()->mempool->GetTransactionsUpdated();
}

bool testBlockValidity(BlockValidationState& state, const CBlock& block, bool check_merkle_root) override
bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) override
{
LOCK(::cs_main);
return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, chainman().ActiveChain().Tip(), /*fCheckPOW=*/false, check_merkle_root);
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static RPCHelpMan generateblock()
LOCK(cs_main);

BlockValidationState state;
if (!miner.testBlockValidity(state, block, /*check_merkle_root=*/false)) {
if (!miner.testBlockValidity(block, /*check_merkle_root=*/false, state)) {
throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("testBlockValidity failed: %s", state.ToString()));
}
}
Expand Down Expand Up @@ -713,7 +713,7 @@ static RPCHelpMan getblocktemplate()
return "inconclusive-not-best-prevblk";
}
BlockValidationState state;
miner.testBlockValidity(state, block);
miner.testBlockValidity(block, /*check_merkle_root=*/true, state);
return BIP22ValidationResult(state);
}

Expand Down

0 comments on commit 75ce763

Please sign in to comment.