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

Function submitblock

src/rpc/mining.cpp:1086–1136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1084};
1085
1086static RPCMethod submitblock()
1087{
1088 // We allow 2 arguments for compliance with BIP22. Argument 2 is ignored.
1089 return RPCMethod{
1090 "submitblock",
1091 "Attempts to submit new block to network.\n"
1092 "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n",
1093 {
1094 {"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block data to submit"},
1095 {"dummy", RPCArg::Type::STR, RPCArg::DefaultHint{"ignored"}, "dummy value, for compatibility with BIP22. This value is ignored."},
1096 },
1097 {
1098 RPCResult{"If the block was accepted", RPCResult::Type::NONE, "", ""},
1099 RPCResult{"Otherwise", RPCResult::Type::STR, "", "According to BIP22"},
1100 },
1101 RPCExamples{
1102 HelpExampleCli("submitblock", "\"mydata\"")
1103 + HelpExampleRpc("submitblock", "\"mydata\"")
1104 },
1105 [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
1106{
1107 std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
1108 CBlock& block = *blockptr;
1109 if (!DecodeHexBlk(block, request.params[0].get_str())) {
1110 throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
1111 }
1112
1113 ChainstateManager& chainman = EnsureAnyChainman(request.context);
1114 {
1115 LOCK(cs_main);
1116 const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock);
1117 if (pindex) {
1118 chainman.UpdateUncommittedBlockStructures(block, pindex);
1119 }
1120 }
1121
1122 bool new_block;
1123 auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash());
1124 CHECK_NONFATAL(chainman.m_options.signals)->RegisterSharedValidationInterface(sc);
1125 bool accepted = chainman.ProcessNewBlock(blockptr, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/&new_block);
1126 CHECK_NONFATAL(chainman.m_options.signals)->UnregisterSharedValidationInterface(sc);
1127 if (!new_block && accepted) {
1128 return "duplicate";
1129 }
1130 if (!sc->found) {
1131 return "inconclusive";
1132 }
1133 return BIP22ValidationResult(sc->state);
1134},
1135 };
1136}
1137
1138static RPCMethod submitheader()
1139{

Callers

nothing calls this directly

Calls 11

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
DecodeHexBlkFunction · 0.85
JSONRPCErrorFunction · 0.85
BIP22ValidationResultFunction · 0.85
LookupBlockIndexMethod · 0.80
ProcessNewBlockMethod · 0.80
GetHashMethod · 0.45

Tested by

no test coverage detected