ci: tighten locking in signblock to ensure consistent main/wallet locking order

This commit is contained in:
Andrew Poelstra 2020-12-11 02:06:16 +00:00
parent 2f5c624b18
commit 47885e97bf

View file

@ -5166,29 +5166,31 @@ static RPCHelpMan signblock()
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
ChainstateManager& chainman = g_chainman; // FIXME avoid using this global, see #19413
LOCK(cs_main);
LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan();
if (!spk_man) {
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
}
uint256 hash = block.GetHash();
BlockMap::iterator mi = chainman.BlockIndex().find(hash);
if (mi != chainman.BlockIndex().end())
throw JSONRPCError(RPC_VERIFY_ERROR, "already have block");
{
LOCK(cs_main);
uint256 hash = block.GetHash();
BlockMap::iterator mi = chainman.BlockIndex().find(hash);
if (mi != chainman.BlockIndex().end())
throw JSONRPCError(RPC_VERIFY_ERROR, "already have block");
CBlockIndex* const pindexPrev = ::ChainActive().Tip();
// TestBlockValidity only supports blocks built on the current Tip
if (block.hashPrevBlock != pindexPrev->GetBlockHash())
throw JSONRPCError(RPC_VERIFY_ERROR, "proposal was not based on our best chain");
CBlockIndex* const pindexPrev = ::ChainActive().Tip();
// TestBlockValidity only supports blocks built on the current Tip
if (block.hashPrevBlock != pindexPrev->GetBlockHash())
throw JSONRPCError(RPC_VERIFY_ERROR, "proposal was not based on our best chain");
BlockValidationState state;
if (!TestBlockValidity(state, Params(), block, pindexPrev, false, true) || !state.IsValid()) {
std::string strRejectReason = state.GetRejectReason();
if (strRejectReason.empty())
throw JSONRPCError(RPC_VERIFY_ERROR, state.IsInvalid() ? "Block proposal was invalid" : "Error checking block proposal");
throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
BlockValidationState state;
if (!TestBlockValidity(state, Params(), block, pindexPrev, false, true) || !state.IsValid()) {
std::string strRejectReason = state.GetRejectReason();
if (strRejectReason.empty())
throw JSONRPCError(RPC_VERIFY_ERROR, state.IsInvalid() ? "Block proposal was invalid" : "Error checking block proposal");
throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
}
}
// Expose SignatureData internals in return value in lieu of "Partially Signed Bitcoin Blocks"