From cb2cfe8db09e714d697438262aaabcd290a8ab0c Mon Sep 17 00:00:00 2001 From: fractasy Date: Thu, 29 Aug 2024 14:48:19 +0000 Subject: [PATCH] Add performance traces to witness and datastream --- src/prover/data_stream.cpp | 30 ++++++++++++++++++++++- src/prover/data_stream.hpp | 3 +++ src/prover/witness.cpp | 6 ++++- src/service/executor/executor_service.cpp | 16 ++++-------- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/prover/data_stream.cpp b/src/prover/data_stream.cpp index fa09013ab..d4ba0c377 100644 --- a/src/prover/data_stream.cpp +++ b/src/prover/data_stream.cpp @@ -2,6 +2,7 @@ #include "zklog.hpp" #include "scalar.hpp" #include "rlp.hpp" +#include "timer.hpp" //#define LOG_DATA_STREAM @@ -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 diff --git a/src/prover/data_stream.hpp b/src/prover/data_stream.hpp index 8c06b3277..bb8c26b84 100644 --- a/src/prover/data_stream.hpp +++ b/src/prover/data_stream.hpp @@ -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); diff --git a/src/prover/witness.cpp b/src/prover/witness.cpp index 18a2267cc..aa8e6d2e7 100644 --- a/src/prover/witness.cpp +++ b/src/prover/witness.cpp @@ -8,6 +8,7 @@ #include "cbor.hpp" #include "utils.hpp" #include "keccak.hpp" +#include "timer.hpp" #define WITNESS_CHECK_BITS //#define WITNESS_CHECK_SMT @@ -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(); @@ -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)); diff --git a/src/service/executor/executor_service.cpp b/src/service/executor/executor_service.cpp index 371ec08d0..de21b3043 100644 --- a/src/service/executor/executor_service.cpp +++ b/src/service/executor/executor_service.cpp @@ -1799,14 +1799,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); @@ -1815,15 +1817,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);