mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Track best block to later know if a DB upgrade is needed
This commit is contained in:
parent
1a25c2084c
commit
7d765a0fce
@ -25,7 +25,7 @@ CQuorumBlockProcessor* quorumBlockProcessor;
|
||||
static const std::string DB_MINED_COMMITMENT = "q_mc";
|
||||
static const std::string DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT = "q_mcih";
|
||||
|
||||
static const std::string DB_UPGRADED = "q_dbupgraded";
|
||||
static const std::string DB_BEST_BLOCK_UPGRADE = "q_bbu";
|
||||
|
||||
void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
|
||||
{
|
||||
@ -121,6 +121,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*
|
||||
|
||||
bool fDIP0003Active = VersionBitsState(pindex->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE;
|
||||
if (!fDIP0003Active) {
|
||||
evoDb.Write(DB_BEST_BLOCK_UPGRADE, block.GetHash());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -151,12 +152,17 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*
|
||||
}
|
||||
}
|
||||
|
||||
auto blockHash = block.GetHash();
|
||||
|
||||
for (auto& p : qcs) {
|
||||
auto& qc = p.second;
|
||||
if (!ProcessCommitment(pindex->nHeight, block.GetHash(), qc, state)) {
|
||||
if (!ProcessCommitment(pindex->nHeight, blockHash, qc, state)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
evoDb.Write(DB_BEST_BLOCK_UPGRADE, blockHash);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -245,21 +251,22 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, const CBlockIndex* pi
|
||||
AddMinableCommitment(qc);
|
||||
}
|
||||
|
||||
evoDb.Write(DB_BEST_BLOCK_UPGRADE, pindex->pprev->GetBlockHash());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO remove this with 0.15.0
|
||||
void CQuorumBlockProcessor::UpgradeDB()
|
||||
{
|
||||
bool v = false;
|
||||
if (evoDb.GetRawDB().Read(DB_UPGRADED, v) && v) {
|
||||
LOCK(cs_main);
|
||||
uint256 bestBlock;
|
||||
if (evoDb.GetRawDB().Read(DB_BEST_BLOCK_UPGRADE, bestBlock) && bestBlock == chainActive.Tip()->GetBlockHash()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LogPrintf("CQuorumBlockProcessor::%s -- Upgrading DB...\n", __func__);
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if (chainActive.Height() >= Params().GetConsensus().DIP0003EnforcementHeight) {
|
||||
auto pindex = chainActive[Params().GetConsensus().DIP0003EnforcementHeight];
|
||||
while (pindex) {
|
||||
@ -281,12 +288,12 @@ void CQuorumBlockProcessor::UpgradeDB()
|
||||
evoDb.GetRawDB().Write(BuildInversedHeightKey((Consensus::LLMQType)qc.llmqType, pindex->nHeight), quorumIndex->nHeight);
|
||||
}
|
||||
|
||||
evoDb.GetRawDB().Write(DB_BEST_BLOCK_UPGRADE, pindex->GetBlockHash());
|
||||
|
||||
pindex = chainActive.Next(pindex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
evoDb.GetRawDB().Write(DB_UPGRADED, true);
|
||||
LogPrintf("CQuorumBlockProcessor::%s -- Upgrade done...\n", __func__);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user