From 8a2509e21abfccf64d375b0700034a478ab8aac8 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 6 Apr 2023 19:21:10 +0200 Subject: [PATCH] doc: warn that CheckBlock() underestimates sigops Counting sigops in the witness requires context that CheckBlock() does not have, so it only counts sigops for non-segwit transactions. This should not be a problem. There are 2 call sites: 1. ConnectBlock(): this checks all sigops 2. TestBlockValidity() used by getblocktemplate: this also calls ConnectBlock() 3. AcceptBlock(): this performs limited checks before storing a block on disk 4. ProcessNewBlock(): calls AcceptBlock() 4. VerifyDB(): disconnects the block at level 3, which results in ConnectBlock() --- src/validation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/validation.cpp b/src/validation.cpp index 8e4ea8eda2f..b3074e0cf43 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4047,6 +4047,7 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), tx_state.GetDebugMessage())); } } + // This underestimates the number of sigops, because unlike ConnectBlock it does not count the witness: unsigned int nSigOps = 0; for (const auto& tx : block.vtx) {