Skip to content

Commit

Permalink
Fix StateManager automatic block creation for fork<7. Fix FullTracer:…
Browse files Browse the repository at this point in the history
…:onError() to return after a responseError detection.
  • Loading branch information
fractasy committed Jan 3, 2024
1 parent 37b1cc3 commit e676e88
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/hashdb/state_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ zkresult StateManager::setStateRoot (const string &batchUUID, uint64_t block, ui
// Set the current state root
batchState.currentStateRoot = stateRoot;

// Check block range
// Check block range, and create any previous block state if missing
// This is required for forks < 7 where block start/finish events are not generated by the ROM,
// and onFinishTx() is not generated for tx=0 because it is a virtual TX to contain SMT activity previous to the first real TX
if (block >= batchState.blockState.size())
{
zklog.error("StateManager::setStateRoot() called with block=" + to_string(block) + " but blockState.size=" + to_string(batchState.blockState.size()));
Unlock();
return ZKR_STATE_MANAGER;
BlockState emptyBlockState;
while (block >= batchState.blockState.size())
{
batchState.blockState.emplace_back(emptyBlockState);
}
}

// Get a reference to the block state
Expand All @@ -88,6 +92,14 @@ zkresult StateManager::setStateRoot (const string &batchUUID, uint64_t block, ui
blockState.oldStateRoot = stateRoot;
}

// If this is a new state root, update the current state root of the block
if ( ((persistence == PERSISTENCE_DATABASE) || (persistence == PERSISTENCE_CACHE)) &&
!bIsOldStateRoot )
{
blockState.currentStateRoot = stateRoot;
}


// Create tx states, if needed
if (tx >= blockState.txState.size())
{
Expand Down
7 changes: 7 additions & 0 deletions src/main_sm/fork_7/main/full_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,13 @@ zkresult FullTracer::onError(Context &ctx, const RomCommand &cmd)
zklog.error("FullTracer::onError() got error=" + lastError + " with txIndex=" + to_string(txIndex) + " but currentBlock.responses.size()=" + to_string(currentBlock.responses.size()));
exitProcess();
}
#ifdef LOG_FULL_TRACER_ON_ERROR
zklog.info("FullTracer::onError() error=" + lastError + " zkPC=" + to_string(*ctx.pZKPC) + " rom=" + ctx.rom.line[*ctx.pZKPC].toString(ctx.fr));
#endif
#ifdef LOG_TIME_STATISTICS
tms.add("onError", TimeDiff(t));
#endif
return ZKR_SUCCESS;
}

if (full_trace.size() > 0)
Expand Down

0 comments on commit e676e88

Please sign in to comment.