Skip to content

Commit 3f398d7

Browse files
committed
Merge #13439: rpc: Avoid "duplicate" return value for invalid submitblock
f748944 Only set fNewBlock to true in AcceptBlock when we write to disk (Matt Corallo) fa6e497 rpc: Avoid "duplicate" return value for invalid submitblock (MarcoFalke) Pull request description: This is #13395 with one more commit tacked on. MarcoFalke got tired of dealing with the stupidity of fixing a return code with too many rounds of review (not that I blame him). Honestly we should probably have no return whatsoever, but for now, this fixes it (as well as nLastBlockTime for eviction purposes). Original description: When `submitblock` of an invalid block, the return value should not be `"duplicate"`. This is only seen when the header was previously found (denoted by the incorrectly named boolean `fBlockPresent`). Fix this bug by removing `fBlockPresent`. Tree-SHA512: 0ce3092655d5d904b4c8c5ff7479f73ce387144a738f20472b8af132564005c6db5594ae366e589508f6258506ee7a28b1c7995a83a8328b334f99316006bf2d
2 parents 0882406 + f748944 commit 3f398d7

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/rpc/mining.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@ static UniValue submitblock(const JSONRPCRequest& request)
725725
}
726726

727727
uint256 hash = block.GetHash();
728-
bool fBlockPresent = false;
729728
{
730729
LOCK(cs_main);
731730
const CBlockIndex* pindex = LookupBlockIndex(hash);
@@ -736,8 +735,6 @@ static UniValue submitblock(const JSONRPCRequest& request)
736735
if (pindex->nStatus & BLOCK_FAILED_MASK) {
737736
return "duplicate-invalid";
738737
}
739-
// Otherwise, we might only have the header - process the block before returning
740-
fBlockPresent = true;
741738
}
742739
}
743740

@@ -749,13 +746,15 @@ static UniValue submitblock(const JSONRPCRequest& request)
749746
}
750747
}
751748

749+
bool new_block;
752750
submitblock_StateCatcher sc(block.GetHash());
753751
RegisterValidationInterface(&sc);
754-
bool fAccepted = ProcessNewBlock(Params(), blockptr, true, nullptr);
752+
bool accepted = ProcessNewBlock(Params(), blockptr, /* fForceProcessing */ true, /* fNewBlock */ &new_block);
755753
UnregisterValidationInterface(&sc);
756-
if (fBlockPresent) {
757-
if (fAccepted && !sc.found) {
758-
return "duplicate-inconclusive";
754+
if (!new_block) {
755+
if (!accepted) {
756+
// TODO Maybe pass down fNewBlock to AcceptBlockHeader, so it is properly set to true in this case?
757+
return "invalid";
759758
}
760759
return "duplicate";
761760
}

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3508,7 +3508,6 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CVali
35083508
// request; don't process these.
35093509
if (pindex->nChainWork < nMinimumChainWork) return true;
35103510
}
3511-
if (fNewBlock) *fNewBlock = true;
35123511

35133512
if (!CheckBlock(block, state, chainparams.GetConsensus()) ||
35143513
!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev)) {
@@ -3525,6 +3524,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CVali
35253524
GetMainSignals().NewPoWValidBlock(pindex, pblock);
35263525

35273526
// Write block to history file
3527+
if (fNewBlock) *fNewBlock = true;
35283528
try {
35293529
CDiskBlockPos blockPos = SaveBlockToDisk(block, pindex->nHeight, chainparams, dbp);
35303530
if (blockPos.IsNull()) {

0 commit comments

Comments
 (0)