Skip to content

Commit 43c6d6d

Browse files
andrejlukacan
authored andcommitted
✨ Use syscall features
1 parent 568bedf commit 43c6d6d

File tree

10 files changed

+50
-17
lines changed

10 files changed

+50
-17
lines changed

Cargo.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ license-file = "./LICENSE"
88
readme = "./README.md"
99
description = "Trident SVM implementation by Ackee Blockchain Security"
1010

11+
[features]
12+
syscalls = ["syscall-v1", "syscall-v2"]
13+
14+
syscall-v1 = [
15+
"trident-syscall-stubs-v1",
16+
"solana_rbpf",
17+
]
18+
syscall-v2 = [
19+
"trident-syscall-stubs-v2",
20+
"solana_rbpf",
21+
]
22+
1123
[dependencies]
1224

1325
# Solana
1426
solana-sdk = "~2.0"
1527
solana-program-runtime = "~2.0"
16-
solana_rbpf = "~0.8"
1728

1829
# Programs
1930
solana-system-program = "~2.0"
@@ -30,6 +41,9 @@ solana-svm = "~2.0"
3041
solana-compute-budget = "~2.0"
3142
solana-logger = "~2.0"
3243

44+
45+
solana_rbpf = {version = "~0.8", optional = true}
46+
3347
# Misc
3448
serde = { version = "1", default-features = false }
3549
bincode = "1.3"
@@ -38,6 +52,8 @@ log = "0.4"
3852
# Syscall stubs
3953
[dependencies.trident-syscall-stubs-v1]
4054
version = "0.0.1"
55+
optional = true
4156

4257
[dependencies.trident-syscall-stubs-v2]
4358
version = "0.0.1"
59+
optional = true

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "1.81.0"
2+
channel = "1.88.0"

src/accounts_database/sysvar_tracker.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ mod tests {
5252
let diff = (updated_clock.unix_timestamp - initial_timestamp) as u64;
5353
assert!(
5454
(1..=3).contains(&diff),
55-
"Clock update difference should be ~2 seconds, got {}",
56-
diff
55+
"Clock update difference should be ~2 seconds, got {diff}"
5756
);
5857
}
5958

src/builder.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::trident_svm::TridentSVM;
22
use crate::trident_svm_log::{setup_cli_logging, setup_file_logging, turn_off_solana_logging};
33
use crate::types::trident_account::TridentAccountSharedData;
4+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
45
use crate::types::trident_entrypoint::TridentEntrypoint;
56
use crate::types::trident_program::TridentProgram;
67

@@ -10,6 +11,7 @@ pub struct TridentSVMConfig {
1011
syscalls_v2: bool,
1112
cli_logs: bool, // TODO, add better debbug levels
1213
debug_file_logs: bool,
14+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
1315
program_entrypoints: Vec<TridentEntrypoint>,
1416
program_binaries: Vec<TridentProgram>,
1517
permanent_accounts: Vec<TridentAccountSharedData>,
@@ -37,6 +39,7 @@ impl TridentSVMBuilder {
3739
self
3840
}
3941

42+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
4043
pub fn with_program_entries(&mut self, entries: Vec<TridentEntrypoint>) -> &Self {
4144
self.config.program_entrypoints = entries;
4245
self
@@ -65,9 +68,11 @@ impl TridentSVMBuilder {
6568
pub fn build(&self) -> TridentSVM {
6669
let mut svm = TridentSVM::default();
6770

71+
#[cfg(feature = "syscall-v1")]
6872
if self.config.syscalls_v1 {
6973
svm.initialize_syscalls_v1();
7074
}
75+
#[cfg(feature = "syscall-v2")]
7176
if self.config.syscalls_v2 {
7277
svm.initialize_syscalls_v2();
7378
}
@@ -80,6 +85,7 @@ impl TridentSVMBuilder {
8085
turn_off_solana_logging();
8186
}
8287

88+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
8389
for entry in &self.config.program_entrypoints {
8490
svm.deploy_entrypoint_program(entry);
8591
}

src/builtin_function.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#![allow(clippy::not_unsafe_ptr_arg_deref)]
22

3-
use std::collections::HashMap;
4-
5-
use solana_sdk::transaction_context::IndexOfAccount;
6-
73
use solana_bpf_loader_program::serialization::serialize_parameters;
8-
94
use solana_program_runtime::invoke_context::InvokeContext;
5+
use solana_sdk::transaction_context::IndexOfAccount;
6+
use std::collections::HashMap;
107

118
use solana_rbpf::aligned_memory::AlignedMemory;
129
use solana_rbpf::ebpf::HOST_ALIGN;
1310

11+
#[cfg(feature = "syscall-v1")]
1412
use trident_syscall_stubs_v1::set_invoke_context as set_invoke_context_v1;
13+
#[cfg(feature = "syscall-v2")]
1514
use trident_syscall_stubs_v2::set_invoke_context as set_invoke_context_v2;
1615

1716
#[macro_export]
@@ -166,7 +165,9 @@ pub fn pre_invocation(
166165
),
167166
Box<dyn std::error::Error>,
168167
> {
168+
#[cfg(feature = "syscall-v1")]
169169
set_invoke_context_v1(invoke_context);
170+
#[cfg(feature = "syscall-v2")]
170171
set_invoke_context_v2(invoke_context);
171172

172173
let transaction_context = &invoke_context.transaction_context;

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ mod trident_fork_graphs;
66
pub mod trident_svm_log;
77
mod utils;
88

9+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
910
pub mod builtin_function;
1011
pub mod trident_svm;
1112
pub mod types;
1213

1314
pub mod processor {
15+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
1416
pub use crate::builtin_function::post_invocation;
17+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
1518
pub use crate::builtin_function::pre_invocation;
1619

1720
pub use solana_program_runtime;
1821
pub use solana_program_runtime::stable_log;
22+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
1923
pub use solana_rbpf;
2024
pub use solana_sdk::account_info;
2125
pub use solana_sdk::entrypoint::deserialize;

src/methods/trident_svm_programs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use solana_sdk::account::WritableAccount;
33
use solana_sdk::bpf_loader_upgradeable;
44
use solana_sdk::bpf_loader_upgradeable::UpgradeableLoaderState;
55

6-
use solana_sdk::native_loader;
6+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
7+
use {
8+
crate::types::trident_entrypoint::TridentEntrypoint,
9+
solana_program_runtime::loaded_programs::ProgramCacheEntry, solana_sdk::native_loader,
10+
};
711

812
use solana_sdk::rent::Rent;
913

10-
use solana_program_runtime::loaded_programs::ProgramCacheEntry;
11-
1214
use crate::trident_svm::TridentSVM;
13-
use crate::types::trident_entrypoint::TridentEntrypoint;
1415
use crate::types::trident_program::TridentProgram;
1516

1617
impl TridentSVM {
@@ -67,6 +68,7 @@ impl TridentSVM {
6768
.set_program(&program_data_account, &account_data);
6869
}
6970

71+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
7072
pub fn deploy_entrypoint_program(&mut self, program: &TridentEntrypoint) {
7173
let entry = match program.entry {
7274
Some(entry) => entry,

src/methods/trident_svm_transactions.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,11 @@ impl TridentSVM {
117117
details,
118118
..
119119
} => match &details.status {
120-
Ok(()) => match &result.loaded_transactions[0] {
121-
Ok(loaded_transaction) => {
120+
Ok(()) => {
121+
if let Ok(loaded_transaction) = &result.loaded_transactions[0] {
122122
self.settle_accounts(&loaded_transaction.accounts);
123123
}
124-
Err(_) => {}
125-
},
124+
}
126125
Err(_transaction_error) => {
127126
// in case of transaction error, we don't need to do anything
128127
}

src/trident_svm.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ use solana_sdk::feature_set::FeatureSet;
3232

3333
use solana_svm::transaction_processing_callback::TransactionProcessingCallback;
3434
use solana_svm::transaction_processor::TransactionBatchProcessor;
35+
36+
#[cfg(feature = "syscall-v1")]
3537
use trident_syscall_stubs_v1::set_stubs_v1;
38+
#[cfg(feature = "syscall-v2")]
3639
use trident_syscall_stubs_v2::set_stubs_v2;
3740

3841
use crate::accounts_database::accounts_db::AccountsDB;
@@ -52,10 +55,12 @@ pub struct TridentSVM {
5255
}
5356

5457
impl TridentSVM {
58+
#[cfg(feature = "syscall-v1")]
5559
pub(crate) fn initialize_syscalls_v1(&mut self) {
5660
set_stubs_v1();
5761
}
5862

63+
#[cfg(feature = "syscall-v2")]
5964
pub(crate) fn initialize_syscalls_v2(&mut self) {
6065
set_stubs_v2();
6166
}

src/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod trident_account;
2+
#[cfg(any(feature = "syscall-v1", feature = "syscall-v2"))]
23
pub mod trident_entrypoint;
34
pub mod trident_program;

0 commit comments

Comments
 (0)