Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,723 Lines • ▼ Show 20 Lines | static bool ConnectBlock(const Config &config, const CBlock &block, | ||||
// Start enforcing BIP68 (sequence locks). | // Start enforcing BIP68 (sequence locks). | ||||
int nLockTimeFlags = 0; | int nLockTimeFlags = 0; | ||||
if (pindex->nHeight >= consensusParams.CSVHeight) { | if (pindex->nHeight >= consensusParams.CSVHeight) { | ||||
nLockTimeFlags |= LOCKTIME_VERIFY_SEQUENCE; | nLockTimeFlags |= LOCKTIME_VERIFY_SEQUENCE; | ||||
} | } | ||||
const uint32_t flags = GetBlockScriptFlags(config, pindex->pprev); | const uint32_t flags = GetBlockScriptFlags(config, pindex->pprev); | ||||
const bool fIsMagneticAnomalyEnabled = | |||||
IsMagneticAnomalyEnabled(config, pindex->pprev); | |||||
int64_t nTime2 = GetTimeMicros(); | int64_t nTime2 = GetTimeMicros(); | ||||
nTimeForks += nTime2 - nTime1; | nTimeForks += nTime2 - nTime1; | ||||
LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs]\n", | LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs]\n", | ||||
0.001 * (nTime2 - nTime1), nTimeForks * 0.000001); | 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001); | ||||
CBlockUndo blockundo; | CBlockUndo blockundo; | ||||
Show All 17 Lines | for (const auto &ptx : block.vtx) { | ||||
nInputs += tx.vin.size(); | nInputs += tx.vin.size(); | ||||
if (tx.IsCoinBase()) { | if (tx.IsCoinBase()) { | ||||
// We've already checked for sigops count before P2SH in CheckBlock. | // We've already checked for sigops count before P2SH in CheckBlock. | ||||
nSigOpsCount += GetSigOpCountWithoutP2SH(tx, flags); | nSigOpsCount += GetSigOpCountWithoutP2SH(tx, flags); | ||||
} | } | ||||
if (fIsMagneticAnomalyEnabled || tx.IsCoinBase()) { | // We do not need to throw when a transaction is duplicated. If they are | ||||
// We do not need to throw when a transaction is duplicated. If they | // in the same block, CheckBlock will catch it, and if they are in a | ||||
// are in the same block, CheckBlock will catch it, and if they are | // different block, it'll register as a double spend or BIP30 violation. | ||||
// in a different block, it'll register as a double spend or BIP30 | // In both cases, we get a more meaningful feedback out of it. | ||||
// violation. In both cases, we get a more meaningful feedback out | |||||
// of it. | |||||
AddCoins(view, tx, pindex->nHeight, true); | AddCoins(view, tx, pindex->nHeight, true); | ||||
} | } | ||||
} | |||||
for (const auto &ptx : block.vtx) { | for (const auto &ptx : block.vtx) { | ||||
const CTransaction &tx = *ptx; | const CTransaction &tx = *ptx; | ||||
if (tx.IsCoinBase()) { | if (tx.IsCoinBase()) { | ||||
continue; | continue; | ||||
} | } | ||||
if (!view.HaveInputs(tx)) { | if (!view.HaveInputs(tx)) { | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | for (const auto &ptx : block.vtx) { | ||||
return error("ConnectBlock(): CheckInputs on %s failed with %s", | return error("ConnectBlock(): CheckInputs on %s failed with %s", | ||||
tx.GetId().ToString(), FormatStateMessage(state)); | tx.GetId().ToString(), FormatStateMessage(state)); | ||||
} | } | ||||
control.Add(vChecks); | control.Add(vChecks); | ||||
blockundo.vtxundo.push_back(CTxUndo()); | blockundo.vtxundo.push_back(CTxUndo()); | ||||
SpendCoins(view, tx, blockundo.vtxundo.back(), pindex->nHeight); | SpendCoins(view, tx, blockundo.vtxundo.back(), pindex->nHeight); | ||||
if (!fIsMagneticAnomalyEnabled) { | |||||
AddCoins(view, tx, pindex->nHeight); | |||||
} | |||||
} | } | ||||
int64_t nTime3 = GetTimeMicros(); | int64_t nTime3 = GetTimeMicros(); | ||||
nTimeConnect += nTime3 - nTime2; | nTimeConnect += nTime3 - nTime2; | ||||
LogPrint(BCLog::BENCH, | LogPrint(BCLog::BENCH, | ||||
" - Connect %u transactions: %.2fms (%.3fms/tx, " | " - Connect %u transactions: %.2fms (%.3fms/tx, " | ||||
"%.3fms/txin) [%.2fs]\n", | "%.3fms/txin) [%.2fs]\n", | ||||
(unsigned)block.vtx.size(), 0.001 * (nTime3 - nTime2), | (unsigned)block.vtx.size(), 0.001 * (nTime3 - nTime2), | ||||
▲ Show 20 Lines • Show All 351 Lines • ▼ Show 20 Lines | if (!FlushStateToDisk(config.GetChainParams(), state, | ||||
FLUSH_STATE_IF_NEEDED)) { | FLUSH_STATE_IF_NEEDED)) { | ||||
return false; | return false; | ||||
} | } | ||||
// If this block was deactivating the replay protection, then we need to | // If this block was deactivating the replay protection, then we need to | ||||
// remove transactions that are replay protected from the mempool. There is | // remove transactions that are replay protected from the mempool. There is | ||||
// no easy way to do this so we'll just discard the whole mempool and then | // no easy way to do this so we'll just discard the whole mempool and then | ||||
// add the transaction of the block we just disconnected back. | // add the transaction of the block we just disconnected back. | ||||
// | if (IsReplayProtectionEnabled(config, pindexDelete) && | ||||
// If we are deactivating Magnetic anomaly, we want to make sure we do not | !IsReplayProtectionEnabled(config, pindexDelete->pprev)) { | ||||
// have transactions in the mempool that use newly introduced opcodes. As a | |||||
// result, we also cleanup the mempool. | |||||
if ((IsReplayProtectionEnabled(config, pindexDelete) && | |||||
!IsReplayProtectionEnabled(config, pindexDelete->pprev)) || | |||||
(IsMagneticAnomalyEnabled(config, pindexDelete) && | |||||
!IsMagneticAnomalyEnabled(config, pindexDelete->pprev))) { | |||||
LogPrint(BCLog::MEMPOOL, "Clearing mempool for reorg"); | LogPrint(BCLog::MEMPOOL, "Clearing mempool for reorg"); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// While not strictly necessary, clearing the disconnect pool is also | // While not strictly necessary, clearing the disconnect pool is also | ||||
// beneficial so we don't try to reuse its content at the end of the | // beneficial so we don't try to reuse its content at the end of the | ||||
// reorg, which we know will fail. | // reorg, which we know will fail. | ||||
if (disconnectpool) { | if (disconnectpool) { | ||||
disconnectpool->clear(); | disconnectpool->clear(); | ||||
▲ Show 20 Lines • Show All 3,301 Lines • Show Last 20 Lines |