Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm: simplify calculation of entrypoint index #11365

Merged
merged 1 commit into from
May 22, 2024
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
17 changes: 8 additions & 9 deletions runtime/near-vm-runner/src/near_vm_runner/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl NearVM {
&self,
artifact: &VMArtifact,
mut import: NearVmImports<'_, '_, '_>,
method_name: &str,
entrypoint: FunctionIndex,
) -> Result<Result<(), FunctionCallError>, VMRunnerError> {
let _span = tracing::debug_span!(target: "vm", "run_method").entered();

Expand All @@ -358,10 +358,6 @@ impl NearVM {
offset_of!(near_vm_types::FastGasCounter, gas_limit)
);
let gas = import.vmlogic.gas_counter_pointer() as *mut near_vm_types::FastGasCounter;
let entrypoint = match get_entrypoint_index(&*artifact, method_name) {
Ok(index) => index,
Err(abort) => return Ok(Err(abort)),
};
unsafe {
let instance = {
let _span = tracing::debug_span!(target: "vm", "run_method/instantiate").entered();
Expand Down Expand Up @@ -615,10 +611,13 @@ impl crate::runner::VM for NearVM {
method_name,
|vmmemory, mut logic, artifact| {
let import = imports::near_vm::build(vmmemory, &mut logic, artifact.engine());
if let Err(e) = get_entrypoint_index(&*artifact, method_name) {
return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol(logic, e));
}
match self.run_method(&artifact, import, method_name)? {
let entrypoint = match get_entrypoint_index(&*artifact, method_name) {
Ok(index) => index,
Err(e) => {
return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol(logic, e))
}
};
match self.run_method(&artifact, import, entrypoint)? {
Ok(()) => Ok(VMOutcome::ok(logic)),
Err(err) => Ok(VMOutcome::abort(logic, err)),
}
Expand Down
15 changes: 6 additions & 9 deletions runtime/near-vm-runner/src/wasmer2_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl Wasmer2VM {
&self,
artifact: &VMArtifact,
mut import: Wasmer2Imports<'_, '_, '_>,
method_name: &str,
entrypoint: FunctionIndex,
) -> Result<Result<(), FunctionCallError>, VMRunnerError> {
let _span = tracing::debug_span!(target: "vm", "run_method").entered();

Expand All @@ -416,10 +416,6 @@ impl Wasmer2VM {
offset_of!(wasmer_types::FastGasCounter, opcode_cost)
);
let gas = import.vmlogic.gas_counter_pointer() as *mut wasmer_types::FastGasCounter;
let entrypoint = match get_entrypoint_index(&*artifact, method_name) {
Ok(index) => index,
Err(abort) => return Ok(Err(abort)),
};
unsafe {
let instance = {
let _span = tracing::debug_span!(target: "vm", "run_method/instantiate").entered();
Expand Down Expand Up @@ -613,10 +609,11 @@ impl crate::runner::VM for Wasmer2VM {
return Ok(VMOutcome::abort(logic, e));
}
let import = imports::wasmer2::build(vmmemory, &mut logic, artifact.engine());
if let Err(e) = get_entrypoint_index(&*artifact, method_name) {
return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol(logic, e));
}
match self.run_method(&artifact, import, method_name)? {
let entrypoint = match get_entrypoint_index(&*artifact, method_name) {
Ok(index) => index,
Err(e) => return Ok(VMOutcome::abort_but_nop_outcome_in_old_protocol(logic, e)),
};
match self.run_method(&artifact, import, entrypoint)? {
Ok(()) => Ok(VMOutcome::ok(logic)),
Err(err) => Ok(VMOutcome::abort(logic, err)),
}
Expand Down
Loading