mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +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 = "q_mc";
|
||||||
static const std::string DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT = "q_mcih";
|
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)
|
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;
|
bool fDIP0003Active = VersionBitsState(pindex->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE;
|
||||||
if (!fDIP0003Active) {
|
if (!fDIP0003Active) {
|
||||||
|
evoDb.Write(DB_BEST_BLOCK_UPGRADE, block.GetHash());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,12 +152,17 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto blockHash = block.GetHash();
|
||||||
|
|
||||||
for (auto& p : qcs) {
|
for (auto& p : qcs) {
|
||||||
auto& qc = p.second;
|
auto& qc = p.second;
|
||||||
if (!ProcessCommitment(pindex->nHeight, block.GetHash(), qc, state)) {
|
if (!ProcessCommitment(pindex->nHeight, blockHash, qc, state)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evoDb.Write(DB_BEST_BLOCK_UPGRADE, blockHash);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,48 +251,49 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, const CBlockIndex* pi
|
|||||||
AddMinableCommitment(qc);
|
AddMinableCommitment(qc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evoDb.Write(DB_BEST_BLOCK_UPGRADE, pindex->pprev->GetBlockHash());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove this with 0.15.0
|
// TODO remove this with 0.15.0
|
||||||
void CQuorumBlockProcessor::UpgradeDB()
|
void CQuorumBlockProcessor::UpgradeDB()
|
||||||
{
|
{
|
||||||
bool v = false;
|
LOCK(cs_main);
|
||||||
if (evoDb.GetRawDB().Read(DB_UPGRADED, v) && v) {
|
uint256 bestBlock;
|
||||||
|
if (evoDb.GetRawDB().Read(DB_BEST_BLOCK_UPGRADE, bestBlock) && bestBlock == chainActive.Tip()->GetBlockHash()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogPrintf("CQuorumBlockProcessor::%s -- Upgrading DB...\n", __func__);
|
LogPrintf("CQuorumBlockProcessor::%s -- Upgrading DB...\n", __func__);
|
||||||
|
|
||||||
{
|
if (chainActive.Height() >= Params().GetConsensus().DIP0003EnforcementHeight) {
|
||||||
LOCK(cs_main);
|
auto pindex = chainActive[Params().GetConsensus().DIP0003EnforcementHeight];
|
||||||
if (chainActive.Height() >= Params().GetConsensus().DIP0003EnforcementHeight) {
|
while (pindex) {
|
||||||
auto pindex = chainActive[Params().GetConsensus().DIP0003EnforcementHeight];
|
CBlock block;
|
||||||
while (pindex) {
|
bool r = ReadBlockFromDisk(block, pindex, Params().GetConsensus());
|
||||||
CBlock block;
|
assert(r);
|
||||||
bool r = ReadBlockFromDisk(block, pindex, Params().GetConsensus());
|
|
||||||
assert(r);
|
|
||||||
|
|
||||||
std::map<Consensus::LLMQType, CFinalCommitment> qcs;
|
std::map<Consensus::LLMQType, CFinalCommitment> qcs;
|
||||||
CValidationState dummyState;
|
CValidationState dummyState;
|
||||||
GetCommitmentsFromBlock(block, pindex->pprev, qcs, dummyState);
|
GetCommitmentsFromBlock(block, pindex->pprev, qcs, dummyState);
|
||||||
|
|
||||||
for (const auto& p : qcs) {
|
for (const auto& p : qcs) {
|
||||||
const auto& qc = p.second;
|
const auto& qc = p.second;
|
||||||
if (qc.IsNull()) {
|
if (qc.IsNull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
auto quorumIndex = mapBlockIndex.at(qc.quorumHash);
|
|
||||||
evoDb.GetRawDB().Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair((uint8_t)qc.llmqType, qc.quorumHash)), std::make_pair(qc, pindex->GetBlockHash()));
|
|
||||||
evoDb.GetRawDB().Write(BuildInversedHeightKey((Consensus::LLMQType)qc.llmqType, pindex->nHeight), quorumIndex->nHeight);
|
|
||||||
}
|
}
|
||||||
|
auto quorumIndex = mapBlockIndex.at(qc.quorumHash);
|
||||||
pindex = chainActive.Next(pindex);
|
evoDb.GetRawDB().Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair((uint8_t)qc.llmqType, qc.quorumHash)), std::make_pair(qc, pindex->GetBlockHash()));
|
||||||
|
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__);
|
LogPrintf("CQuorumBlockProcessor::%s -- Upgrade done...\n", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user