Skip to content

Commit

Permalink
Add performance traces to witness and datastream
Browse files Browse the repository at this point in the history
  • Loading branch information
fractasy committed Aug 29, 2024
1 parent f3f2a63 commit 548a51e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
30 changes: 29 additions & 1 deletion src/prover/data_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "zklog.hpp"
#include "scalar.hpp"
#include "rlp.hpp"
#include "timer.hpp"

//#define LOG_DATA_STREAM

Expand Down Expand Up @@ -947,11 +948,38 @@ zkresult dataStreamBatch2batchL2Data (const DataStreamBatch &batch, string &batc
}
}

zklog.info("dataStreamBatch2batchL2Data() generated data of size=" + to_string(batchL2Data.size()));
//zklog.info("dataStreamBatch2batchL2Data() generated data of size=" + to_string(batchL2Data.size()));

return ZKR_SUCCESS;
}

zkresult dataStream2batchL2Data (const string &dataStream, DataStreamBatch &batch, string &batchL2Data)
{
// Save start time
struct timeval t;
gettimeofday(&t, NULL);

// Call dataStream2batch
zkresult zkr = dataStream2batch(dataStream, batch);
if (zkr != ZKR_SUCCESS)
{
zklog.error("dataStream2batchL2Data() failed calling dataStream2batch() zkr=" + zkresult2string(zkr));
return zkr;
}

// Call dataStreamBatch2batchL2Data
zkr = dataStreamBatch2batchL2Data(batch, batchL2Data);
if (zkr != ZKR_SUCCESS)
{
zklog.error("dataStream2batchL2Data() failed calling dataStreamBatch2batchL2Data() zkr=" + zkresult2string(zkr));
return zkr;
}

zklog.info("dataStream2batchL2Data() done dataStream.size=" + to_string(dataStream.size()) + " batch=" + batch.toString() + " batchL2Data.size=" + to_string(batchL2Data.size()) + " in " + to_string(TimeDiff(t)) + "us");

return zkr;
}

//#define LOG_TX_FIELDS

// Decodes tx from Ethereum RLP format, and encodes it into ROM RLP format
Expand Down
3 changes: 3 additions & 0 deletions src/prover/data_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ zkresult dataStream2batch (const string &dataStream, DataStreamBatch &batch);
// Encodes a DataStreamBatch into a batch L2 data byte array
zkresult dataStreamBatch2batchL2Data (const DataStreamBatch &batch, string &batchL2Data);

// Decodes a data stream and encodes a batch L2 data
zkresult dataStream2batchL2Data (const string &dataStream, DataStreamBatch &batch, string &batchL2Data);

// Decodes tx from Ethereum RLP format, and encodes it into ROM RLP format
zkresult transcodeTx (const string &tx, uint32_t batchChainId, string &transcodedTx);

Expand Down
6 changes: 5 additions & 1 deletion src/prover/witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "cbor.hpp"
#include "utils.hpp"
#include "keccak.hpp"
#include "timer.hpp"

#define WITNESS_CHECK_BITS
//#define WITNESS_CHECK_SMT
Expand Down Expand Up @@ -505,6 +506,9 @@ zkresult calculateWitnessHash (WitnessContext &ctx, Goldilocks::Element (&hash)[

zkresult witness2db (const string &witness, DatabaseMap::MTMap &db, DatabaseMap::ProgramMap &programs, mpz_class &stateRoot)
{
struct timeval t;
gettimeofday(&t, NULL);

db.clear();
programs.clear();

Expand Down Expand Up @@ -541,7 +545,7 @@ zkresult witness2db (const string &witness, DatabaseMap::MTMap &db, DatabaseMap:
// Convert state root
fea2scalar(fr, stateRoot, hash);

zklog.info("witness2db() calculated stateRoot=" + stateRoot.get_str(16) + " from size=" + to_string(witness.size()));
zklog.info("witness2db() calculated stateRoot=" + stateRoot.get_str(16) + " from size=" + to_string(witness.size()) + "B generating db.size=" + to_string(db.size()) + " and programs.size=" + to_string(programs.size()) + " in " + to_string(TimeDiff(t)) + "us");

#ifdef WITNESS_CHECK_SMT
zklog.info("witness2db() calculated SMT root=" + fea2string(fr, ctx.root));
Expand Down
25 changes: 14 additions & 11 deletions src/service/executor/executor_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,15 @@ ::grpc::Status ExecutorServiceImpl::ProcessStatelessBatchV2 (::grpc::ServerConte
return Status::CANCELLED;
}

// If the config.hashDBSingleton is set to true, reject any request
// We can only process stateless requests if they don't share the DB cache with other requests
if (config.hashDBSingleton)
{
zklog.error("ExecutorServiceImpl::ProcessStatelessBatchV2() called with config.hashDBSingleton=true");
response->set_error(executor::v1::EXECUTOR_ERROR_DB_ERROR);
return Status::OK;
}

//TimerStart(EXECUTOR_PROCESS_BATCH);
struct timeval EXECUTOR_PROCESS_BATCH_start;
gettimeofday(&EXECUTOR_PROCESS_BATCH_start,NULL);
Expand Down Expand Up @@ -1792,14 +1801,16 @@ ::grpc::Status ExecutorServiceImpl::ProcessStatelessBatchV2 (::grpc::ServerConte

// Parse data stream and get a binary structure
DataStreamBatch batch;
zkr = dataStream2batch(proverRequest.input.publicInputsExtended.publicInputs.dataStream, batch);
zkr = dataStream2batchL2Data(proverRequest.input.publicInputsExtended.publicInputs.dataStream, batch, proverRequest.input.publicInputsExtended.publicInputs.batchL2Data);
if (zkr != ZKR_SUCCESS)
{
zklog.error("ExecutorServiceImpl::ProcessStatelessBatchV2() failed calling dataStream2batch() result=" + zkresult2string(zkr), &proverRequest.tags);
zklog.error("ExecutorServiceImpl::ProcessStatelessBatchV2() failed calling dataStream2batchL2Data() result=" + zkresult2string(zkr), &proverRequest.tags);
response->set_error(zkresult2error(zkr));
//TimerStopAndLog(EXECUTOR_PROCESS_BATCH);
return Status::OK;
}

// Check blocks
if (batch.blocks.empty())
{
zklog.error("ExecutorServiceImpl::ProcessStatelessBatchV2() called dataStream2batch() but got zero blocks", &proverRequest.tags);
Expand All @@ -1808,15 +1819,7 @@ ::grpc::Status ExecutorServiceImpl::ProcessStatelessBatchV2 (::grpc::ServerConte
return Status::OK;
}

// Get batchL2Data
zkr = dataStreamBatch2batchL2Data(batch, proverRequest.input.publicInputsExtended.publicInputs.batchL2Data);
if (zkr != ZKR_SUCCESS)
{
zklog.error("ExecutorServiceImpl::ProcessStatelessBatchV2() failed calling dataStreamBatch2batchL2Data() result=" + zkresult2string(zkr), &proverRequest.tags);
response->set_error(zkresult2error(zkr));
//TimerStopAndLog(EXECUTOR_PROCESS_BATCH);
return Status::OK;
}
// Check batchL2Data
if (proverRequest.input.publicInputsExtended.publicInputs.batchL2Data.size() > MAX_BATCH_L2_DATA_SIZE)
{
zklog.error("ExecutorServiceImpl::ProcessBatchV2() found batchL2Data.size()=" + to_string(proverRequest.input.publicInputsExtended.publicInputs.batchL2Data.size()) + " > MAX_BATCH_L2_DATA_SIZE=" + to_string(MAX_BATCH_L2_DATA_SIZE), &proverRequest.tags);
Expand Down

0 comments on commit 548a51e

Please sign in to comment.