Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,610 Lines • ▼ Show 20 Lines | if ((block.nVersion < 2 && nHeight >= consensusParams.BIP34Height) || | ||||
strprintf("rejected nVersion=0x%08x block", block.nVersion)); | strprintf("rejected nVersion=0x%08x block", block.nVersion)); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool ContextualCheckTransaction(const Config &config, const CTransaction &tx, | bool ContextualCheckTransaction(const Config &config, const CTransaction &tx, | ||||
CValidationState &state, int nHeight, | CValidationState &state, int nHeight, | ||||
int64_t nLockTimeCutoff) { | int64_t nLockTimeCutoff, | ||||
int64_t nMedianTImePast) { | |||||
Mengerian: Un-capitalize "i" in "nMedianTimePast" ? | |||||
if (!IsFinalTx(tx, nHeight, nLockTimeCutoff)) { | if (!IsFinalTx(tx, nHeight, nLockTimeCutoff)) { | ||||
// While this is only one transaction, we use txns in the error to | // While this is only one transaction, we use txns in the error to | ||||
// ensure continuity with other clients. | // ensure continuity with other clients. | ||||
return state.DoS(10, false, REJECT_INVALID, "bad-txns-nonfinal", false, | return state.DoS(10, false, REJECT_INVALID, "bad-txns-nonfinal", false, | ||||
"non-final transaction"); | "non-final transaction"); | ||||
} | } | ||||
if (IsMagneticAnomalyEnabled(config, nMedianTImePast)) { | |||||
// Size limit | |||||
if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) < | |||||
MIN_TX_SIZE) { | |||||
return state.DoS(100, false, REJECT_INVALID, "bad-txns-undersize"); | |||||
} | |||||
} | |||||
return true; | return true; | ||||
} | } | ||||
bool ContextualCheckTransactionForCurrentBlock(const Config &config, | bool ContextualCheckTransactionForCurrentBlock(const Config &config, | ||||
const CTransaction &tx, | const CTransaction &tx, | ||||
CValidationState &state, | CValidationState &state, | ||||
int flags) { | int flags) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
Show All 13 Lines | bool ContextualCheckTransactionForCurrentBlock(const Config &config, | ||||
// than chainActive.Height(). | // than chainActive.Height(). | ||||
const int nBlockHeight = chainActive.Height() + 1; | const int nBlockHeight = chainActive.Height() + 1; | ||||
// BIP113 will require that time-locked transactions have nLockTime set to | // BIP113 will require that time-locked transactions have nLockTime set to | ||||
// less than the median time of the previous block they're contained in. | // less than the median time of the previous block they're contained in. | ||||
// When the next block is created its previous block will be the current | // When the next block is created its previous block will be the current | ||||
// chain tip, so we use that to calculate the median time passed to | // chain tip, so we use that to calculate the median time passed to | ||||
// ContextualCheckTransaction() if LOCKTIME_MEDIAN_TIME_PAST is set. | // ContextualCheckTransaction() if LOCKTIME_MEDIAN_TIME_PAST is set. | ||||
const int64_t nMedianTimePast = | |||||
chainActive.Tip() == nullptr ? 0 | |||||
: chainActive.Tip()->GetMedianTimePast(); | |||||
const int64_t nLockTimeCutoff = (flags & LOCKTIME_MEDIAN_TIME_PAST) | const int64_t nLockTimeCutoff = (flags & LOCKTIME_MEDIAN_TIME_PAST) | ||||
? chainActive.Tip()->GetMedianTimePast() | ? nMedianTimePast | ||||
: GetAdjustedTime(); | : GetAdjustedTime(); | ||||
return ContextualCheckTransaction(config, tx, state, nBlockHeight, | return ContextualCheckTransaction(config, tx, state, nBlockHeight, | ||||
nLockTimeCutoff); | nLockTimeCutoff, nMedianTimePast); | ||||
} | } | ||||
static bool ContextualCheckBlock(const Config &config, const CBlock &block, | static bool ContextualCheckBlock(const Config &config, const CBlock &block, | ||||
CValidationState &state, | CValidationState &state, | ||||
const CBlockIndex *pindexPrev) { | const CBlockIndex *pindexPrev) { | ||||
const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; | const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; | ||||
const Consensus::Params &consensusParams = | const Consensus::Params &consensusParams = | ||||
config.GetChainParams().GetConsensus(); | config.GetChainParams().GetConsensus(); | ||||
Show All 27 Lines | for (const auto &ptx : block.vtx) { | ||||
prevTx->GetId().ToString())); | prevTx->GetId().ToString())); | ||||
} | } | ||||
if (prevTx || !tx.IsCoinBase()) { | if (prevTx || !tx.IsCoinBase()) { | ||||
prevTx = &tx; | prevTx = &tx; | ||||
} | } | ||||
} | } | ||||
LogPrintf("nLockTimeCutoff:\t%d\n", nLockTimeCutoff); | |||||
LogPrintf("MedianPastTime:\t%d\n", nMedianTimePast); | |||||
LogPrintf("MagneticAnomalyActivation:\t%d\n", | |||||
IsMagneticAnomalyEnabled(config, pindexPrev)); | |||||
if (!ContextualCheckTransaction(config, tx, state, nHeight, | if (!ContextualCheckTransaction(config, tx, state, nHeight, | ||||
nLockTimeCutoff)) { | nLockTimeCutoff, nMedianTimePast)) { | ||||
// state set by ContextualCheckTransaction. | // state set by ContextualCheckTransaction. | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
// Enforce rule that the coinbase starts with serialized block height | // Enforce rule that the coinbase starts with serialized block height | ||||
if (nHeight >= consensusParams.BIP34Height) { | if (nHeight >= consensusParams.BIP34Height) { | ||||
CScript expect = CScript() << nHeight; | CScript expect = CScript() << nHeight; | ||||
▲ Show 20 Lines • Show All 1,827 Lines • Show Last 20 Lines |
Un-capitalize "i" in "nMedianTimePast" ?