MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / SubmitBlock

Function SubmitBlock

src/node/miner.cpp:388–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386} // namespace
387
388bool SubmitBlock(ChainstateManager& chainman, const std::shared_ptr<const CBlock>& block, bool* new_block, std::string& reason, std::string& debug)
389{
390 reason.clear();
391 debug.clear();
392
393 // This follows the submitblock RPC's validation-state capture pattern, but
394 // is intentionally kept separate from the RPC implementation. The RPC entry
395 // point decodes hex, formats BIP22/JSONRPC results, and calls
396 // UpdateUncommittedBlockStructures() for legacy witness handling. IPC
397 // callers submit already-formed blocks and need bool + reason/debug
398 // results, while submitSolution() preserves its duplicate-as-success
399 // behavior.
400 auto sc = std::make_shared<SubmitBlockStateCatcher>(block->GetHash());
401 CHECK_NONFATAL(chainman.m_options.signals)->RegisterSharedValidationInterface(sc);
402 bool accepted = chainman.ProcessNewBlock(block, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/new_block);
403 CHECK_NONFATAL(chainman.m_options.signals)->UnregisterSharedValidationInterface(sc);
404
405 if (new_block && !*new_block && accepted) {
406 reason = "duplicate";
407 } else if (!sc->m_found) {
408 // A block can be accepted and stored without being connected, for
409 // example if it does not have more work than the current tip. In that
410 // case no BlockChecked callback is emitted, so the validation result is
411 // inconclusive. Mining::submitBlock treats this as an error for mining
412 // clients, but it does not mean the block is invalid.
413 reason = "inconclusive";
414 } else if (!sc->m_state.IsValid()) {
415 reason = sc->m_state.GetRejectReason();
416 debug = sc->m_state.GetDebugMessage();
417 }
418 return accepted;
419}
420
421void InterruptWait(KernelNotifications& kernel_notifications, bool& interrupt_wait)
422{

Callers 2

submitSolutionMethod · 0.85
submitBlockMethod · 0.85

Calls 8

ProcessNewBlockMethod · 0.80
GetRejectReasonMethod · 0.80
GetDebugMessageMethod · 0.80
clearMethod · 0.45
GetHashMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected