From 6d46e067b71901308433afd7c70d4ea64c2a1d1b Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 31 Oct 2024 11:58:44 -0700 Subject: [PATCH] Remove processNewBlock() from mining interface processNewBlock was added in 7b4d3249ced93ec5986500e43b324005ed89502f, but became unnecessary with the introduction of interfaces::BlockTemplate::submitSolution in 7b4d3249ced93ec5986500e43b324005ed89502f. getTransactionsUpdated() is only needed by the implementation of waitFeesChanged() (not yet part of the interface). --- src/interfaces/mining.h | 9 --------- src/ipc/capnp/mining.capnp | 1 - src/node/interfaces.cpp | 5 ----- src/rpc/mining.cpp | 13 +++++-------- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/interfaces/mining.h b/src/interfaces/mining.h index 55bbd09d8ecd4..8b3e425f4fe8f 100644 --- a/src/interfaces/mining.h +++ b/src/interfaces/mining.h @@ -94,15 +94,6 @@ class Mining */ virtual std::unique_ptr createNewBlock(const CScript& script_pub_key, const node::BlockCreateOptions& options = {}) = 0; - /** - * Processes new block. A valid new block is automatically relayed to peers. - * - * @param[in] block The block we want to process. - * @param[out] new_block A boolean which is set to indicate if the block was first received via this call - * @returns If the block was processed, independently of block validity - */ - virtual bool processNewBlock(const std::shared_ptr& block, bool* new_block) = 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 f96d073905010..fbf48dd99117c 100644 --- a/src/ipc/capnp/mining.capnp +++ b/src/ipc/capnp/mining.capnp @@ -18,7 +18,6 @@ interface Mining $Proxy.wrap("interfaces::Mining") { getTip @2 (context :Proxy.Context) -> (result: Common.BlockRef, hasResult: Bool); 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); } interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") { diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 27c1bdd7f93dc..b8c1222ab8f70 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -981,11 +981,6 @@ class MinerImpl : public Mining return BlockRef{chainman().ActiveChain().Tip()->GetBlockHash(), chainman().ActiveChain().Tip()->nHeight}; } - bool processNewBlock(const std::shared_ptr& block, bool* new_block) override - { - return chainman().ProcessNewBlock(block, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/new_block); - } - std::unique_ptr createNewBlock(const CScript& script_pub_key, const BlockCreateOptions& options) override { BlockAssembler::Options assemble_options{options}; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 6053a8429cb21..2e4c014747732 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -130,7 +130,7 @@ static RPCHelpMan getnetworkhashps() }; } -static bool GenerateBlock(ChainstateManager& chainman, Mining& miner, CBlock&& block, uint64_t& max_tries, std::shared_ptr& block_out, bool process_new_block) +static bool GenerateBlock(ChainstateManager& chainman, CBlock&& block, uint64_t& max_tries, std::shared_ptr& block_out, bool process_new_block) { block_out.reset(); block.hashMerkleRoot = BlockMerkleRoot(block); @@ -150,7 +150,7 @@ static bool GenerateBlock(ChainstateManager& chainman, Mining& miner, CBlock&& b if (!process_new_block) return true; - if (!miner.processNewBlock(block_out, nullptr)) { + if (!chainman.ProcessNewBlock(block_out, /*force_processing=*/true, /*min_pow_checked=*/true, nullptr)) { throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); } @@ -165,7 +165,7 @@ static UniValue generateBlocks(ChainstateManager& chainman, Mining& miner, const CHECK_NONFATAL(block_template); std::shared_ptr block_out; - if (!GenerateBlock(chainman, miner, block_template->getBlock(), nMaxTries, block_out, /*process_new_block=*/true)) { + if (!GenerateBlock(chainman, block_template->getBlock(), nMaxTries, block_out, /*process_new_block=*/true)) { break; } @@ -393,7 +393,7 @@ static RPCHelpMan generateblock() std::shared_ptr block_out; uint64_t max_tries{DEFAULT_MAX_TRIES}; - if (!GenerateBlock(chainman, miner, std::move(block), max_tries, block_out, process_new_block) || !block_out) { + if (!GenerateBlock(chainman, std::move(block), max_tries, block_out, process_new_block) || !block_out) { throw JSONRPCError(RPC_MISC_ERROR, "Failed to make block."); } @@ -1044,13 +1044,10 @@ static RPCHelpMan submitblock() } } - NodeContext& node = EnsureAnyNodeContext(request.context); - Mining& miner = EnsureMining(node); - bool new_block; auto sc = std::make_shared(block.GetHash()); CHECK_NONFATAL(chainman.m_options.signals)->RegisterSharedValidationInterface(sc); - bool accepted = miner.processNewBlock(blockptr, /*new_block=*/&new_block); + bool accepted = chainman.ProcessNewBlock(blockptr, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/&new_block); CHECK_NONFATAL(chainman.m_options.signals)->UnregisterSharedValidationInterface(sc); if (!new_block && accepted) { return "duplicate";