Skip to content

Commit 78adef1

Browse files
committed
refactor: use chainman instead of chainParams for DeploymentActive*
1 parent deffe0d commit 78adef1

File tree

4 files changed

+60
-63
lines changed

4 files changed

+60
-63
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ void PeerManagerImpl::FindNextBlocksToDownload(NodeId nodeid, unsigned int count
11101110
if (state->pindexLastCommonBlock == state->pindexBestKnownBlock)
11111111
return;
11121112

1113-
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
11141113
std::vector<const CBlockIndex*> vToFetch;
11151114
const CBlockIndex *pindexWalk = state->pindexLastCommonBlock;
11161115
// Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond the last
@@ -1140,7 +1139,7 @@ void PeerManagerImpl::FindNextBlocksToDownload(NodeId nodeid, unsigned int count
11401139
// We consider the chain that this peer is on invalid.
11411140
return;
11421141
}
1143-
if (!State(nodeid)->fHaveWitness && DeploymentActiveAt(*pindex, consensusParams, Consensus::DEPLOYMENT_SEGWIT)) {
1142+
if (!State(nodeid)->fHaveWitness && DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_SEGWIT)) {
11441143
// We wouldn't download this block or its descendants from this peer.
11451144
return;
11461145
}
@@ -1641,7 +1640,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
16411640
return;
16421641
m_highest_fast_announce = pindex->nHeight;
16431642

1644-
bool fWitnessEnabled = DeploymentActiveAt(*pindex, m_chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT);
1643+
bool fWitnessEnabled = DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_SEGWIT);
16451644
uint256 hashBlock(pblock->GetHash());
16461645
const std::shared_future<CSerializedNetMsg> lazy_ser{
16471646
std::async(std::launch::deferred, [&] { return msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
@@ -2258,7 +2257,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
22582257
while (pindexWalk && !m_chainman.ActiveChain().Contains(pindexWalk) && vToFetch.size() <= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
22592258
if (!(pindexWalk->nStatus & BLOCK_HAVE_DATA) &&
22602259
!IsBlockRequested(pindexWalk->GetBlockHash()) &&
2261-
(!DeploymentActiveAt(*pindexWalk, m_chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT) || State(pfrom.GetId())->fHaveWitness)) {
2260+
(!DeploymentActiveAt(*pindexWalk, m_chainman, Consensus::DEPLOYMENT_SEGWIT) || State(pfrom.GetId())->fHaveWitness)) {
22622261
// We don't have this block, and it's not yet in flight.
22632262
vToFetch.push_back(pindexWalk);
22642263
}
@@ -3629,7 +3628,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
36293628
return;
36303629
}
36313630

3632-
if (DeploymentActiveAt(*pindex, m_chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT) && !nodestate->fSupportsDesiredCmpctVersion) {
3631+
if (DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_SEGWIT) && !nodestate->fSupportsDesiredCmpctVersion) {
36333632
// Don't bother trying to process compact blocks from v1 peers
36343633
// after segwit activates.
36353634
return;

src/rpc/blockchain.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,26 +1064,26 @@ static RPCHelpMan verifychain()
10641064
};
10651065
}
10661066

1067-
static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softforks, const Consensus::Params& params, Consensus::BuriedDeployment dep)
1067+
static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softforks, const ChainstateManager& chainman, Consensus::BuriedDeployment dep)
10681068
{
10691069
// For buried deployments.
10701070

1071-
if (!DeploymentEnabled(params, dep)) return;
1071+
if (!DeploymentEnabled(chainman, dep)) return;
10721072

10731073
UniValue rv(UniValue::VOBJ);
10741074
rv.pushKV("type", "buried");
10751075
// getdeploymentinfo reports the softfork as active from when the chain height is
10761076
// one below the activation height
1077-
rv.pushKV("active", DeploymentActiveAfter(blockindex, params, dep));
1078-
rv.pushKV("height", params.DeploymentHeight(dep));
1077+
rv.pushKV("active", DeploymentActiveAfter(blockindex, chainman, dep));
1078+
rv.pushKV("height", chainman.GetConsensus().DeploymentHeight(dep));
10791079
softforks.pushKV(DeploymentName(dep), rv);
10801080
}
10811081

1082-
static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softforks, const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
1082+
static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softforks, const ChainstateManager& chainman, Consensus::DeploymentPos id)
10831083
{
10841084
// For BIP9 deployments.
10851085

1086-
if (!DeploymentEnabled(consensusParams, id)) return;
1086+
if (!DeploymentEnabled(chainman, id)) return;
10871087
if (blockindex == nullptr) return;
10881088

10891089
auto get_state_name = [](const ThresholdState state) -> std::string {
@@ -1099,29 +1099,29 @@ static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softfo
10991099

11001100
UniValue bip9(UniValue::VOBJ);
11011101

1102-
const ThresholdState next_state = g_versionbitscache.State(blockindex, consensusParams, id);
1103-
const ThresholdState current_state = g_versionbitscache.State(blockindex->pprev, consensusParams, id);
1102+
const ThresholdState next_state = g_versionbitscache.State(blockindex, chainman.GetConsensus(), id);
1103+
const ThresholdState current_state = g_versionbitscache.State(blockindex->pprev, chainman.GetConsensus(), id);
11041104

11051105
const bool has_signal = (ThresholdState::STARTED == current_state || ThresholdState::LOCKED_IN == current_state);
11061106

11071107
// BIP9 parameters
11081108
if (has_signal) {
1109-
bip9.pushKV("bit", consensusParams.vDeployments[id].bit);
1109+
bip9.pushKV("bit", chainman.GetConsensus().vDeployments[id].bit);
11101110
}
1111-
bip9.pushKV("start_time", consensusParams.vDeployments[id].nStartTime);
1112-
bip9.pushKV("timeout", consensusParams.vDeployments[id].nTimeout);
1113-
bip9.pushKV("min_activation_height", consensusParams.vDeployments[id].min_activation_height);
1111+
bip9.pushKV("start_time", chainman.GetConsensus().vDeployments[id].nStartTime);
1112+
bip9.pushKV("timeout", chainman.GetConsensus().vDeployments[id].nTimeout);
1113+
bip9.pushKV("min_activation_height", chainman.GetConsensus().vDeployments[id].min_activation_height);
11141114

11151115
// BIP9 status
11161116
bip9.pushKV("status", get_state_name(current_state));
1117-
bip9.pushKV("since", g_versionbitscache.StateSinceHeight(blockindex->pprev, consensusParams, id));
1117+
bip9.pushKV("since", g_versionbitscache.StateSinceHeight(blockindex->pprev, chainman.GetConsensus(), id));
11181118
bip9.pushKV("status_next", get_state_name(next_state));
11191119

11201120
// BIP9 signalling status, if applicable
11211121
if (has_signal) {
11221122
UniValue statsUV(UniValue::VOBJ);
11231123
std::vector<bool> signals;
1124-
BIP9Stats statsStruct = g_versionbitscache.Statistics(blockindex, consensusParams, id, &signals);
1124+
BIP9Stats statsStruct = g_versionbitscache.Statistics(blockindex, chainman.GetConsensus(), id, &signals);
11251125
statsUV.pushKV("period", statsStruct.period);
11261126
statsUV.pushKV("elapsed", statsStruct.elapsed);
11271127
statsUV.pushKV("count", statsStruct.count);
@@ -1142,7 +1142,7 @@ static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softfo
11421142
UniValue rv(UniValue::VOBJ);
11431143
rv.pushKV("type", "bip9");
11441144
if (ThresholdState::ACTIVE == next_state) {
1145-
rv.pushKV("height", g_versionbitscache.StateSinceHeight(blockindex, consensusParams, id));
1145+
rv.pushKV("height", g_versionbitscache.StateSinceHeight(blockindex, chainman.GetConsensus(), id));
11461146
}
11471147
rv.pushKV("active", ThresholdState::ACTIVE == next_state);
11481148
rv.pushKV("bip9", bip9);
@@ -1152,7 +1152,7 @@ static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softfo
11521152

11531153
namespace {
11541154
/* TODO: when -deprecatedrpc=softforks is removed, drop these */
1155-
UniValue DeploymentInfo(const CBlockIndex* tip, const Consensus::Params& consensusParams);
1155+
UniValue DeploymentInfo(const CBlockIndex* tip, const ChainstateManager& chainman);
11561156
extern const std::vector<RPCResult> RPCHelpForDeployment;
11571157
}
11581158

@@ -1227,8 +1227,7 @@ RPCHelpMan getblockchaininfo()
12271227
}
12281228

12291229
if (IsDeprecatedRPCEnabled("softforks")) {
1230-
const Consensus::Params& consensusParams = Params().GetConsensus();
1231-
obj.pushKV("softforks", DeploymentInfo(&tip, consensusParams));
1230+
obj.pushKV("softforks", DeploymentInfo(&tip, chainman));
12321231
}
12331232

12341233
obj.pushKV("warnings", GetWarnings(false).original);
@@ -1263,16 +1262,16 @@ const std::vector<RPCResult> RPCHelpForDeployment{
12631262
}},
12641263
};
12651264

1266-
UniValue DeploymentInfo(const CBlockIndex* blockindex, const Consensus::Params& consensusParams)
1265+
UniValue DeploymentInfo(const CBlockIndex* blockindex, const ChainstateManager& chainman)
12671266
{
12681267
UniValue softforks(UniValue::VOBJ);
1269-
SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_HEIGHTINCB);
1270-
SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_DERSIG);
1271-
SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_CLTV);
1272-
SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_CSV);
1273-
SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_SEGWIT);
1274-
SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
1275-
SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_TAPROOT);
1268+
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_HEIGHTINCB);
1269+
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_DERSIG);
1270+
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_CLTV);
1271+
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_CSV);
1272+
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_SEGWIT);
1273+
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_TESTDUMMY);
1274+
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_TAPROOT);
12761275
return softforks;
12771276
}
12781277
} // anon namespace
@@ -1311,12 +1310,10 @@ static RPCHelpMan getdeploymentinfo()
13111310
}
13121311
}
13131312

1314-
const Consensus::Params& consensusParams = Params().GetConsensus();
1315-
13161313
UniValue deploymentinfo(UniValue::VOBJ);
13171314
deploymentinfo.pushKV("hash", blockindex->GetBlockHash().ToString());
13181315
deploymentinfo.pushKV("height", blockindex->nHeight);
1319-
deploymentinfo.pushKV("deployments", DeploymentInfo(blockindex, consensusParams));
1316+
deploymentinfo.pushKV("deployments", DeploymentInfo(blockindex, chainman));
13201317
return deploymentinfo;
13211318
},
13221319
};

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static RPCHelpMan getblocktemplate()
770770
pblock->nNonce = 0;
771771

772772
// NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration
773-
const bool fPreSegWit = !DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT);
773+
const bool fPreSegWit = !DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_SEGWIT);
774774

775775
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
776776

0 commit comments

Comments
 (0)