From c293a2efd280fd52873403af0ea6305aa4ca6948 Mon Sep 17 00:00:00 2001 From: Warren Togami Date: Mon, 19 Jan 2015 01:51:55 -1000 Subject: [PATCH] Litecoin: Enforce v2 blocks, mainnet >= 710k, testnet >= 400k regtest/unittest uses supermajority rule --- src/chainparams.cpp | 12 ++++++++++++ src/chainparams.h | 6 ++++++ src/main.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 9c62594d1..e8b06c738 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -176,6 +176,9 @@ public: fMineBlocksOnDemand = false; fSkipProofOfWorkCheck = false; fTestnetToBeDeprecatedFieldRPC = false; + + // Litecoin: Mainnet v2 enforced as of block 710k + nEnforceV2AfterHeight = 710000; } const Checkpoints::CCheckpointData& Checkpoints() const @@ -233,6 +236,9 @@ public: fRequireStandard = false; fMineBlocksOnDemand = false; fTestnetToBeDeprecatedFieldRPC = true; + + // Litecoin: Testnet v2 enforced as of block 400k + nEnforceV2AfterHeight = 400000; } const Checkpoints::CCheckpointData& Checkpoints() const { @@ -278,6 +284,9 @@ public: fRequireStandard = false; fMineBlocksOnDemand = true; fTestnetToBeDeprecatedFieldRPC = false; + + // Litecoin: v2 enforced using Bitcoin's supermajority rule + nEnforceV2AfterHeight = -1; } const Checkpoints::CCheckpointData& Checkpoints() const { @@ -303,6 +312,9 @@ public: fDefaultCheckMemPool = true; fAllowMinDifficultyBlocks = false; fMineBlocksOnDemand = true; + + // Litecoin: v2 enforced using Bitcoin's supermajority rule + nEnforceV2AfterHeight = -1; } const Checkpoints::CCheckpointData& Checkpoints() const diff --git a/src/chainparams.h b/src/chainparams.h index 5d1ee1d3c..488c8e55c 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -79,6 +79,9 @@ public: const std::vector& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; } const std::vector& FixedSeeds() const { return vFixedSeeds; } virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0; + + // Litecoin: Height to enforce v2 block + int EnforceV2AfterHeight() const { return nEnforceV2AfterHeight; } protected: CChainParams() {} @@ -109,6 +112,9 @@ protected: bool fMineBlocksOnDemand; bool fSkipProofOfWorkCheck; bool fTestnetToBeDeprecatedFieldRPC; + + // Litecoin: Height to enforce v2 blocks + int nEnforceV2AfterHeight; }; /** diff --git a/src/main.cpp b/src/main.cpp index c8a0d10e4..b35bf0dbf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2518,9 +2518,25 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta if (pcheckpoint && nHeight < pcheckpoint->nHeight) return state.DoS(100, error("%s : forked chain older than last checkpoint (height %d)", __func__, nHeight)); - // Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded: - if (block.nVersion < 2 && - CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority())) + // Litecoin: Reject block.nVersion=1 blocks (mainnet >= 710000, testnet >= 400000, regtest uses supermajority) + bool enforceV2 = false; + if (block.nVersion < 2) + { + if (Params().EnforceV2AfterHeight() != -1) + { + // Mainnet 710k, Testnet 400k + if (nHeight >= Params().EnforceV2AfterHeight()) + enforceV2 = true; + } + else + { + // Regtest and Unittest: use Bitcoin's supermajority rule + if (CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority())) + enforceV2 = true; + } + } + + if (enforceV2) { return state.Invalid(error("%s : rejected nVersion=1 block", __func__), REJECT_OBSOLETE, "bad-version"); @@ -2546,10 +2562,27 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn return state.DoS(10, error("%s : contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal"); } + // Litecoin: (mainnet >= 710000, testnet >= 400000, regtest uses supermajority) // Enforce block.nVersion=2 rule that the coinbase starts with serialized block height // if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet): - if (block.nVersion >= 2 && - CBlockIndex::IsSuperMajority(2, pindexPrev, Params().EnforceBlockUpgradeMajority())) + bool checkHeightMismatch = false; + if (block.nVersion >= 2) + { + if (Params().EnforceV2AfterHeight() != -1) + { + // Mainnet 710k, Testnet 400k + if (nHeight >= Params().EnforceV2AfterHeight()) + checkHeightMismatch = true; + } + else + { + // Regtest and Unittest: use Bitcoin's supermajority rule + if (CBlockIndex::IsSuperMajority(2, pindexPrev, Params().EnforceBlockUpgradeMajority())) + checkHeightMismatch = true; + } + } + + if (checkHeightMismatch) { CScript expect = CScript() << nHeight; if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||