Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 589 Lines • ▼ Show 20 Lines | bool IsMagneticAnomalyEnabled(const Config &config, | ||||
const CBlockIndex *pindexPrev) { | const CBlockIndex *pindexPrev) { | ||||
if (pindexPrev == nullptr) { | if (pindexPrev == nullptr) { | ||||
return false; | return false; | ||||
} | } | ||||
return IsMagneticAnomalyEnabled(config, pindexPrev->GetMedianTimePast()); | return IsMagneticAnomalyEnabled(config, pindexPrev->GetMedianTimePast()); | ||||
} | } | ||||
static bool IsMagneticAnomalyEnabledForCurrentBlock(const Config &config) { | |||||
AssertLockHeld(cs_main); | |||||
return IsMagneticAnomalyEnabled(config, chainActive.Tip()); | |||||
} | |||||
static bool IsReplayProtectionEnabled(const Config &config, | static bool IsReplayProtectionEnabled(const Config &config, | ||||
int64_t nMedianTimePast) { | int64_t nMedianTimePast) { | ||||
return nMedianTimePast >= gArgs.GetArg("-replayprotectionactivationtime", | return nMedianTimePast >= gArgs.GetArg("-replayprotectionactivationtime", | ||||
config.GetChainParams() | config.GetChainParams() | ||||
.GetConsensus() | .GetConsensus() | ||||
.magneticAnomalyActivationTime); | .magneticAnomalyActivationTime); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 361 Lines • ▼ Show 20 Lines | // Check for conflicts with in-memory transactions | ||||
} | } | ||||
// Set extraFlags as a set of flags that needs to be activated. | // Set extraFlags as a set of flags that needs to be activated. | ||||
uint32_t extraFlags = SCRIPT_VERIFY_NONE; | uint32_t extraFlags = SCRIPT_VERIFY_NONE; | ||||
if (IsReplayProtectionEnabledForCurrentBlock(config)) { | if (IsReplayProtectionEnabledForCurrentBlock(config)) { | ||||
extraFlags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | extraFlags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | ||||
} | } | ||||
if (IsMagneticAnomalyEnabledForCurrentBlock(config)) { | |||||
extraFlags |= SCRIPT_ENABLE_CHECKDATASIG; | |||||
} | |||||
// Check inputs based on the set of flags we activate. | // Check inputs based on the set of flags we activate. | ||||
uint32_t scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS; | uint32_t scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS; | ||||
if (!config.GetChainParams().RequireStandard()) { | if (!config.GetChainParams().RequireStandard()) { | ||||
scriptVerifyFlags = | scriptVerifyFlags = | ||||
SCRIPT_ENABLE_SIGHASH_FORKID | | SCRIPT_ENABLE_SIGHASH_FORKID | | ||||
gArgs.GetArg("-promiscuousmempoolflags", scriptVerifyFlags); | gArgs.GetArg("-promiscuousmempoolflags", scriptVerifyFlags); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 928 Lines • ▼ Show 20 Lines | static uint32_t GetBlockScriptFlags(const Config &config, | ||||
// s in their signature. We also make sure that signature that are supposed | // s in their signature. We also make sure that signature that are supposed | ||||
// to fail (for instance in multisig or other forms of smart contracts) are | // to fail (for instance in multisig or other forms of smart contracts) are | ||||
// null. | // null. | ||||
if (IsDAAEnabled(config, pChainTip)) { | if (IsDAAEnabled(config, pChainTip)) { | ||||
flags |= SCRIPT_VERIFY_LOW_S; | flags |= SCRIPT_VERIFY_LOW_S; | ||||
flags |= SCRIPT_VERIFY_NULLFAIL; | flags |= SCRIPT_VERIFY_NULLFAIL; | ||||
} | } | ||||
// When the magnetic anomaly fork is enabled, we start accepting | |||||
// transactions using the OP_CHECKDATASIG opcode and it's verify | |||||
// alternative. We also start enforcing push only signatures. | |||||
if (IsMagneticAnomalyEnabled(config, pChainTip)) { | if (IsMagneticAnomalyEnabled(config, pChainTip)) { | ||||
flags |= SCRIPT_ENABLE_CHECKDATASIG; | |||||
flags |= SCRIPT_VERIFY_SIGPUSHONLY; | flags |= SCRIPT_VERIFY_SIGPUSHONLY; | ||||
} | } | ||||
// We make sure this node will have replay protection during the next hard | // We make sure this node will have replay protection during the next hard | ||||
// fork. | // fork. | ||||
if (IsReplayProtectionEnabled(config, pChainTip)) { | if (IsReplayProtectionEnabled(config, pChainTip)) { | ||||
flags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | flags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 633 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) && | // | ||||
!IsReplayProtectionEnabled(config, pindexDelete->pprev)) { | // If we are deactivating Magnetic anomaly, we want to make sure we do not | ||||
// 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"); | ||||
mempool.clear(); | 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 2,980 Lines • Show Last 20 Lines |