Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,8 @@ bool CDeterministicMNManager::UpgradeDBIfNeeded()
LOCK(cs_main);

if (chainActive.Tip() == nullptr) {
return true;
// should have no records
return evoDb.IsEmpty();
}

if (evoDb.GetRawDB().Exists(EVODB_BEST_BLOCK)) {
Expand Down
2 changes: 2 additions & 0 deletions src/evo/evodb.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class CEvoDB

bool CommitRootTransaction();

bool IsEmpty() { return db.IsEmpty(); }

bool VerifyBestBlock(const uint256& hash);
void WriteBestBlock(const uint256& hash);

Expand Down
9 changes: 8 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

#include <evo/deterministicmns.h>
#include <llmq/quorums_init.h>
#include <llmq/quorums_blockprocessor.h>

#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -1981,7 +1982,13 @@ bool AppInitMain()
assert(chainActive.Tip() != NULL);
}

if (!deterministicMNManager->UpgradeDBIfNeeded()) {
if (is_coinsview_empty && !evoDb->IsEmpty()) {
// EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
strLoadError = _("Error initializing block database");
break;
}

if (!deterministicMNManager->UpgradeDBIfNeeded() || !llmq::quorumBlockProcessor->UpgradeDB()) {
strLoadError = _("Error upgrading evo database");
break;
}
Expand Down
13 changes: 10 additions & 3 deletions src/llmq/quorums_blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,18 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, const CBlockIndex* pi
}

// TODO remove this with 0.15.0
void CQuorumBlockProcessor::UpgradeDB()
bool CQuorumBlockProcessor::UpgradeDB()
{
LOCK(cs_main);

if (chainActive.Tip() == nullptr) {
// should have no records
return evoDb.IsEmpty();
}

uint256 bestBlock;
if (evoDb.GetRawDB().Read(DB_BEST_BLOCK_UPGRADE, bestBlock) && bestBlock == chainActive.Tip()->GetBlockHash()) {
return;
return true;
}

LogPrintf("CQuorumBlockProcessor::%s -- Upgrading DB...\n", __func__);
Expand All @@ -283,7 +289,7 @@ void CQuorumBlockProcessor::UpgradeDB()
while (pindex) {
if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
// Too late, we already pruned blocks we needed to reprocess commitments
throw std::runtime_error(std::string(__func__) + ": Quorum Commitments DB upgrade failed, you need to re-download the blockchain");
return false;
}
CBlock block;
bool r = ReadBlockFromDisk(block, pindex, Params().GetConsensus());
Expand All @@ -310,6 +316,7 @@ void CQuorumBlockProcessor::UpgradeDB()
}

LogPrintf("CQuorumBlockProcessor::%s -- Upgrade done...\n", __func__);
return true;
}

bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindex, std::map<Consensus::LLMQType, CFinalCommitment>& ret, CValidationState& state)
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums_blockprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CQuorumBlockProcessor
public:
explicit CQuorumBlockProcessor(CEvoDB& _evoDb) : evoDb(_evoDb) {}

void UpgradeDB();
bool UpgradeDB();

void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);

Expand Down
2 changes: 0 additions & 2 deletions src/llmq/quorums_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ void DestroyLLMQSystem()

void StartLLMQSystem()
{
quorumBlockProcessor->UpgradeDB();

if (blsWorker) {
blsWorker->Start();
}
Expand Down