Skip to content

Commit fc1d66b

Browse files
authored
Revert "Support registering custom syscalls" (#127)
1 parent eb5fea3 commit fc1d66b

File tree

7 files changed

+26
-175
lines changed

7 files changed

+26
-175
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ audit:
2929
# Build test programs
3030
build-test-programs:
3131
@cargo build-sbf --manifest-path test-programs/cpi-target/Cargo.toml
32-
@cargo build-sbf --manifest-path test-programs/custom-syscall/Cargo.toml
3332
@cargo build-sbf --manifest-path test-programs/primary/Cargo.toml
3433

3534
# Pre-publish checks
@@ -85,7 +84,6 @@ check-features:
8584

8685
# Run tests
8786
test:
88-
@$(MAKE) build-test-programs
8987
@cargo test --all-features
9088

9189
# Run all checks in sequence

harness/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ impl Default for Mollusk {
503503
solana_runtime::message_processor=debug,\
504504
solana_runtime::system_instruction_processor=trace",
505505
);
506-
let compute_budget = ComputeBudget::default();
507506
#[cfg(feature = "fuzz")]
508507
let feature_set = {
509508
// Omit "test features" (they have the same u64 ID).
@@ -516,13 +515,12 @@ impl Default for Mollusk {
516515
};
517516
#[cfg(not(feature = "fuzz"))]
518517
let feature_set = FeatureSet::all_enabled();
519-
let program_cache = ProgramCache::new(&feature_set, &compute_budget);
520518
Self {
521519
config: Config::default(),
522-
compute_budget,
520+
compute_budget: ComputeBudget::default(),
523521
feature_set,
524522
logger: None,
525-
program_cache,
523+
program_cache: ProgramCache::default(),
526524
sysvars: Sysvars::default(),
527525
#[cfg(feature = "fuzz-fd")]
528526
slot: 0,
@@ -575,7 +573,13 @@ impl Mollusk {
575573
elf: &[u8],
576574
loader_key: &Pubkey,
577575
) {
578-
self.program_cache.add_program(program_id, loader_key, elf);
576+
self.program_cache.add_program(
577+
program_id,
578+
loader_key,
579+
elf,
580+
&self.compute_budget,
581+
&self.feature_set,
582+
);
579583
}
580584

581585
/// Warp the test environment to a slot by updating sysvars.

harness/src/program.rs

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ use {
88
solana_loader_v3_interface::state::UpgradeableLoaderState,
99
solana_loader_v4_interface::state::{LoaderV4State, LoaderV4Status},
1010
solana_program_runtime::{
11-
invoke_context::{BuiltinFunctionWithContext, InvokeContext},
11+
invoke_context::BuiltinFunctionWithContext,
1212
loaded_programs::{LoadProgramMetrics, ProgramCacheEntry, ProgramCacheForTxBatch},
13-
solana_sbpf::{
14-
elf::ElfError,
15-
program::{BuiltinFunction, BuiltinProgram},
16-
},
1713
},
1814
solana_pubkey::Pubkey,
1915
solana_rent::Rent,
@@ -61,23 +57,13 @@ pub struct ProgramCache {
6157
//
6258
// K: program ID, V: loader key
6359
entries_cache: Rc<RefCell<HashMap<Pubkey, Pubkey>>>,
64-
// The function registry (syscalls) to use for verifying and loading
65-
// program ELFs.
66-
program_runtime_environment: BuiltinProgram<InvokeContext<'static>>,
6760
}
6861

69-
impl ProgramCache {
70-
pub fn new(feature_set: &FeatureSet, compute_budget: &ComputeBudget) -> Self {
62+
impl Default for ProgramCache {
63+
fn default() -> Self {
7164
let me = Self {
7265
cache: Rc::new(RefCell::new(ProgramCacheForTxBatch::default())),
7366
entries_cache: Rc::new(RefCell::new(HashMap::new())),
74-
program_runtime_environment: create_program_runtime_environment_v1(
75-
feature_set,
76-
compute_budget,
77-
/* reject_deployment_of_broken_elfs */ false,
78-
/* debugging_features */ false,
79-
)
80-
.unwrap(),
8167
};
8268
BUILTINS.iter().for_each(|builtin| {
8369
let program_id = builtin.program_id;
@@ -86,7 +72,9 @@ impl ProgramCache {
8672
});
8773
me
8874
}
75+
}
8976

77+
impl ProgramCache {
9078
pub(crate) fn cache(&self) -> RefMut<ProgramCacheForTxBatch> {
9179
self.cache.borrow_mut()
9280
}
@@ -106,24 +94,18 @@ impl ProgramCache {
10694
}
10795

10896
/// Add a program to the cache.
109-
pub fn add_program(&mut self, program_id: &Pubkey, loader_key: &Pubkey, elf: &[u8]) {
110-
// This might look rough, but it's actually functionally the same as
111-
// calling `create_program_runtime_environment_v1` on every addition.
112-
let environment = {
113-
let config = self.program_runtime_environment.get_config().clone();
114-
let mut loader = BuiltinProgram::new_loader(config);
115-
116-
for (_key, (name, value)) in self
117-
.program_runtime_environment
118-
.get_function_registry()
119-
.iter()
120-
{
121-
let name = std::str::from_utf8(name).unwrap();
122-
loader.register_function(name, value).unwrap();
123-
}
124-
125-
Arc::new(loader)
126-
};
97+
pub fn add_program(
98+
&mut self,
99+
program_id: &Pubkey,
100+
loader_key: &Pubkey,
101+
elf: &[u8],
102+
compute_budget: &ComputeBudget,
103+
feature_set: &FeatureSet,
104+
) {
105+
let environment = Arc::new(
106+
create_program_runtime_environment_v1(feature_set, compute_budget, false, false)
107+
.unwrap(),
108+
);
127109
self.replenish(
128110
*program_id,
129111
Arc::new(
@@ -167,19 +149,6 @@ impl ProgramCache {
167149
})
168150
.collect()
169151
}
170-
171-
/// Register a new function (syscall) with the program runtime environment.
172-
///
173-
/// **Important**: You should register all custom syscalls BEFORE adding any
174-
/// programs to the store that will use them.
175-
pub fn register_function(
176-
&mut self,
177-
name: &str,
178-
value: BuiltinFunction<InvokeContext<'static>>,
179-
) -> Result<(), ElfError> {
180-
self.program_runtime_environment
181-
.register_function(name, value)
182-
}
183152
}
184153

185154
pub struct Builtin {

harness/tests/custom_syscall.rs

Lines changed: 0 additions & 67 deletions
This file was deleted.

test-programs/custom-syscall/Cargo.toml

Lines changed: 0 additions & 16 deletions
This file was deleted.

test-programs/custom-syscall/src/lib.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)