@@ -1215,71 +1215,55 @@ static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softfo
1215
1215
static void SoftForkDescPushBack (const CBlockIndex* blockindex, UniValue& softforks, const ChainstateManager& chainman, Consensus::DeploymentPos id)
1216
1216
{
1217
1217
// For BIP9 deployments.
1218
-
1219
1218
if (!DeploymentEnabled (chainman, id)) return ;
1220
1219
if (blockindex == nullptr ) return ;
1221
1220
1222
- auto get_state_name = [](const ThresholdState state) -> std::string {
1223
- switch (state) {
1224
- case ThresholdState::DEFINED: return " defined" ;
1225
- case ThresholdState::STARTED: return " started" ;
1226
- case ThresholdState::LOCKED_IN: return " locked_in" ;
1227
- case ThresholdState::ACTIVE: return " active" ;
1228
- case ThresholdState::FAILED: return " failed" ;
1229
- }
1230
- return " invalid" ;
1231
- };
1232
-
1233
1221
UniValue bip9 (UniValue::VOBJ);
1234
-
1235
- const ThresholdState next_state = chainman.m_versionbitscache .State (blockindex, chainman.GetConsensus (), id);
1236
- const ThresholdState current_state = chainman.m_versionbitscache .State (blockindex->pprev , chainman.GetConsensus (), id);
1237
-
1238
- const bool has_signal = (ThresholdState::STARTED == current_state || ThresholdState::LOCKED_IN == current_state);
1222
+ BIP9Info info{chainman.m_versionbitscache .Info (*blockindex, chainman.GetConsensus (), id)};
1223
+ const auto & depparams{chainman.GetConsensus ().vDeployments [id]};
1239
1224
1240
1225
// BIP9 parameters
1241
- if (has_signal ) {
1242
- bip9.pushKV (" bit" , chainman. GetConsensus (). vDeployments [id] .bit );
1226
+ if (info. stats . has_value () ) {
1227
+ bip9.pushKV (" bit" , depparams .bit );
1243
1228
}
1244
- bip9.pushKV (" start_time" , chainman. GetConsensus (). vDeployments [id] .nStartTime );
1245
- bip9.pushKV (" timeout" , chainman. GetConsensus (). vDeployments [id] .nTimeout );
1246
- bip9.pushKV (" min_activation_height" , chainman. GetConsensus (). vDeployments [id] .min_activation_height );
1229
+ bip9.pushKV (" start_time" , depparams .nStartTime );
1230
+ bip9.pushKV (" timeout" , depparams .nTimeout );
1231
+ bip9.pushKV (" min_activation_height" , depparams .min_activation_height );
1247
1232
1248
1233
// BIP9 status
1249
- bip9.pushKV (" status" , get_state_name ( current_state) );
1250
- bip9.pushKV (" since" , chainman. m_versionbitscache . StateSinceHeight (blockindex-> pprev , chainman. GetConsensus (), id) );
1251
- bip9.pushKV (" status_next" , get_state_name ( next_state) );
1234
+ bip9.pushKV (" status" , info. current_state );
1235
+ bip9.pushKV (" since" , info. since );
1236
+ bip9.pushKV (" status_next" , info. next_state );
1252
1237
1253
1238
// BIP9 signalling status, if applicable
1254
- if (has_signal ) {
1239
+ if (info. stats . has_value () ) {
1255
1240
UniValue statsUV (UniValue::VOBJ);
1256
- std::vector<bool > signals;
1257
- BIP9Stats statsStruct = chainman.m_versionbitscache .Statistics (blockindex, chainman.GetConsensus (), id, &signals);
1258
- statsUV.pushKV (" period" , statsStruct.period );
1259
- statsUV.pushKV (" elapsed" , statsStruct.elapsed );
1260
- statsUV.pushKV (" count" , statsStruct.count );
1261
- if (ThresholdState::LOCKED_IN != current_state) {
1262
- statsUV.pushKV (" threshold" , statsStruct.threshold );
1263
- statsUV.pushKV (" possible" , statsStruct.possible );
1241
+ statsUV.pushKV (" period" , info.stats ->period );
1242
+ statsUV.pushKV (" elapsed" , info.stats ->elapsed );
1243
+ statsUV.pushKV (" count" , info.stats ->count );
1244
+ if (info.stats ->threshold > 0 || info.stats ->possible ) {
1245
+ statsUV.pushKV (" threshold" , info.stats ->threshold );
1246
+ statsUV.pushKV (" possible" , info.stats ->possible );
1264
1247
}
1265
1248
bip9.pushKV (" statistics" , std::move (statsUV));
1266
1249
1267
1250
std::string sig;
1268
- sig.reserve (signals .size ());
1269
- for (const bool s : signals ) {
1251
+ sig.reserve (info. signalling_blocks .size ());
1252
+ for (const bool s : info. signalling_blocks ) {
1270
1253
sig.push_back (s ? ' #' : ' -' );
1271
1254
}
1272
1255
bip9.pushKV (" signalling" , sig);
1273
1256
}
1274
1257
1275
1258
UniValue rv (UniValue::VOBJ);
1276
1259
rv.pushKV (" type" , " bip9" );
1277
- if (ThresholdState::ACTIVE == next_state) {
1278
- rv.pushKV (" height" , chainman.m_versionbitscache .StateSinceHeight (blockindex, chainman.GetConsensus (), id));
1260
+ bool is_active = false ;
1261
+ if (info.active_since .has_value ()) {
1262
+ rv.pushKV (" height" , *info.active_since );
1263
+ is_active = (*info.active_since <= blockindex->nHeight + 1 );
1279
1264
}
1280
- rv.pushKV (" active" , ThresholdState::ACTIVE == next_state);
1281
- rv.pushKV (" bip9" , std::move (bip9));
1282
-
1265
+ rv.pushKV (" active" , is_active);
1266
+ rv.pushKV (" bip9" , bip9);
1283
1267
softforks.pushKV (DeploymentName (id), std::move (rv));
1284
1268
}
1285
1269
0 commit comments