Skip to content

Commit 8efa0ed

Browse files
committed
✨ Update logging , so we support difference between stored logs and logs printed to the CLI
1 parent 4391d66 commit 8efa0ed

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

src/builder.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::log::{setup_solana_logging, turn_off_solana_logging};
12
use crate::trident_svm::TridentSVM;
23
use crate::types::trident_account::TridentAccountSharedData;
34
use crate::types::trident_entrypoint::TridentEntrypoint;
@@ -7,6 +8,7 @@ use crate::types::trident_program::TridentProgram;
78
pub struct TridentSVMConfig {
89
syscalls_v1: bool,
910
syscalls_v2: bool,
11+
cli_logs: bool, // TODO, add better debbug levels
1012
program_entrypoints: Vec<TridentEntrypoint>,
1113
program_binaries: Vec<TridentProgram>,
1214
permanent_accounts: Vec<TridentAccountSharedData>,
@@ -24,32 +26,37 @@ impl TridentSVMBuilder {
2426
}
2527
}
2628

27-
pub fn with_syscalls_v1(mut self) -> Self {
29+
pub fn with_syscalls_v1(&mut self) -> &Self {
2830
self.config.syscalls_v1 = true;
2931
self
3032
}
3133

32-
pub fn with_syscalls_v2(mut self) -> Self {
34+
pub fn with_syscalls_v2(&mut self) -> &Self {
3335
self.config.syscalls_v2 = true;
3436
self
3537
}
3638

37-
pub fn with_program_entries(mut self, entries: Vec<TridentEntrypoint>) -> Self {
39+
pub fn with_program_entries(&mut self, entries: Vec<TridentEntrypoint>) -> &Self {
3840
self.config.program_entrypoints = entries;
3941
self
4042
}
4143

42-
pub fn with_sbf_programs(mut self, programs: Vec<TridentProgram>) -> Self {
44+
pub fn with_sbf_programs(&mut self, programs: Vec<TridentProgram>) -> &Self {
4345
self.config.program_binaries = programs;
4446
self
4547
}
4648

47-
pub fn with_permanent_accounts(mut self, accounts: Vec<TridentAccountSharedData>) -> Self {
49+
pub fn with_permanent_accounts(&mut self, accounts: Vec<TridentAccountSharedData>) -> &Self {
4850
self.config.permanent_accounts = accounts;
4951
self
5052
}
5153

52-
pub fn build(self) -> TridentSVM {
54+
pub fn with_cli_logs(&mut self) -> &Self {
55+
self.config.cli_logs = true;
56+
self
57+
}
58+
59+
pub fn build(&self) -> TridentSVM {
5360
let mut svm = TridentSVM::default();
5461

5562
if self.config.syscalls_v1 {
@@ -59,15 +66,21 @@ impl TridentSVMBuilder {
5966
svm.initialize_syscalls_v2();
6067
}
6168

62-
for entry in self.config.program_entrypoints {
63-
svm.deploy_entrypoint_program(&entry);
69+
if self.config.cli_logs {
70+
setup_solana_logging();
71+
} else {
72+
turn_off_solana_logging();
73+
}
74+
75+
for entry in &self.config.program_entrypoints {
76+
svm.deploy_entrypoint_program(entry);
6477
}
6578

66-
for program in self.config.program_binaries {
67-
svm.deploy_binary_program(&program);
79+
for program in &self.config.program_binaries {
80+
svm.deploy_binary_program(program);
6881
}
6982

70-
for account in self.config.permanent_accounts {
83+
for account in &self.config.permanent_accounts {
7184
svm.accounts
7285
.set_permanent_account(&account.address, &account.account);
7386
}

src/methods/trident_svm_transactions.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ use solana_svm::transaction_processor::TransactionProcessingEnvironment;
1414

1515
use solana_compute_budget::compute_budget::ComputeBudget;
1616

17-
use crate::log::setup_solana_logging;
18-
use crate::log::turn_off_solana_logging;
1917
use crate::trident_svm::TridentSVM;
2018

2119
impl TridentSVM {
@@ -38,12 +36,8 @@ impl TridentSVM {
3836

3937
let tx_processing_config = TransactionProcessingConfig {
4038
compute_budget: Some(ComputeBudget::default()),
41-
log_messages_bytes_limit: Some(10 * 1000),
42-
recording_config: ExecutionRecordingConfig {
43-
enable_cpi_recording: true,
44-
enable_log_recording: true,
45-
enable_return_data_recording: true,
46-
},
39+
log_messages_bytes_limit: Some(20 * 1000),
40+
recording_config: ExecutionRecordingConfig::new_single_setting(true),
4741
..Default::default()
4842
};
4943

@@ -87,25 +81,13 @@ impl TridentSVM {
8781
rent_collector: None,
8882
};
8983

90-
let mut tx_processing_config = TransactionProcessingConfig {
84+
let tx_processing_config = TransactionProcessingConfig {
9185
compute_budget: Some(ComputeBudget::default()),
92-
log_messages_bytes_limit: Some(10 * 1000),
93-
recording_config: ExecutionRecordingConfig {
94-
enable_cpi_recording: true,
95-
enable_log_recording: true,
96-
enable_return_data_recording: true,
97-
},
86+
log_messages_bytes_limit: Some(20 * 1000),
87+
recording_config: ExecutionRecordingConfig::new_single_setting(true),
9888
..Default::default()
9989
};
10090

101-
if std::env::var("TRIDENT_LOG").is_ok() {
102-
setup_solana_logging();
103-
tx_processing_config.recording_config.enable_log_recording = true;
104-
} else {
105-
turn_off_solana_logging();
106-
tx_processing_config.recording_config.enable_log_recording = false;
107-
}
108-
10991
// reset sysvar cache
11092
self.processor.reset_sysvar_cache();
11193

0 commit comments

Comments
 (0)