From bfc4e029d41ec3052d68f174565802016cb05d41 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 31 Oct 2024 11:55:13 -0700 Subject: [PATCH] Remove testBlockValidity() from mining interface It's very low level and not used by the proposed Template Provider. This method was introduced in d8a3496b5ad27bea4c79ea0344f595cc1b95f0d3 and a74b0f93efa1d9eaf5abc2f6591c44a632aec6ed. --- src/interfaces/mining.h | 12 ------------ src/ipc/capnp/mining.capnp | 1 - src/node/interfaces.cpp | 13 ------------- src/rpc/mining.cpp | 9 +++++---- test/functional/rpc_generate.py | 2 +- 5 files changed, 6 insertions(+), 31 deletions(-) diff --git a/src/interfaces/mining.h b/src/interfaces/mining.h index dd5cfe5ccc6..b8ec3aed846 100644 --- a/src/interfaces/mining.h +++ b/src/interfaces/mining.h @@ -106,18 +106,6 @@ public: //! 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. - * Only works on top of our current best block. - * Does not check proof-of-work. - * - * @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 it does not build on the current tip, or any of the checks fail - */ - 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. virtual node::NodeContext* context() { return nullptr; } diff --git a/src/ipc/capnp/mining.capnp b/src/ipc/capnp/mining.capnp index 5af37b725ab..3d9b12e7348 100644 --- a/src/ipc/capnp/mining.capnp +++ b/src/ipc/capnp/mining.capnp @@ -20,7 +20,6 @@ interface Mining $Proxy.wrap("interfaces::Mining") { createNewBlock @4 (options: BlockCreateOptions) -> (result: BlockTemplate); processNewBlock @5 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool); getTransactionsUpdated @6 (context :Proxy.Context) -> (result: UInt32); - testBlockValidity @7 (context :Proxy.Context, block: Data, checkMerkleRoot: Bool) -> (state: BlockValidationState, result: Bool); } interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") { diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 68fc17aa701..7a98f402b96 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -989,19 +989,6 @@ public: return context()->mempool->GetTransactionsUpdated(); } - bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) override - { - LOCK(cs_main); - CBlockIndex* tip{chainman().ActiveChain().Tip()}; - // Fail if the tip updated before the lock was taken - if (block.hashPrevBlock != tip->GetBlockHash()) { - state.Error("Block does not connect to current chain tip."); - return false; - } - - return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, tip, /*fCheckPOW=*/false, check_merkle_root); - } - std::unique_ptr createNewBlock(const BlockCreateOptions& options) override { BlockAssembler::Options assemble_options{options}; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 5516e1c0d99..1870636ab14 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -384,9 +384,10 @@ static RPCHelpMan generateblock() RegenerateCommitments(block, chainman); { + LOCK(::cs_main); BlockValidationState state; - if (!miner.testBlockValidity(block, /*check_merkle_root=*/false, state)) { - throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("testBlockValidity failed: %s", state.ToString())); + if (!TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) { + throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("TestBlockValidity failed: %s", state.ToString())); } } @@ -709,12 +710,12 @@ static RPCHelpMan getblocktemplate() return "duplicate-inconclusive"; } - // testBlockValidity only supports blocks built on the current Tip + // TestBlockValidity only supports blocks built on the current Tip if (block.hashPrevBlock != tip) { return "inconclusive-not-best-prevblk"; } BlockValidationState state; - miner.testBlockValidity(block, /*check_merkle_root=*/true, state); + TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/true); return BIP22ValidationResult(state); } diff --git a/test/functional/rpc_generate.py b/test/functional/rpc_generate.py index 68de9006644..74f31f45716 100755 --- a/test/functional/rpc_generate.py +++ b/test/functional/rpc_generate.py @@ -87,7 +87,7 @@ class RPCGenerateTest(BitcoinTestFramework): txid1 = miniwallet.send_self_transfer(from_node=node)['txid'] utxo1 = miniwallet.get_utxo(txid=txid1) rawtx2 = miniwallet.create_self_transfer(utxo_to_spend=utxo1)['hex'] - assert_raises_rpc_error(-25, 'testBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [rawtx2, txid1]) + assert_raises_rpc_error(-25, 'TestBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [rawtx2, txid1]) self.log.info('Fail to generate block with txid not in mempool') missing_txid = '0000000000000000000000000000000000000000000000000000000000000000'