6
6
#include < util/check.h>
7
7
#include < versionbits.h>
8
8
9
- ThresholdState AbstractThresholdConditionChecker::GetStateFor (const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
9
+ ThresholdState AbstractThresholdConditionChecker::GetStateFor (const CBlockIndex* pindexPrev, ThresholdConditionCache& cache) const
10
10
{
11
- int nPeriod = Period (params );
12
- int nThreshold = Threshold (params );
13
- int min_activation_height = MinActivationHeight (params );
14
- int64_t nTimeStart = BeginTime (params );
15
- int64_t nTimeTimeout = EndTime (params );
11
+ int nPeriod = Period ();
12
+ int nThreshold = Threshold ();
13
+ int min_activation_height = MinActivationHeight ();
14
+ int64_t nTimeStart = BeginTime ();
15
+ int64_t nTimeTimeout = EndTime ();
16
16
17
17
// Check if this deployment is always active.
18
18
if (nTimeStart == Consensus::BIP9Deployment::ALWAYS_ACTIVE) {
@@ -68,7 +68,7 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
68
68
const CBlockIndex* pindexCount = pindexPrev;
69
69
int count = 0 ;
70
70
for (int i = 0 ; i < nPeriod; i++) {
71
- if (Condition (pindexCount, params )) {
71
+ if (Condition (pindexCount)) {
72
72
count++;
73
73
}
74
74
pindexCount = pindexCount->pprev ;
@@ -99,12 +99,12 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
99
99
return state;
100
100
}
101
101
102
- BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor (const CBlockIndex* pindex, const Consensus::Params& params, std::vector<bool >* signalling_blocks) const
102
+ BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor (const CBlockIndex* pindex, std::vector<bool >* signalling_blocks) const
103
103
{
104
104
BIP9Stats stats = {};
105
105
106
- stats.period = Period (params );
107
- stats.threshold = Threshold (params );
106
+ stats.period = Period ();
107
+ stats.threshold = Threshold ();
108
108
109
109
if (pindex == nullptr ) return stats;
110
110
@@ -123,7 +123,7 @@ BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockI
123
123
do {
124
124
++elapsed;
125
125
--blocks_in_period;
126
- if (Condition (currentIndex, params )) {
126
+ if (Condition (currentIndex)) {
127
127
++count;
128
128
if (signalling_blocks) signalling_blocks->at (blocks_in_period) = true ;
129
129
}
@@ -137,21 +137,21 @@ BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockI
137
137
return stats;
138
138
}
139
139
140
- int AbstractThresholdConditionChecker::GetStateSinceHeightFor (const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
140
+ int AbstractThresholdConditionChecker::GetStateSinceHeightFor (const CBlockIndex* pindexPrev, ThresholdConditionCache& cache) const
141
141
{
142
- int64_t start_time = BeginTime (params );
142
+ int64_t start_time = BeginTime ();
143
143
if (start_time == Consensus::BIP9Deployment::ALWAYS_ACTIVE || start_time == Consensus::BIP9Deployment::NEVER_ACTIVE) {
144
144
return 0 ;
145
145
}
146
146
147
- const ThresholdState initialState = GetStateFor (pindexPrev, params, cache);
147
+ const ThresholdState initialState = GetStateFor (pindexPrev, cache);
148
148
149
149
// BIP 9 about state DEFINED: "The genesis block is by definition in this state for each deployment."
150
150
if (initialState == ThresholdState::DEFINED) {
151
151
return 0 ;
152
152
}
153
153
154
- const int nPeriod = Period (params );
154
+ const int nPeriod = Period ();
155
155
156
156
// A block's state is always the same as that of the first of its period, so it is computed based on a pindexPrev whose height equals a multiple of nPeriod - 1.
157
157
// To ease understanding of the following height calculation, it helps to remember that
@@ -163,7 +163,7 @@ int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex*
163
163
164
164
const CBlockIndex* previousPeriodParent = pindexPrev->GetAncestor (pindexPrev->nHeight - nPeriod);
165
165
166
- while (previousPeriodParent != nullptr && GetStateFor (previousPeriodParent, params, cache) == initialState) {
166
+ while (previousPeriodParent != nullptr && GetStateFor (previousPeriodParent, cache) == initialState) {
167
167
pindexPrev = previousPeriodParent;
168
168
previousPeriodParent = pindexPrev->GetAncestor (pindexPrev->nHeight - nPeriod);
169
169
}
@@ -179,47 +179,48 @@ namespace
179
179
*/
180
180
class VersionBitsConditionChecker : public AbstractThresholdConditionChecker {
181
181
private:
182
+ const Consensus::Params& params;
182
183
const Consensus::DeploymentPos id;
183
184
184
185
protected:
185
- int64_t BeginTime (const Consensus::Params& params ) const override { return params.vDeployments [id].nStartTime ; }
186
- int64_t EndTime (const Consensus::Params& params ) const override { return params.vDeployments [id].nTimeout ; }
187
- int MinActivationHeight (const Consensus::Params& params ) const override { return params.vDeployments [id].min_activation_height ; }
188
- int Period (const Consensus::Params& params ) const override { return params.nMinerConfirmationWindow ; }
189
- int Threshold (const Consensus::Params& params ) const override { return params.nRuleChangeActivationThreshold ; }
186
+ int64_t BeginTime () const override { return params.vDeployments [id].nStartTime ; }
187
+ int64_t EndTime () const override { return params.vDeployments [id].nTimeout ; }
188
+ int MinActivationHeight () const override { return params.vDeployments [id].min_activation_height ; }
189
+ int Period () const override { return params.nMinerConfirmationWindow ; }
190
+ int Threshold () const override { return params.nRuleChangeActivationThreshold ; }
190
191
191
- bool Condition (const CBlockIndex* pindex, const Consensus::Params& params ) const override
192
+ bool Condition (const CBlockIndex* pindex) const override
192
193
{
193
- return (((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) && (pindex->nVersion & Mask (params )) != 0 );
194
+ return (((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) && (pindex->nVersion & Mask ()) != 0 );
194
195
}
195
196
196
197
public:
197
- explicit VersionBitsConditionChecker (Consensus::DeploymentPos id_ ) : id(id_) {}
198
- uint32_t Mask (const Consensus::Params& params ) const { return (uint32_t {1 }) << params.vDeployments [id].bit ; }
198
+ explicit VersionBitsConditionChecker (const Consensus::Params& params, Consensus:: DeploymentPos id ) : params{params}, id{id} {}
199
+ uint32_t Mask () const { return (uint32_t {1 }) << params.vDeployments [id].bit ; }
199
200
};
200
201
201
202
} // namespace
202
203
203
204
ThresholdState VersionBitsCache::State (const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)
204
205
{
205
206
LOCK (m_mutex);
206
- return VersionBitsConditionChecker (pos).GetStateFor (pindexPrev, params , m_caches[pos]);
207
+ return VersionBitsConditionChecker (params, pos).GetStateFor (pindexPrev, m_caches[pos]);
207
208
}
208
209
209
210
BIP9Stats VersionBitsCache::Statistics (const CBlockIndex* pindex, const Consensus::Params& params, Consensus::DeploymentPos pos, std::vector<bool >* signalling_blocks)
210
211
{
211
- return VersionBitsConditionChecker (pos).GetStateStatisticsFor (pindex, params , signalling_blocks);
212
+ return VersionBitsConditionChecker (params, pos).GetStateStatisticsFor (pindex, signalling_blocks);
212
213
}
213
214
214
215
int VersionBitsCache::StateSinceHeight (const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)
215
216
{
216
217
LOCK (m_mutex);
217
- return VersionBitsConditionChecker (pos).GetStateSinceHeightFor (pindexPrev, params , m_caches[pos]);
218
+ return VersionBitsConditionChecker (params, pos).GetStateSinceHeightFor (pindexPrev, m_caches[pos]);
218
219
}
219
220
220
221
uint32_t VersionBitsCache::Mask (const Consensus::Params& params, Consensus::DeploymentPos pos)
221
222
{
222
- return VersionBitsConditionChecker (pos).Mask (params );
223
+ return VersionBitsConditionChecker (params, pos).Mask ();
223
224
}
224
225
225
226
int32_t VersionBitsCache::ComputeBlockVersion (const CBlockIndex* pindexPrev, const Consensus::Params& params)
@@ -229,7 +230,7 @@ int32_t VersionBitsCache::ComputeBlockVersion(const CBlockIndex* pindexPrev, con
229
230
230
231
for (int i = 0 ; i < (int )Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
231
232
Consensus::DeploymentPos pos = static_cast <Consensus::DeploymentPos>(i);
232
- ThresholdState state = VersionBitsConditionChecker (pos).GetStateFor (pindexPrev, params , m_caches[pos]);
233
+ ThresholdState state = VersionBitsConditionChecker (params, pos).GetStateFor (pindexPrev, m_caches[pos]);
233
234
if (state == ThresholdState::LOCKED_IN || state == ThresholdState::STARTED) {
234
235
nVersion |= Mask (params, pos);
235
236
}
0 commit comments