Skip to content

Commit

Permalink
versionbits: Expose VersionBitsConditionChecker via impl header
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtowns committed Oct 12, 2024
1 parent 64cc508 commit 53a2dd6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
31 changes: 0 additions & 31 deletions src/versionbits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,36 +187,6 @@ int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex*
return pindexPrev->nHeight + 1;
}

namespace
{
/**
* Class to implement versionbits logic.
*/
class VersionBitsConditionChecker : public AbstractThresholdConditionChecker {
private:
const Consensus::BIP9Deployment& dep;

protected:
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
{
return (((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) && (pindex->nVersion & Mask()) != 0);
}

public:
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

BIP9Info VersionBitsCache::Info(const CBlockIndex& block_index, const Consensus::Params& params, Consensus::DeploymentPos id)
{
BIP9Info result;
Expand Down Expand Up @@ -253,7 +223,6 @@ BIP9Info VersionBitsCache::Info(const CBlockIndex& block_index, const Consensus:
return result;
}


BIP9GBTStatus VersionBitsCache::GBTStatus(const CBlockIndex& block_index, const Consensus::Params& params)
{
BIP9GBTStatus result;
Expand Down
26 changes: 26 additions & 0 deletions src/versionbits_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,30 @@ class AbstractThresholdConditionChecker {
int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, ThresholdConditionCache& cache) const;
};

/**
* Class to implement versionbits logic.
*/
class VersionBitsConditionChecker : public AbstractThresholdConditionChecker {
private:
const Consensus::BIP9Deployment& dep;

protected:
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
{
return (((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) && (pindex->nVersion & Mask()) != 0);
}

public:
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; }
};

#endif // BITCOIN_VERSIONBITS_IMPL_H

0 comments on commit 53a2dd6

Please sign in to comment.