Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions src/builder.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<TridentEntrypoint>,
program_binaries: Vec<TridentProgram>,
permanent_accounts: Vec<TridentAccountSharedData>,
Expand All @@ -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<TridentEntrypoint>) -> Self {
pub fn with_program_entries(&mut self, entries: Vec<TridentEntrypoint>) -> &Self {
self.config.program_entrypoints = entries;
self
}

pub fn with_sbf_programs(mut self, programs: Vec<TridentProgram>) -> Self {
pub fn with_sbf_programs(&mut self, programs: Vec<TridentProgram>) -> &Self {
self.config.program_binaries = programs;
self
}

pub fn with_permanent_accounts(mut self, accounts: Vec<TridentAccountSharedData>) -> Self {
pub fn with_permanent_accounts(&mut self, accounts: Vec<TridentAccountSharedData>) -> &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 {
Expand All @@ -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);
}
Expand Down
28 changes: 5 additions & 23 deletions src/methods/trident_svm_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
};

Expand Down Expand Up @@ -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();

Expand Down
Loading