aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-06-09 12:47:12 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-06-09 12:52:29 +0200
commit62fdf381fa707206140f80e010e15de23ca3c8fd (patch)
tree74481380f2eea8a6ea74a6273136019e80eba108 /src/main.cpp
parent07b233a1b6e5f15ac7c8b3343088d1b2f3c8e1f1 (diff)
parentf0a83fc256023f68cc046bd096de69f16ce9d394 (diff)
downloadbitcoin-62fdf381fa707206140f80e010e15de23ca3c8fd.tar.xz
Merge pull request #3824
f0a83fc Use Params().NetworkID() instead of TestNet() from the payment protocol (jtimon) 2871889 net.h was using std namespace through chainparams.h included in protocol.h (jtimon) c8c52de Replace virtual methods with static attributes, chainparams.h depends on protocol.h instead of the other way around (jtimon) a3d946e Get rid of TestNet() (jtimon) 6fc0fa6 Add RPCisTestNet chain parameter (jtimon) cfeb823 Add RequireStandard chain parameter (jtimon) 21913a9 Add AllowMinDifficultyBlocks chain parameter (jtimon) d754f34 Move majority constants to chainparams (jtimon) 8d26721 Get rid of RegTest() (jtimon) cb9bd83 Add DefaultCheckMemPool chain parameter (jtimon) 2595b9a Add DefaultMinerThreads chain parameter (jtimon) bfa9a1a Add MineBlocksOnDemand chain parameter (jtimon) 1712adb Add MiningRequiresPeers chain parameter (jtimon)
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 16d1cba6ef..5d1ff94f5d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -828,7 +828,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
// Rather not work on nonstandard transactions (unless -testnet/-regtest)
string reason;
- if (Params().NetworkID() == CChainParams::MAIN && !IsStandardTx(tx, reason))
+ if (Params().RequireStandard() && !IsStandardTx(tx, reason))
return state.DoS(0,
error("AcceptToMemoryPool : nonstandard transaction: %s", reason),
REJECT_NONSTANDARD, reason);
@@ -892,7 +892,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
}
// Check for non-standard pay-to-script-hash in inputs
- if (Params().NetworkID() == CChainParams::MAIN && !AreInputsStandard(tx, view))
+ if (Params().RequireStandard() && !AreInputsStandard(tx, view))
return error("AcceptToMemoryPool: : nonstandard transaction input");
// Note: if you modify this code to accept non-standard transactions, then
@@ -1207,7 +1207,7 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime)
const uint256 &bnLimit = Params().ProofOfWorkLimit();
// Testnet has min-difficulty blocks
// after nTargetSpacing*2 time between blocks:
- if (TestNet() && nTime > nTargetSpacing*2)
+ if (Params().AllowMinDifficultyBlocks() && nTime > nTargetSpacing*2)
return bnLimit.GetCompact();
uint256 bnResult;
@@ -1235,7 +1235,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
// Only change once per interval
if ((pindexLast->nHeight+1) % nInterval != 0)
{
- if (TestNet())
+ if (Params().AllowMinDifficultyBlocks())
{
// Special difficulty rule for testnet:
// If the new block's timestamp is more than 2* 10 minutes
@@ -1465,7 +1465,7 @@ void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev)
block.nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
// Updating time can change work required on testnet:
- if (TestNet())
+ if (Params().AllowMinDifficultyBlocks())
block.nBits = GetNextWorkRequired(pindexPrev, &block);
}
@@ -2482,14 +2482,11 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
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:
- if (block.nVersion < 2)
+ if (block.nVersion < 2 &&
+ CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority()))
{
- if ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 950, 1000)) ||
- (TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 75, 100)))
- {
- return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"),
- REJECT_OBSOLETE, "bad-version");
- }
+ return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"),
+ REJECT_OBSOLETE, "bad-version");
}
}
@@ -2529,19 +2526,15 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
}
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
- if (block.nVersion >= 2)
+ // if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
+ if (block.nVersion >= 2 &&
+ CBlockIndex::IsSuperMajority(2, pindex->pprev, Params().EnforceBlockUpgradeMajority()))
{
- // if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
- if ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 750, 1000)) ||
- (TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 51, 100)))
- {
- CScript expect = CScript() << nHeight;
- if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
- !std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) {
- pindex->nStatus |= BLOCK_FAILED_VALID;
- return state.DoS(100, error("AcceptBlock() : block height mismatch in coinbase"),
- REJECT_INVALID, "bad-cb-height");
- }
+ CScript expect = CScript() << nHeight;
+ if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
+ !std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) {
+ pindex->nStatus |= BLOCK_FAILED_VALID;
+ return state.DoS(100, error("AcceptBlock() : block height mismatch in coinbase"), REJECT_INVALID, "bad-cb-height");
}
}
@@ -2565,8 +2558,9 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
return true;
}
-bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired, unsigned int nToCheck)
+bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired)
{
+ unsigned int nToCheck = Params().ToCheckBlockUpgradeMajority();
unsigned int nFound = 0;
for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++)
{