Skip to content

Commit

Permalink
Remove saving dirty flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sieniven committed Jan 17, 2024
1 parent 2d63446 commit 5bcd8a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 49 deletions.
12 changes: 0 additions & 12 deletions src/dfi/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,18 +815,6 @@ void CCustomCSView::SetDbVersion(int version) {
Write(DbVersion::prefix(), version);
}

bool CCustomCSView::GetEvmDirtyFlag() const {
bool dirtyFlag;
if (Read(EvmDirtyFlag::prefix(), dirtyFlag)) {
return dirtyFlag;
}
return false;
}

void CCustomCSView::SetEvmDirtyFlag(bool flag) {
Write(EvmDirtyFlag::prefix(), flag);
}

CTeamView::CTeam CCustomCSView::CalcNextTeam(int height, const uint256 &stakeModifier) {
if (stakeModifier == uint256()) {
return Params().GetGenesisTeam();
Expand Down
8 changes: 1 addition & 7 deletions src/dfi/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,8 @@ class CCustomCSView : public CMasternodesView,
const DCT_ID &id) const override;

void SetDbVersion(int version);
int GetDbVersion() const;

void SetEvmDirtyFlag(bool flag);
bool GetEvmDirtyFlag() const;
int GetDbVersion() const;

uint256 MerkleRoot();

Expand All @@ -626,10 +624,6 @@ class CCustomCSView : public CMasternodesView,
struct DbVersion {
static constexpr uint8_t prefix() { return 'D'; }
};

struct EvmDirtyFlag {
static constexpr uint8_t prefix() { return 'p'; }
};
};

std::map<CKeyID, CKey> AmISignerNow(int height, const CAnchorData::CTeam &team);
Expand Down
41 changes: 11 additions & 30 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
// Dump addresses to banlist.dat every 15 minutes (900s)
static constexpr int DUMP_BANS_INTERVAL = 60 * 15;

static bool fEvmDatabaseDirty = false;

std::unique_ptr<CConnman> g_connman;
std::unique_ptr<PeerLogicValidation> peerLogic;
std::unique_ptr<BanMan> g_banman;
Expand Down Expand Up @@ -294,12 +292,7 @@ void Shutdown(InitInterfaces& interfaces)
// next startup faster by avoiding rescan.

ShutdownDfTxGlobalTaskPool();
auto res = XResultStatusLogged(ain_rs_stop_core_services(result));
if (!res) {
fEvmDatabaseDirty = true;
}
pcustomcsview->SetEvmDirtyFlag(fEvmDatabaseDirty);

XResultStatusLogged(ain_rs_stop_core_services(result));
LogPrint(BCLog::SPV, "Releasing\n");
spv::pspv.reset();
{
Expand Down Expand Up @@ -1838,7 +1831,7 @@ bool AppInitMain(InitInterfaces& interfaces)
fReindex = gArgs.GetBoolArg("-reindex", false);
bool fReindexChainState = gArgs.GetBoolArg("-reindex-chainstate", false);
while (!fLoaded && !ShutdownRequested()) {
bool fReset = (fReindex || fEvmDatabaseDirty);
bool fReset = fReindex;
std::string strLoadError;

uiInterface.InitMessage(_("Loading block index...").translated);
Expand Down Expand Up @@ -1928,13 +1921,6 @@ bool AppInitMain(InitInterfaces& interfaces)
// Ensure we are on latest DB version
pcustomcsview->SetDbVersion(CCustomCSView::DbVersion);

// Set evm database dirty flag
fEvmDatabaseDirty = pcustomcsview->GetEvmDirtyFlag();
if (!fReset && fEvmDatabaseDirty) {
LogPrintf("Evm database dirty, re-indexing chain state.\n");
break;
}

// make account history db
paccountHistoryDB.reset();
if (gArgs.GetBoolArg("-acindex", DEFAULT_ACINDEX)) {
Expand Down Expand Up @@ -2063,23 +2049,18 @@ bool AppInitMain(InitInterfaces& interfaces)
} while(false);

if (!fLoaded && !ShutdownRequested()) {
// first suggest a reindex
if (!fReset) {
if (fEvmDatabaseDirty) {
// Evm database dirty. Abort shutdown and run re-index pipeline.
bool fRet = uiInterface.ThreadSafeQuestion(
strLoadError + ".\n\n" + _("Do you want to rebuild the block database now?").translated,
strLoadError + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
if (fRet) {
fReindex = true;
AbortShutdown();
} else {
// first suggest a reindex
bool fRet = uiInterface.ThreadSafeQuestion(
strLoadError + ".\n\n" + _("Do you want to rebuild the block database now?").translated,
strLoadError + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
if (fRet) {
fReindex = true;
AbortShutdown();
} else {
LogPrintf("Aborted block database rebuild. Exiting.\n");
return false;
}
LogPrintf("Aborted block database rebuild. Exiting.\n");
return false;
}
} else {
return InitError(strLoadError);
Expand Down

0 comments on commit 5bcd8a0

Please sign in to comment.