refactor: drop global variable fDIP0001ActiveAtTip - partial implementation

Impossible to drop it completelly right now because:
 - net doesn't know any details about chain - can't check status of fork
 - the functional test feature_maxuploadtarget.py assume block size 1Mb
 - DIP0001 can't be activated from regtest early block2 because big txes are
 not allowed after DIP0001

refactor: drop global variable fDIP0001ActiveAtTip - attempt 2
This commit is contained in:
Konstantin Akimov 2023-12-05 15:32:18 +07:00 committed by PastaPastaPasta
parent 1b3237d147
commit c3c9ccf261
5 changed files with 15 additions and 8 deletions

View File

@ -35,6 +35,7 @@
#include <llmq/utils.h>
#include <masternode/payments.h>
#include <spork.h>
#include <validation.h>
#include <algorithm>
#include <utility>
@ -72,8 +73,7 @@ BlockAssembler::BlockAssembler(const CSporkManager& sporkManager, CGovernanceMan
m_evoDb(evoDb)
{
blockMinFeeRate = options.blockMinFeeRate;
// Limit size to between 1K and MaxBlockSize()-1K for sanity:
nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MaxBlockSize(fDIP0001ActiveAtTip) - 1000), (unsigned int)options.nBlockMaxSize));
nBlockMaxSize = options.nBlockMaxSize;
}
static BlockAssembler::Options DefaultOptions()
@ -133,10 +133,15 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
assert(pindexPrev != nullptr);
nHeight = pindexPrev->nHeight + 1;
const bool fDIP0001Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0001)};
const bool fDIP0003Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0003)};
const bool fDIP0008Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0008)};
const bool fV20Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V20)};
// Limit size to between 1K and MaxBlockSize()-1K for sanity:
nBlockMaxSize = std::max<unsigned int>(1000, std::min<unsigned int>(MaxBlockSize(fDIP0001Active_context) - 1000, nBlockMaxSize));
nBlockMaxSigOps = MaxBlockSigOps(fDIP0001Active_context);
pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
// Non-mainnet only: allow overriding block.nVersion with
// -blockversion=N to test forking scenarios
@ -284,7 +289,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, unsigned int packageSigOp
{
if (nBlockSize + packageSize >= nBlockMaxSize)
return false;
if (nBlockSigOps + packageSigOps >= MaxBlockSigOps(fDIP0001ActiveAtTip))
if (nBlockSigOps + packageSigOps >= nBlockMaxSigOps)
return false;
return true;
}

View File

@ -8,7 +8,6 @@
#include <primitives/block.h>
#include <txmempool.h>
#include <validation.h>
#include <memory>
#include <optional>
@ -20,6 +19,7 @@
class CBlockIndex;
class CChainParams;
class CConnman;
class CEvoDB;
class CGovernanceManager;
class CScript;
class CSporkManager;
@ -142,6 +142,7 @@ private:
// Configuration parameters for the block size
unsigned int nBlockMaxSize;
unsigned int nBlockMaxSigOps;
CFeeRate blockMinFeeRate;
// Information on the current status of the block

View File

@ -29,7 +29,7 @@
#include <util/thread.h>
#include <util/time.h>
#include <util/translation.h>
#include <validation.h>
#include <validation.h> // for fDIP0001ActiveAtTip
#include <masternode/meta.h>
#include <masternode/sync.h>

View File

@ -903,6 +903,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
aMutable.push_back("version/force");
}
const bool fDIP0001Active_context{DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0001)};
result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex());
result.pushKV("transactions", transactions);
result.pushKV("coinbaseaux", aux);
@ -912,8 +913,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1);
result.pushKV("mutable", aMutable);
result.pushKV("noncerange", "00000000ffffffff");
result.pushKV("sigoplimit", (int64_t)MaxBlockSigOps(fDIP0001ActiveAtTip));
result.pushKV("sizelimit", (int64_t)MaxBlockSize(fDIP0001ActiveAtTip));
result.pushKV("sigoplimit", (int64_t)MaxBlockSigOps(fDIP0001Active_context));
result.pushKV("sizelimit", (int64_t)MaxBlockSize(fDIP0001Active_context));
result.pushKV("curtime", pblock->GetBlockTime());
result.pushKV("bits", strprintf("%08x", pblock->nBits));
result.pushKV("previousbits", strprintf("%08x", pblocktemplate->nPrevBits));

View File

@ -156,7 +156,7 @@ bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
uint64_t nPruneTarget = 0;
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
// TODO: drop this global variable
// TODO: drop this global variable. Used by net.cpp module only
std::atomic<bool> fDIP0001ActiveAtTip{false};
uint256 hashAssumeValid;