| 386 | } // namespace |
| 387 | |
| 388 | bool 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 | |
| 421 | void InterruptWait(KernelNotifications& kernel_notifications, bool& interrupt_wait) |
| 422 | { |
no test coverage detected