Litecoin: Enforce v2 blocks, mainnet >= 710k, testnet >= 400k

regtest/unittest uses supermajority rule
This commit is contained in:
Warren Togami 2015-01-19 01:51:55 -10:00
parent 8bd58f9d1d
commit c293a2efd2
3 changed files with 56 additions and 5 deletions

View File

@ -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

View File

@ -79,6 +79,9 @@ public:
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
const std::vector<CAddress>& 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;
};
/**

View File

@ -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() ||