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

backport 4046 #4048

Merged
merged 2 commits into from
Jun 30, 2023
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
4 changes: 2 additions & 2 deletions script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ mod verify_env;

pub use crate::error::{ScriptError, TransactionScriptError};
pub use crate::types::{
CoreMachine, ScriptGroup, ScriptGroupType, ScriptVersion, TransactionSnapshot,
TransactionState, VerifyResult, VmIsa, VmVersion,
CoreMachine, MachineContext, ResumableMachine, ScriptGroup, ScriptGroupType, ScriptVersion,
TransactionSnapshot, TransactionState, VerifyResult, VmIsa, VmVersion,
};
pub use crate::verify::{TransactionScriptsSyscallsGenerator, TransactionScriptsVerifier};
pub use crate::verify_env::TxVerifyEnv;
8 changes: 7 additions & 1 deletion script/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ pub(crate) type Machine = TraceMachine<CoreMachine>;
/// a chain of spawned machines.
#[derive(Default)]
pub struct MachineContext {
pub(crate) suspended_machines: Vec<ResumableMachine>,
/// A stack of ResumableMachines.
pub suspended_machines: Vec<ResumableMachine>,
}

/// Data structure captured all environment data for a suspended machine
Expand Down Expand Up @@ -175,8 +176,11 @@ impl TryFrom<&SpawnData> for ResumePoint {
}
}

/// An enumerated type indicating the type of the Machine.
pub enum ResumableMachine {
/// Root machine instance.
Initial(Machine),
/// A machine which created by spawn syscall.
Spawn(Machine, SpawnData),
}

Expand Down Expand Up @@ -211,10 +215,12 @@ impl ResumableMachine {
set_vm_max_cycles(self.machine_mut(), cycles)
}

/// Add cycles to current machine.
pub fn add_cycles(&mut self, cycles: Cycle) -> Result<(), VMInternalError> {
self.machine_mut().machine.add_cycles(cycles)
}

/// Run machine.
pub fn run(&mut self) -> Result<i8, VMInternalError> {
self.machine_mut().run()
}
Expand Down