From 3b33ec85ed00ba7e7525858e3701f9f55071c58b Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 15 Aug 2015 23:32:38 +0200 Subject: Avoid duplicate CheckBlock checks --- src/main.cpp | 6 ++++++ src/primitives/block.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 1e0194e2cd..e8bc68fe64 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2587,6 +2587,9 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo { // These are checks that are independent of context. + if (block.fChecked) + return true; + // Check that the header is valid (particularly PoW). This is mostly // redundant with the call in AcceptBlockHeader. if (!CheckBlockHeader(block, state, fCheckPOW)) @@ -2642,6 +2645,9 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo return state.DoS(100, error("CheckBlock(): out-of-bounds SigOpCount"), REJECT_INVALID, "bad-blk-sigops", true); + if (fCheckPOW && fCheckMerkleRoot) + block.fChecked = true; + return true; } diff --git a/src/primitives/block.h b/src/primitives/block.h index 7fe8c84cb7..86106098f5 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -77,6 +77,9 @@ public: // network and disk std::vector vtx; + // memory only + mutable bool fChecked; + CBlock() { SetNull(); @@ -100,6 +103,7 @@ public: { CBlockHeader::SetNull(); vtx.clear(); + fChecked = false; } CBlockHeader GetBlockHeader() const -- cgit v1.2.3