refactor: centralize SubmitBlock result handling

Move the accepted/new-block/reason consistency check into SubmitBlock()
so submitBlock() and submitSolution() use the same success criteria.

This keeps duplicate and inconclusive handling in one place, removes the
new_block output parameter from the helper, and makes the helper return
whether the submitted block was accepted as a new valid block.
This commit is contained in:
w0xlt
2026-05-28 11:24:28 -07:00
parent cbaa1696f3
commit ed75d70fdb
3 changed files with 12 additions and 20 deletions

View File

@@ -920,9 +920,7 @@ public:
bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase, std::string& reason, std::string& debug) override
{
AddMerkleRootAndCoinbase(m_block_template->block, std::move(coinbase), version, timestamp, nonce);
bool new_block;
const bool accepted = SubmitBlock(chainman(), std::make_shared<const CBlock>(m_block_template->block), &new_block, reason, debug);
return accepted && new_block && reason.empty();
return SubmitBlock(chainman(), std::make_shared<const CBlock>(m_block_template->block), reason, debug);
}
std::unique_ptr<BlockTemplate> waitNext(BlockWaitOptions options) override
@@ -1025,15 +1023,7 @@ public:
bool submitBlock(const CBlock& block_in, std::string& reason, std::string& debug) override
{
auto block = std::make_shared<const CBlock>(block_in);
bool new_block;
const bool accepted = SubmitBlock(chainman(), block, &new_block, reason, debug);
// ProcessNewBlock() can accept and store a block before it is checked
// for validity. Treat duplicates as errors for mining clients, and only
// return success when validation completed without setting a reason.
const bool result{accepted && new_block && reason.empty()};
CHECK_NONFATAL(result == reason.empty());
return result;
return SubmitBlock(chainman(), std::make_shared<const CBlock>(block_in), reason, debug);
}
const NodeContext* context() override { return &m_node; }