Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 994 Lines • ▼ Show 20 Lines | static UniValue getblocktemplate(const Config &config, | ||||
result.pushKV("sizelimit", DEFAULT_MAX_BLOCK_SIZE); | result.pushKV("sizelimit", DEFAULT_MAX_BLOCK_SIZE); | ||||
result.pushKV("curtime", pblock->GetBlockTime()); | result.pushKV("curtime", pblock->GetBlockTime()); | ||||
result.pushKV("bits", strprintf("%08x", pblock->nBits)); | result.pushKV("bits", strprintf("%08x", pblock->nBits)); | ||||
result.pushKV("height", int64_t(pindexPrev->nHeight) + 1); | result.pushKV("height", int64_t(pindexPrev->nHeight) + 1); | ||||
return result; | return result; | ||||
} | } | ||||
class submitblock_StateCatcher : public CValidationInterface { | class submitblock_StateCatcher final : public CValidationInterface { | ||||
public: | public: | ||||
uint256 hash; | uint256 hash; | ||||
bool found; | bool found; | ||||
BlockValidationState state; | BlockValidationState state; | ||||
explicit submitblock_StateCatcher(const uint256 &hashIn) | explicit submitblock_StateCatcher(const uint256 &hashIn) | ||||
: hash(hashIn), found(false), state() {} | : hash(hashIn), found(false), state() {} | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | const BlockHash hash = block.GetHash(); | ||||
} | } | ||||
if (pindex->nStatus.isInvalid()) { | if (pindex->nStatus.isInvalid()) { | ||||
return "duplicate-invalid"; | return "duplicate-invalid"; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
bool new_block; | bool new_block; | ||||
submitblock_StateCatcher sc(block.GetHash()); | auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash()); | ||||
RegisterValidationInterface(&sc); | RegisterSharedValidationInterface(sc); | ||||
bool accepted = | bool accepted = | ||||
EnsureChainman(request.context) | EnsureChainman(request.context) | ||||
.ProcessNewBlock(config, blockptr, /* fForceProcessing */ true, | .ProcessNewBlock(config, blockptr, /* fForceProcessing */ true, | ||||
/* fNewBlock */ &new_block); | /* fNewBlock */ &new_block); | ||||
// We are only interested in BlockChecked which will have been dispatched | UnregisterSharedValidationInterface(sc); | ||||
// in-thread, so no need to sync before unregistering. | |||||
UnregisterValidationInterface(&sc); | |||||
// Sync to ensure that the catcher's slots aren't executing when it goes out | |||||
// of scope and is deleted. | |||||
SyncWithValidationInterfaceQueue(); | |||||
if (!new_block && accepted) { | if (!new_block && accepted) { | ||||
return "duplicate"; | return "duplicate"; | ||||
} | } | ||||
if (!sc.found) { | if (!sc->found) { | ||||
return "inconclusive"; | return "inconclusive"; | ||||
} | } | ||||
return BIP22ValidationResult(config, sc.state); | return BIP22ValidationResult(config, sc->state); | ||||
} | } | ||||
static UniValue submitheader(const Config &config, | static UniValue submitheader(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"submitheader", | "submitheader", | ||||
"Decode the given hexdata as a header and submit it as a candidate " | "Decode the given hexdata as a header and submit it as a candidate " | ||||
"chain tip if valid." | "chain tip if valid." | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |