From bc4aebb8a76839132352d3af8ca6053811fe0656 Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Mon, 10 Aug 2015 13:41:55 +0200 Subject: [PATCH] Only test supermajority for block rejects against v3 blocks Since v2 and v1 blocks will be rejected at exactly the same time, only check for supermajority once to save 2000 iterations over blockheaders per block. Also moves the version check to AcceptBlockHeader() rather than AcceptBlock() to be able to reject early on. --- src/main.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1b51e4968..5cf8d744c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2712,17 +2712,13 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex if (pcheckpoint && nHeight < pcheckpoint->nHeight) return state.DoS(100, error("AcceptBlock() : forked chain older than last checkpoint (height %d)", nHeight)); - // Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded: - // Dogecoin: reject ONLY if block.nVersion=3 has a supermajority because CBlockIndex::IsSuperMajority - // was hard-disabled until now - if (block.GetBaseVersion() < 2) - { + // Reject block.nVersion<3 blocks when 95% (75% on testnet) of the network has upgraded + // Dogecoin: reject v2 and v1 blocks at the same time, only check once + if (block.GetBaseVersion() < 3) { if ((!TestNet() && CBlockIndex::IsSuperMajority(3, pindexPrev, 1900, 2000)) || (TestNet() && CBlockIndex::IsSuperMajority(3, pindexPrev, 750, 1000))) - { - return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"), + return state.Invalid(error("AcceptBlock() : rejected nVersion<3 block"), REJECT_OBSOLETE, "bad-version"); - } } } @@ -2763,16 +2759,6 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, REJECT_INVALID, "bad-txns-nonfinal"); } - // Reject block.nVersion=2 blocks when 95% (75% on testnet) of the network has upgraded: - if (block.GetBaseVersion() < 3) - { - if ((!TestNet() && CBlockIndex::IsSuperMajority(3, pindex->pprev, 1900, 2000)) || - (TestNet() && CBlockIndex::IsSuperMajority(3, pindex->pprev, 750, 1000))) - { - return state.Invalid(error("AcceptBlock() : rejected nVersion=2 block"), - REJECT_OBSOLETE, "bad-version"); - } - } // Enforce block.nVersion=2 rule that the coinbase starts with serialized block height // Dogecoin: reject ONLY if block.nVersion=3 has a supermajority because CBlockIndex::IsSuperMajority // was hard-disabled until now