diff --git a/src/builder.rs b/src/builder.rs index dec57f1..1df933c 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,3 +1,4 @@ +use crate::log::{setup_solana_logging, turn_off_solana_logging}; use crate::trident_svm::TridentSVM; use crate::types::trident_account::TridentAccountSharedData; use crate::types::trident_entrypoint::TridentEntrypoint; @@ -7,6 +8,7 @@ use crate::types::trident_program::TridentProgram; pub struct TridentSVMConfig { syscalls_v1: bool, syscalls_v2: bool, + cli_logs: bool, // TODO, add better debbug levels program_entrypoints: Vec, program_binaries: Vec, permanent_accounts: Vec, @@ -24,32 +26,37 @@ impl TridentSVMBuilder { } } - pub fn with_syscalls_v1(mut self) -> Self { + pub fn with_syscalls_v1(&mut self) -> &Self { self.config.syscalls_v1 = true; self } - pub fn with_syscalls_v2(mut self) -> Self { + pub fn with_syscalls_v2(&mut self) -> &Self { self.config.syscalls_v2 = true; self } - pub fn with_program_entries(mut self, entries: Vec) -> Self { + pub fn with_program_entries(&mut self, entries: Vec) -> &Self { self.config.program_entrypoints = entries; self } - pub fn with_sbf_programs(mut self, programs: Vec) -> Self { + pub fn with_sbf_programs(&mut self, programs: Vec) -> &Self { self.config.program_binaries = programs; self } - pub fn with_permanent_accounts(mut self, accounts: Vec) -> Self { + pub fn with_permanent_accounts(&mut self, accounts: Vec) -> &Self { self.config.permanent_accounts = accounts; self } - pub fn build(self) -> TridentSVM { + pub fn with_cli_logs(&mut self) -> &Self { + self.config.cli_logs = true; + self + } + + pub fn build(&self) -> TridentSVM { let mut svm = TridentSVM::default(); if self.config.syscalls_v1 { @@ -59,15 +66,21 @@ impl TridentSVMBuilder { svm.initialize_syscalls_v2(); } - for entry in self.config.program_entrypoints { - svm.deploy_entrypoint_program(&entry); + if self.config.cli_logs { + setup_solana_logging(); + } else { + turn_off_solana_logging(); + } + + for entry in &self.config.program_entrypoints { + svm.deploy_entrypoint_program(entry); } - for program in self.config.program_binaries { - svm.deploy_binary_program(&program); + for program in &self.config.program_binaries { + svm.deploy_binary_program(program); } - for account in self.config.permanent_accounts { + for account in &self.config.permanent_accounts { svm.accounts .set_permanent_account(&account.address, &account.account); } diff --git a/src/methods/trident_svm_transactions.rs b/src/methods/trident_svm_transactions.rs index 28b3798..b6b6f28 100644 --- a/src/methods/trident_svm_transactions.rs +++ b/src/methods/trident_svm_transactions.rs @@ -14,8 +14,6 @@ use solana_svm::transaction_processor::TransactionProcessingEnvironment; use solana_compute_budget::compute_budget::ComputeBudget; -use crate::log::setup_solana_logging; -use crate::log::turn_off_solana_logging; use crate::trident_svm::TridentSVM; impl TridentSVM { @@ -38,12 +36,8 @@ impl TridentSVM { let tx_processing_config = TransactionProcessingConfig { compute_budget: Some(ComputeBudget::default()), - log_messages_bytes_limit: Some(10 * 1000), - recording_config: ExecutionRecordingConfig { - enable_cpi_recording: true, - enable_log_recording: true, - enable_return_data_recording: true, - }, + log_messages_bytes_limit: Some(20 * 1000), + recording_config: ExecutionRecordingConfig::new_single_setting(true), ..Default::default() }; @@ -87,25 +81,13 @@ impl TridentSVM { rent_collector: None, }; - let mut tx_processing_config = TransactionProcessingConfig { + let tx_processing_config = TransactionProcessingConfig { compute_budget: Some(ComputeBudget::default()), - log_messages_bytes_limit: Some(10 * 1000), - recording_config: ExecutionRecordingConfig { - enable_cpi_recording: true, - enable_log_recording: true, - enable_return_data_recording: true, - }, + log_messages_bytes_limit: Some(20 * 1000), + recording_config: ExecutionRecordingConfig::new_single_setting(true), ..Default::default() }; - if std::env::var("TRIDENT_LOG").is_ok() { - setup_solana_logging(); - tx_processing_config.recording_config.enable_log_recording = true; - } else { - turn_off_solana_logging(); - tx_processing_config.recording_config.enable_log_recording = false; - } - // reset sysvar cache self.processor.reset_sysvar_cache();