Skip to content

Commit

Permalink
Fix logs in internal calls in FullTracer
Browse files Browse the repository at this point in the history
  • Loading branch information
fractasy committed Mar 13, 2024
1 parent 7c87684 commit 7f91302
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/config/version.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef ZKEVM_PROVER_VERSION_HPP
#define ZKEVM_PROVER_VERSION_HPP

#define ZKEVM_PROVER_VERSION "v5.0.7-RC1"
#define ZKEVM_PROVER_VERSION "v5.0.7"

#endif
65 changes: 36 additions & 29 deletions src/main_sm/fork_8/main/full_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,49 +914,32 @@ zkresult FullTracer::onFinishBlock (Context &ctx)
// Clear logs
currentBlock.logs.clear();

// Order all logs (from all CTX) in order of index
map<uint64_t, LogV2> auxLogs;
map<uint64_t, map<uint64_t, LogV2>>::iterator logIt;
map<uint64_t, LogV2>::const_iterator it;
for (logIt=logs.begin(); logIt!=logs.end(); logIt++)

// Add blockhash to all logs on every tx, and add logs to block response
for (uint64_t r = 0; r < currentBlock.responses.size(); r++)
{
for (it = logIt->second.begin(); it != logIt->second.end(); it++)
// Set block hash to all txs of block
currentBlock.responses[r].block_hash = currentBlock.block_hash;
currentBlock.responses[r].block_number = currentBlock.block_number;

for (uint64_t l = 0; l < currentBlock.responses[r].logs.size(); l++)
{
auxLogs[it->second.index] = it->second;
currentBlock.responses[r].logs[l].block_hash = currentBlock.block_hash;

// Store all logs in auxLogs, in order of index
auxLogs[currentBlock.responses[r].logs[l].index] = currentBlock.responses[r].logs[l];
}
}

// Append to response logs, overwriting log indexes to be sequential
//uint64_t logIndex = 0;
map<uint64_t, LogV2>::iterator auxLogsIt;
for (auxLogsIt = auxLogs.begin(); auxLogsIt != auxLogs.end(); auxLogsIt++)
{
// Set log index
//auxLogsIt->second.index = logIndex;
//logIndex++;

// Set block hash
auxLogsIt->second.block_hash = currentBlock.block_hash;

// Store block log
currentBlock.logs.emplace_back(auxLogsIt->second);

// Store transaction log
if (auxLogsIt->second.tx_index >= currentBlock.responses.size())
{
zklog.error("FullTracer::onFinishBlock() found log.tx_index=" + to_string(auxLogsIt->second.tx_index) + " >= currentBlock.responses.size=" + to_string(currentBlock.responses.size()));
exitProcess();
}
currentBlock.responses[auxLogsIt->second.tx_index].logs.emplace_back(auxLogsIt->second);
}

// Set block hash to all txs of block
for (uint64_t tx=0; tx<currentBlock.responses.size(); tx++)
{
currentBlock.responses[tx].block_hash = currentBlock.block_hash;
currentBlock.responses[tx].block_number = currentBlock.block_number;
};

// Append block to final trace
finalTrace.block_responses.emplace_back(currentBlock);
currentBlock.initialized = false;
Expand Down Expand Up @@ -1696,6 +1679,30 @@ zkresult FullTracer::onFinishTx(Context &ctx, const RomCommand &cmd)
numberOfOpcodesInThisTx = 0;
lastErrorOpcode = 0;

// Order all logs (from all CTX) in order of index
map<uint64_t, LogV2> auxLogs;
map<uint64_t, map<uint64_t, LogV2>>::iterator logIt;
map<uint64_t, LogV2>::const_iterator it;
for (logIt=logs.begin(); logIt!=logs.end(); logIt++)
{
for (it = logIt->second.begin(); it != logIt->second.end(); it++)
{
auxLogs[it->second.index] = it->second;
}
}

// Append to response logs, overwriting log indexes to be sequential
map<uint64_t, LogV2>::iterator auxLogsIt;
uint64_t lastTx = currentBlock.responses.size() - 1;
currentBlock.responses[lastTx].logs.clear();
for (auxLogsIt = auxLogs.begin(); auxLogsIt != auxLogs.end(); auxLogsIt++)
{
currentBlock.responses[lastTx].logs.push_back(auxLogsIt->second);
}

// Reset logs
logs.clear();

// Call finishTx()
ctx.pHashDB->finishTx(ctx.proverRequest.uuid, response.state_root, ctx.proverRequest.input.bUpdateMerkleTree ? PERSISTENCE_DATABASE : PERSISTENCE_CACHE);

Expand Down
8 changes: 8 additions & 0 deletions src/service/executor/executor_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,8 @@ ::grpc::Status ExecutorServiceImpl::ProcessBatchV2 (::grpc::ServerContext* conte
pLog->set_tx_index(block_responses[block].logs[log].tx_index); // Index of the transaction in the block
//pLog->set_batch_hash(string2ba(block_responses[block].logs[log].batch_hash)); // Hash of the batch in which the transaction was included
pLog->set_index(block_responses[block].logs[log].index); // Index of the log in the block
pLog->set_block_hash(string2ba(block_responses[block].logs[log].block_hash));
pLog->set_block_number(block_responses[block].logs[log].block_number);
}

vector<ResponseV2> &responses = block_responses[block].responses;
Expand Down Expand Up @@ -1458,6 +1460,8 @@ ::grpc::Status ExecutorServiceImpl::ProcessBatchV2 (::grpc::ServerContext* conte
pLog->set_tx_index(responses[tx].logs[log].tx_index); // Index of the transaction in the block
//pLog->set_batch_hash(string2ba(responses[tx].logs[log].batch_hash)); // Hash of the batch in which the transaction was included
pLog->set_index(responses[tx].logs[log].index); // Index of the log in the block
pLog->set_block_hash(string2ba(responses[tx].logs[log].block_hash));
pLog->set_block_number(responses[tx].logs[log].block_number);
}
if (proverRequest.input.traceConfig.bEnabled && (proverRequest.input.traceConfig.txHashToGenerateFullTrace == responses[tx].tx_hash))
{
Expand Down Expand Up @@ -2049,6 +2053,8 @@ ::grpc::Status ExecutorServiceImpl::ProcessStatelessBatchV2 (::grpc::ServerConte
pLog->set_tx_index(block_responses[block].logs[log].tx_index); // Index of the transaction in the block
//pLog->set_batch_hash(string2ba(block_responses[block].logs[log].batch_hash)); // Hash of the batch in which the transaction was included
pLog->set_index(block_responses[block].logs[log].index); // Index of the log in the block
pLog->set_block_hash(string2ba(block_responses[block].logs[log].block_hash));
pLog->set_block_number(block_responses[block].logs[log].block_number);
}

vector<ResponseV2> &responses = block_responses[block].responses;
Expand Down Expand Up @@ -2098,6 +2104,8 @@ ::grpc::Status ExecutorServiceImpl::ProcessStatelessBatchV2 (::grpc::ServerConte
pLog->set_tx_index(responses[tx].logs[log].tx_index); // Index of the transaction in the block
//pLog->set_batch_hash(string2ba(responses[tx].logs[log].batch_hash)); // Hash of the batch in which the transaction was included
pLog->set_index(responses[tx].logs[log].index); // Index of the log in the block
pLog->set_block_hash(string2ba(responses[tx].logs[log].block_hash));
pLog->set_block_number(responses[tx].logs[log].block_number);
}
if (proverRequest.input.traceConfig.bEnabled && (proverRequest.input.traceConfig.txHashToGenerateFullTrace == responses[tx].tx_hash))
{
Expand Down

0 comments on commit 7f91302

Please sign in to comment.