Skip to content

Commit

Permalink
Enable execution with stateManager=false, mandatory for hashDBSinglet…
Browse files Browse the repository at this point in the history
…on=false
  • Loading branch information
fractasy committed Aug 28, 2024
1 parent a5c0b30 commit 4095868
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,5 +756,11 @@ bool Config::check (void)
bError = true;
}

if (!hashDBSingleton && stateManager)
{
zklog.error("hashDBSingleton=false but stateManager=true");
bError = true;
}

return bError;
}
25 changes: 20 additions & 5 deletions src/service/hashdb/hashdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ zkresult HashDB::setProgram (const string &batchUUID, uint64_t block, uint64_t t
string keyString = fea2string(fr, key);

// Call writeProgram()
zkresult zkr = stateManager.writeProgram(batchUUID, block, tx, keyString, data, persistence);
zkresult zkr;
if (config.stateManager)
{
zkr = stateManager.writeProgram(batchUUID, block, tx, keyString, data, persistence);
}
else
{
zkr = db.setProgram(keyString, data, persistence == PERSISTENCE_DATABASE);
}

#ifdef LOG_TIME_STATISTICS_HASHDB
tms.add("setProgram", TimeDiff(t));
Expand All @@ -116,14 +124,21 @@ zkresult HashDB::getProgram (const string &batchUUID, const Goldilocks::Element
data.clear();

// Call readProgram
zkresult zkr = stateManager.readProgram(batchUUID, keyString, data, dbReadLog);
if (zkr != ZKR_SUCCESS)
zkresult zkr;
if (config.stateManager)
{
zkr = db.getProgram(keyString, data, dbReadLog);
zkr = stateManager.readProgram(batchUUID, keyString, data, dbReadLog);
if (zkr != ZKR_SUCCESS)
{
zklog.error("HashDB::getProgram() failed result=" + zkresult2string(zkr) + " key=" + keyString);
zkr = db.getProgram(keyString, data, dbReadLog);
}
} else
{
zkr = db.getProgram(keyString, data, dbReadLog);
}
if (zkr != ZKR_SUCCESS)
{
zklog.error("HashDB::getProgram() failed result=" + zkresult2string(zkr) + " key=" + keyString);
}

#ifdef LOG_TIME_STATISTICS_HASHDB
Expand Down

0 comments on commit 4095868

Please sign in to comment.