From e62a8abd7df21795dcd173773f689b6d4c8feab6 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Thu, 21 Nov 2024 12:36:55 +0100 Subject: [PATCH] rpc: Remove submitblock invalid-duplicate precheck ProcessNewBlock fails if an invalid duplicate block is passed in through its call to AcceptBlock and AcceptBlockHeader. The failure in AcceptBlockHeader makes AcceptBlock return early. This makes the pre-check in submitblock redundant. --- With the introduction of a mining ipc interface and the potential future introduction of a kernel library API it becomes increasingly important to offer common behaviour between them. An example of this is ProcessNewBlock, which is used by ipc, rpc, net_processing and (potentially) the kernel library. Having divergent behaviour on suggested pre-checks and checks for these functions is confusing to both developers and users and is a maintenance burden. The rpc interface for ProcessNewBlock (submitblock) currently pre-checks if the block has a coinbase transaction and whether it has been processed before. While the current example binary for how to use the kernel library, bitcoin-chainstate, imitates these checks, the other interfaces do not. --- src/rpc/mining.cpp | 3 --- src/validation.cpp | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 7726d250994..47a5bce22bb 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1024,9 +1024,6 @@ static RPCHelpMan submitblock() if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) { return "duplicate"; } - if (pindex->nStatus & BLOCK_FAILED_MASK) { - return "duplicate-invalid"; - } } } diff --git a/src/validation.cpp b/src/validation.cpp index 226f344d92f..37a4f55ca6b 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4285,7 +4285,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida *ppindex = pindex; if (pindex->nStatus & BLOCK_FAILED_MASK) { LogDebug(BCLog::VALIDATION, "%s: block %s is marked invalid\n", __func__, hash.ToString()); - return state.Invalid(BlockValidationResult::BLOCK_CACHED_INVALID, "duplicate"); + return state.Invalid(BlockValidationResult::BLOCK_CACHED_INVALID, "duplicate-invalid"); } return true; }