Skip to content

Commit 1f7fc73

Browse files
committed
rpc: Remove submitblock duplicate pre-check
The duplicate checks are repeated early in the contextual checks of ProcessNewBlock. If duplicate blocks are detected much of their validation is skipped. Depending on the constitution of the block, validating the merkle root of the block is part of the more intensive workload when validating a block. This could be an argument for moving the pre-checks into block processing. In net_processing this would have a smaller effect however, since the block mutation check, which also validates the merkle root, is done before. A side effect of this change is that a duplicate block is persisted again on disk even when pruning is activated. This is similar to the behaviour with getblockfrompeer. Add a release note for this change in behaviour. Testing spamming a node with valid, but duplicate unrequested blocks seems to exhaust a CPU thread, but does not seem to significantly impact keeping up with the tip. The benefits of adding these checks to net_processing are questionable, especially since there are other ways to trigger the more CPU-intensive checks without submitting a duplicate block. Since these DOS concerns apply even less to the RPC interface, which does not have banning mechanics built in, remove them too. --- 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.
1 parent e62a8ab commit 1f7fc73

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

doc/release-notes-31175.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
RPC
2+
---
3+
4+
Duplicate blocks submitted with `submitblock` will now persist their block data
5+
even if it was previously pruned. If pruning is activated, the data will be
6+
pruned again eventually once the block file it is persisted in is selected for
7+
pruning. This is consistent with the behaviour of `getblockfrompeer` where the
8+
block is persisted as well even when pruning.

src/rpc/mining.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,17 +1016,6 @@ static RPCHelpMan submitblock()
10161016
}
10171017

10181018
ChainstateManager& chainman = EnsureAnyChainman(request.context);
1019-
uint256 hash = block.GetHash();
1020-
{
1021-
LOCK(cs_main);
1022-
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
1023-
if (pindex) {
1024-
if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) {
1025-
return "duplicate";
1026-
}
1027-
}
1028-
}
1029-
10301019
{
10311020
LOCK(cs_main);
10321021
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock);

0 commit comments

Comments
 (0)