Skip to content

Commit

Permalink
fix: missing governance.dat, spork.dat do not trigger more error mess…
Browse files Browse the repository at this point in the history
…age in logs
  • Loading branch information
knst committed Oct 29, 2024
1 parent 75db349 commit fe559d2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/flat-database.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CFlatDB
std::string strFilename;
std::string strMagicMessage;

bool CoreWrite(const T& objToSave)
[[nodiscard]] bool CoreWrite(const T& objToSave)
{
// LOCK(objToSave.cs);

Expand All @@ -53,8 +53,9 @@ class CFlatDB
// open output file, and associate with CAutoFile
FILE *file = fsbridge::fopen(pathDB, "wb");
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
if (fileout.IsNull())
if (fileout.IsNull()) {
return error("%s: Failed to open file %s", __func__, fs::PathToString(pathDB));
}

// Write and commit header, data
try {
Expand All @@ -71,17 +72,16 @@ class CFlatDB
return true;
}

ReadResult CoreRead(T& objToLoad)
[[nodiscard]] ReadResult CoreRead(T& objToLoad)
{
//LOCK(objToLoad.cs);

int64_t nStart = GetTimeMillis();
// open input file, and associate with CAutoFile
FILE *file = fsbridge::fopen(pathDB, "rb");
CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
if (filein.IsNull())
{
error("%s: Failed to open file %s", __func__, fs::PathToString(pathDB));
if (filein.IsNull()) {
// It is not actually error, maybe it's a first initialization of core.
return FileError;
}

Expand Down Expand Up @@ -156,14 +156,14 @@ class CFlatDB
return Ok;
}

bool Read(T& objToLoad)
[[nodiscard]] bool Read(T& objToLoad)
{
ReadResult readResult = CoreRead(objToLoad);
if (readResult == FileError)
LogPrintf("Missing file %s, will try to recreate\n", strFilename);
else if (readResult != Ok)
{
LogPrintf("Error reading %s: ", strFilename);
LogPrintf("ERROR: CFlatDB::Read Error reading %s: ", strFilename);
if(readResult == IncorrectFormat)
{
LogPrintf("%s: Magic is ok but data has invalid format, will try to recreate\n", __func__);
Expand All @@ -185,7 +185,7 @@ class CFlatDB
{
}

bool Load(T& objToLoad)
[[nodiscard]] bool Load(T& objToLoad)
{
LogPrintf("Reading info from %s...\n", strFilename);
return Read(objToLoad);
Expand All @@ -200,10 +200,10 @@ class CFlatDB
int64_t nStart = GetTimeMillis();

LogPrintf("Writing info to %s...\n", strFilename);
CoreWrite(objToSave);
const bool ret = CoreWrite(objToSave);
LogPrintf("%s dump finished %dms\n", strFilename, GetTimeMillis() - nStart);

return true;
return ret;
}
};

Expand Down

0 comments on commit fe559d2

Please sign in to comment.