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:
Anthony Towns
2023-12-09 08:09:36 +10:00
parent b1e967c3ec
commit 1198e7d2fd
3 changed files with 72 additions and 41 deletions

View File

@@ -66,6 +66,15 @@ struct BIP9Info {
std::optional<int> active_since;
};
struct BIP9GBTStatus {
struct Info {
int bit;
uint32_t mask;
bool gbt_force;
};
std::map<std::string, const Info, std::less<>> signalling, locked_in, active;
};
/**
* Abstract class that implements BIP9-style threshold logic, and caches results.
*/
@@ -109,6 +118,8 @@ public:
BIP9Info Info(const CBlockIndex& block_index, const Consensus::Params& params, Consensus::DeploymentPos id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
BIP9GBTStatus GBTStatus(const CBlockIndex& block_index, const Consensus::Params& params) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
/** Get the BIP9 state for a given deployment for the block after pindexPrev. */
ThresholdState State(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);