mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
Merge 7c08d81e11 into merged_master (Bitcoin PR bitcoin/bitcoin#23536)
This commit is contained in:
commit
087b2f13f4
4 changed files with 37 additions and 43 deletions
43
src/validation.cpp
Normal file → Executable file
43
src/validation.cpp
Normal file → Executable file
|
|
@ -267,7 +267,7 @@ bool CheckSequenceLocksAtTip(CBlockIndex* tip,
|
|||
}
|
||||
|
||||
// Returns the script flags which should be checked for a given block
|
||||
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& chainparams);
|
||||
static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Consensus::Params& chainparams);
|
||||
|
||||
static void LimitMempoolSize(CTxMemPool& pool, CCoinsViewCache& coins_cache, size_t limit, std::chrono::seconds age)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main, pool.cs)
|
||||
|
|
@ -1104,7 +1104,7 @@ bool MemPoolAccept::ConsensusScriptChecks(const ATMPArgs& args, Workspace& ws)
|
|||
// There is a similar check in CreateNewBlock() to prevent creating
|
||||
// invalid blocks (using TestBlockValidity), however allowing such
|
||||
// transactions into the mempool can be exploited as a DoS attack.
|
||||
unsigned int currentBlockScriptVerifyFlags = GetBlockScriptFlags(m_active_chainstate.m_chain.Tip(), chainparams.GetConsensus());
|
||||
unsigned int currentBlockScriptVerifyFlags{GetBlockScriptFlags(*m_active_chainstate.m_chain.Tip(), chainparams.GetConsensus())};
|
||||
if (!CheckInputsFromMempoolAndCache(tx, state, m_view, m_pool, currentBlockScriptVerifyFlags,
|
||||
ws.m_precomputed_txdata, m_active_chainstate.CoinsTip())) {
|
||||
LogPrintf("BUG! PLEASE REPORT THIS! CheckInputScripts failed against latest-block but not STANDARD flags %s, %s\n", hash.ToString(), state.ToString());
|
||||
|
|
@ -1992,49 +1992,43 @@ public:
|
|||
|
||||
static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS] GUARDED_BY(cs_main);
|
||||
|
||||
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams)
|
||||
static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Consensus::Params& consensusparams)
|
||||
{
|
||||
unsigned int flags = SCRIPT_VERIFY_NONE;
|
||||
|
||||
// BIP16 didn't become active until Apr 1 2012 (on mainnet, and
|
||||
// retroactively applied to testnet)
|
||||
// However, only one historical block violated the P2SH rules (on both
|
||||
// mainnet and testnet), so for simplicity, always leave P2SH
|
||||
// on except for the one violating block.
|
||||
if (consensusparams.BIP16Exception.IsNull() || // no bip16 exception on this chain
|
||||
pindex->phashBlock == nullptr || // this is a new candidate block, eg from TestBlockValidity()
|
||||
*pindex->phashBlock != consensusparams.BIP16Exception) // this block isn't the historical exception
|
||||
{
|
||||
// Enforce WITNESS rules whenever P2SH is in effect
|
||||
flags |= SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS;
|
||||
// mainnet and testnet).
|
||||
// Similarly, only one historical block violated the TAPROOT rules on
|
||||
// mainnet.
|
||||
// For simplicity, always leave P2SH+WITNESS+TAPROOT on except for the two
|
||||
// violating blocks.
|
||||
uint32_t flags{SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_TAPROOT};
|
||||
const auto it{consensusparams.script_flag_exceptions.find(*Assert(block_index.phashBlock))};
|
||||
if (it != consensusparams.script_flag_exceptions.end()) {
|
||||
flags = it->second;
|
||||
}
|
||||
|
||||
// Enforce the DERSIG (BIP66) rule
|
||||
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_DERSIG)) {
|
||||
if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_DERSIG)) {
|
||||
flags |= SCRIPT_VERIFY_DERSIG;
|
||||
}
|
||||
|
||||
// Enforce CHECKLOCKTIMEVERIFY (BIP65)
|
||||
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_CLTV)) {
|
||||
if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_CLTV)) {
|
||||
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
|
||||
}
|
||||
|
||||
// Enforce CHECKSEQUENCEVERIFY (BIP112)
|
||||
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_CSV)) {
|
||||
if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_CSV)) {
|
||||
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
|
||||
}
|
||||
|
||||
// Enforce Taproot (BIP340-BIP342)
|
||||
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_TAPROOT)) {
|
||||
flags |= SCRIPT_VERIFY_TAPROOT;
|
||||
}
|
||||
|
||||
// Enforce BIP147 NULLDUMMY (activated simultaneously with segwit)
|
||||
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_SEGWIT)) {
|
||||
if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_SEGWIT)) {
|
||||
flags |= SCRIPT_VERIFY_NULLDUMMY;
|
||||
}
|
||||
|
||||
if (DeploymentActiveAfter(pindex->pprev, consensusparams, Consensus::DEPLOYMENT_DYNA_FED)) {
|
||||
if (DeploymentActiveAfter(block_index.pprev, consensusparams, Consensus::DEPLOYMENT_DYNA_FED)) {
|
||||
flags |= SCRIPT_SIGHASH_RANGEPROOF;
|
||||
}
|
||||
|
||||
|
|
@ -2042,7 +2036,6 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
|
|||
}
|
||||
|
||||
|
||||
|
||||
static int64_t nTimeCheck = 0;
|
||||
static int64_t nTimeForks = 0;
|
||||
static int64_t nTimeVerify = 0;
|
||||
|
|
@ -2274,7 +2267,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
|||
}
|
||||
|
||||
// Get the script flags for this block
|
||||
unsigned int flags = GetBlockScriptFlags(pindex, m_params.GetConsensus());
|
||||
unsigned int flags{GetBlockScriptFlags(*pindex, m_params.GetConsensus())};
|
||||
|
||||
int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1;
|
||||
LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime2 - nTime1), nTimeForks * MICRO, nTimeForks * MILLI / nBlocksTotal);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue