Skip to content

Commit

Permalink
vm: simplify calculation of entrypoint index (#11365)
Browse files Browse the repository at this point in the history
This was a headscratcher to me as I ended up with the two blocks in the
same area and the `Err` branch in the 2nd block seemed unreachable to me
(and there were not any side-effects in between.) At first I thought
that maybe this is a holdover from wasmer2 times, but it is the same
there!
  • Loading branch information
nagisa committed May 22, 2024
1 parent 87da0e1 commit 204b798
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
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

0 comments on commit 204b798

Please sign in to comment.