mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
versionbits: Move BIP9 status logic for getblocktemplate to versionbits
Rather than having the RPC code have knowledge about how BIP9 is implemented, create a reporting function in the versionbits code, and limit the RPC code to coverting the result of that into the appropriate output for getblocktemplate.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <consensus/params.h>
|
||||
#include <deploymentinfo.h>
|
||||
#include <kernel/chainparams.h>
|
||||
#include <util/check.h>
|
||||
#include <versionbits.h>
|
||||
@@ -246,6 +247,37 @@ BIP9Info VersionBitsCache::Info(const CBlockIndex& block_index, const Consensus:
|
||||
return result;
|
||||
}
|
||||
|
||||
BIP9GBTStatus VersionBitsCache::GBTStatus(const CBlockIndex& block_index, const Consensus::Params& params)
|
||||
{
|
||||
BIP9GBTStatus result;
|
||||
|
||||
LOCK(m_mutex);
|
||||
for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
|
||||
auto pos = static_cast<Consensus::DeploymentPos>(i);
|
||||
VersionBitsConditionChecker checker(params, pos);
|
||||
ThresholdState state = checker.GetStateFor(&block_index, m_caches[pos]);
|
||||
const VBDeploymentInfo& vbdepinfo = VersionBitsDeploymentInfo[pos];
|
||||
BIP9GBTStatus::Info gbtinfo{.bit=params.vDeployments[pos].bit, .mask=checker.Mask(), .gbt_force=vbdepinfo.gbt_force};
|
||||
|
||||
switch (state) {
|
||||
case DEFINED:
|
||||
case FAILED:
|
||||
// Not exposed to GBT
|
||||
break;
|
||||
case STARTED:
|
||||
result.signalling.try_emplace(vbdepinfo.name, gbtinfo);
|
||||
break;
|
||||
case LOCKED_IN:
|
||||
result.locked_in.try_emplace(vbdepinfo.name, gbtinfo);
|
||||
break;
|
||||
case ACTIVE:
|
||||
result.active.try_emplace(vbdepinfo.name, gbtinfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ThresholdState VersionBitsCache::State(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||
{
|
||||
LOCK(m_mutex);
|
||||
|
||||
Reference in New Issue
Block a user