Skip to content

Instantly share code, notes, and snippets.

@Bushstar
Created May 19, 2022 13:17
Show Gist options
  • Save Bushstar/e811fe60b0150ec6a483066ce0c7e35d to your computer and use it in GitHub Desktop.
Save Bushstar/e811fe60b0150ec6a483066ce0c7e35d to your computer and use it in GitHub Desktop.
Keep Live Gov vars at 1896000
if (pindex->nHeight >= chainparams.GetConsensus().FortCanningHeight) {
// Apply any pending GovVariable changes. Will come into effect on the next block.
auto storedGovVars = cache.GetStoredVariables(static_cast<uint32_t>(pindex->nHeight));
for (const auto& var : storedGovVars) {
if (var) {
CCustomCSView govCache(cache);
// Add to existing ATTRIBUTES instead of overwriting.
if (var->GetName() == "ATTRIBUTES") {
auto govVar = mnview.GetAttributes();
// One stored var at this height on mainnet.
if (Params().NetworkIDString() == CBaseChainParams::MAIN && pindex->nHeight == 1896000)
{
for (auto it = govVar->attributes.begin(); it != govVar->attributes.end();) {
auto key = boost::get<const CDataStructureV0>(&it->first);
assert(key);
if (key->type != AttributeTypes::Live) {
govVar->attributes.erase(it++);
} else {
++it;
}
}
govVar->Import(var->Export());
govCache.SetVariable(*govVar);
govCache.Flush();
} else {
if (govVar->Import(var->Export()) && govVar->Validate(govCache) && govVar->Apply(govCache, pindex->nHeight) && govCache.SetVariable(*var)) {
govCache.Flush();
}
}
} else if (var->Validate(govCache) && var->Apply(govCache, pindex->nHeight) && govCache.SetVariable(*var)) {
govCache.Flush();
}
}
}
cache.EraseStoredVariables(static_cast<uint32_t>(pindex->nHeight));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment