From abdc72a7077be6aadc77a1e813eba0fbd69acd23 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Thu, 22 Aug 2024 16:03:53 -0700 Subject: [PATCH] fix --- bin/host/src/execute.rs | 69 +++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/bin/host/src/execute.rs b/bin/host/src/execute.rs index 6ccad5d..2f39154 100644 --- a/bin/host/src/execute.rs +++ b/bin/host/src/execute.rs @@ -1,8 +1,23 @@ use csv::Writer; use rsp_client_executor::{io::ClientExecutorInput, ChainVariant}; +use serde::{Deserialize, Serialize}; use sp1_sdk::ExecutionReport; use std::{fs::OpenOptions, path::PathBuf}; +#[derive(Serialize, Deserialize)] +struct ExecutionReportData { + chain_id: u64, + block_number: u64, + gas_used: u64, + tx_count: usize, + number_cycles: u64, + number_syscalls: u64, + bn_add_cycles: u64, + bn_mul_cycles: u64, + bn_pair_cycles: u64, + kzg_point_eval_cycles: u64, +} + /// Given an execution report, print it out and write it to a CSV specified by report_path. pub fn process_execution_report( variant: ChainVariant, @@ -20,17 +35,30 @@ pub fn process_execution_report( let number_cycles = execution_report.total_instruction_count(); let number_syscalls = execution_report.total_syscall_count(); - let bn_add_cycles = execution_report.cycle_tracker.get("precompile-bn-add").unwrap_or(&0); - let bn_mul_cycles = execution_report.cycle_tracker.get("precompile-bn-mul").unwrap_or(&0); - let bn_pair_cycles = execution_report.cycle_tracker.get("precompile-bn-pair").unwrap_or(&0); - let kzg_cyles = - execution_report.cycle_tracker.get("precompile-kzg-point-evaluation").unwrap_or(&0); + let bn_add_cycles = *execution_report.cycle_tracker.get("precompile-bn-add").unwrap_or(&0); + let bn_mul_cycles = *execution_report.cycle_tracker.get("precompile-bn-mul").unwrap_or(&0); + let bn_pair_cycles = *execution_report.cycle_tracker.get("precompile-bn-pair").unwrap_or(&0); + let kzg_point_eval_cycles = + *execution_report.cycle_tracker.get("precompile-kzg-point-evaluation").unwrap_or(&0); // TODO: we can track individual syscalls in our CSV once we have sp1-core as a dependency // let keccak_count = execution_report.syscall_counts.get(SyscallCode::KECCAK_PERMUTE); // let secp256k1_decompress_count = // execution_report.syscall_counts.get(SyscallCode::SECP256K1_DECOMPRESS); + let report_data = ExecutionReportData { + chain_id, + block_number, + gas_used, + tx_count, + number_cycles, + number_syscalls, + bn_add_cycles, + bn_mul_cycles, + bn_pair_cycles, + kzg_point_eval_cycles, + }; + let report_file_exists = report_path.exists(); // Open the file for appending or create it if it doesn't exist @@ -38,35 +66,8 @@ pub fn process_execution_report( let mut writer = Writer::from_writer(file); - // Write the header if the file doesn't exist - if !report_file_exists { - writer.write_record([ - "chain_id", - "block_number", - "gas_used", - "tx_count", - "number_cycles", - "number_syscalls", - "bn_add_cycles", - "bn_mul_cycles", - "bn_pair_cycles", - "kzg_point_eval_cycles", - ])?; - } - - // Write the data - writer.write_record(&[ - chain_id.to_string(), - block_number.to_string(), - gas_used.to_string(), - tx_count.to_string(), - number_cycles.to_string(), - number_syscalls.to_string(), - bn_add_cycles.to_string(), - bn_mul_cycles.to_string(), - bn_pair_cycles.to_string(), - kzg_cyles.to_string(), - ])?; + // Serialize and write the data. Note: Writes the header if the file is empty. + writer.serialize(report_data)?; writer.flush()?;