consensus/params: Move version bits period/threshold to bip9 param

Rather than having the rule change period/threshold be constant for all
potential deployments on a chain, have it be specific to the deployment
itself. This both matches history (BIP 9 specified a 2016 block period
and 1916 block threshold; BIP 91 specified a 336 block period and 269
block threshold; and BIP 341 specified a 2016 block period and 1815
block threshold), and allows the code to be simplified, as only the
BIP9Deployment structure is needed, not the full Consensus::Params
structure.
This commit is contained in:
Anthony Towns
2023-12-07 12:16:22 +10:00
parent e9d617095d
commit a679040ec1
5 changed files with 76 additions and 45 deletions

View File

@@ -179,15 +179,14 @@ namespace
*/
class VersionBitsConditionChecker : public AbstractThresholdConditionChecker {
private:
const Consensus::Params& params;
const Consensus::DeploymentPos id;
const Consensus::BIP9Deployment& dep;
protected:
int64_t BeginTime() const override { return params.vDeployments[id].nStartTime; }
int64_t EndTime() const override { return params.vDeployments[id].nTimeout; }
int MinActivationHeight() const override { return params.vDeployments[id].min_activation_height; }
int Period() const override { return params.nMinerConfirmationWindow; }
int Threshold() const override { return params.nRuleChangeActivationThreshold; }
int64_t BeginTime() const override { return dep.nStartTime; }
int64_t EndTime() const override { return dep.nTimeout; }
int MinActivationHeight() const override { return dep.min_activation_height; }
int Period() const override { return dep.period; }
int Threshold() const override { return dep.threshold; }
bool Condition(const CBlockIndex* pindex) const override
{
@@ -195,8 +194,10 @@ protected:
}
public:
explicit VersionBitsConditionChecker(const Consensus::Params& params, Consensus::DeploymentPos id) : params{params}, id{id} {}
uint32_t Mask() const { return (uint32_t{1}) << params.vDeployments[id].bit; }
explicit VersionBitsConditionChecker(const Consensus::BIP9Deployment& dep) : dep{dep} {}
explicit VersionBitsConditionChecker(const Consensus::Params& params, Consensus::DeploymentPos id) : VersionBitsConditionChecker{params.vDeployments[id]} {}
uint32_t Mask() const { return (uint32_t{1}) << dep.bit; }
};
} // namespace