When validation is waiting for parent chain daemon, "stall".

Currently, if -validatepegin is given, and block validation can't proceed
because the parent chain is not synced, we mark the block invalid and put
it in a queue to be "revalidated" later. Unfortunately, marking a block
invalid has downstream consequences, in particular causing descendant blocks
to be marked invalid, which are not currently fixed by the queue.

Instead, we'll use a different strategy: if the mainchain daemon isn't
sufficiently synced to validate a block, we will "stall" connecting that
block to the chain, and have ActivateBestChain simply keep the tip at the
previous block until we're ready.

We can still download and validate (partly) blocks past this point while
we're waiting. They will be connected once the parent chain daemon catches
up.
This commit is contained in:
Glenn Willen 2021-06-30 02:19:24 -07:00 committed by Andrew Poelstra
parent 5b1f3cc00b
commit 4ba4e0716d
8 changed files with 78 additions and 113 deletions

View file

@ -152,18 +152,24 @@ UniValue CallMainChainRPC(const std::string& strMethod, const UniValue& params)
bool IsConfirmedBitcoinBlock(const uint256& hash, const int nMinConfirmationDepth, const int nbTxs)
{
LogPrintf("Checking for confirmed bitcoin block with hash %s, mindepth %d, nbtxs %d\n", hash.ToString().c_str(), nMinConfirmationDepth, nbTxs);
try {
UniValue params(UniValue::VARR);
params.push_back(hash.GetHex());
UniValue reply = CallMainChainRPC("getblockheader", params);
if (!find_value(reply, "error").isNull())
if (!find_value(reply, "error").isNull()) {
LogPrintf("ERROR: Got error reply from bitcoind getblockheader.\n");
return false;
}
UniValue result = find_value(reply, "result");
if (!result.isObject())
if (!result.isObject()) {
LogPrintf("ERROR: bitcoind getblockheader result was malformed (not object).\n");
return false;
}
UniValue confirmations = find_value(result.get_obj(), "confirmations");
if (!confirmations.isNum() || confirmations.get_int64() < nMinConfirmationDepth) {
LogPrintf("Insufficient confirmations (got %s).\n", confirmations.write());
return false;
}