Skip to content

Commit

Permalink
fix creating StarcoinVM
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjiao committed Oct 15, 2024
1 parent 9190d07 commit 56c73e9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
7 changes: 0 additions & 7 deletions vm/vm-runtime/src/data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@ impl<'a, S: StateView> ResourceResolver for RemoteStorage<'a, S> {
}
}

// TODO Note for Conflicting: conflicting implementation in crate `starcoin_vm_types`: - impl<V> ConfigStorage for V where V: StateView;
// impl<'a, S: StateView> ConfigStorage for RemoteStorage<'a, S> {
// fn fetch_config(&self, access_path: AccessPath) -> Option<Vec<u8>> {
// self.get(&access_path).ok()?
// }
// }

impl<'a, S> Deref for RemoteStorage<'a, S> {
type Target = S;

Expand Down
2 changes: 1 addition & 1 deletion vm/vm-runtime/src/parallel_executor/vm_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<'a, S: 'a + StateView + Sync> ExecutorTask for StarcoinVMWrapper<'a, S> {
// XXX FIXME YSG
fn init(argument: &'a S) -> Self {
// XXX FIXME YSG
let mut vm = StarcoinVM::new(None);
let mut vm = StarcoinVM::new(None, argument);
// XXX FIXME YSG
vm.load_configs(argument)
.expect("load configs should always success");
Expand Down
37 changes: 30 additions & 7 deletions vm/vm-runtime/src/starcoin_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use starcoin_types::{
TransactionPayload, TransactionStatus,
},
};
use starcoin_vm_types::on_chain_config::{Features, TimedFeaturesBuilder};
use starcoin_vm_types::{
access::{ModuleAccess, ScriptAccess},
account_address::AccountAddress,
Expand Down Expand Up @@ -93,11 +94,22 @@ const FLEXI_DAG_UPGRADE_VERSION_MARK: u64 = 12;

impl StarcoinVM {
#[cfg(feature = "metrics")]
pub fn new(metrics: Option<VMMetrics>) -> Self {
pub fn new<S: StateView>(metrics: Option<VMMetrics>, state: &S) -> Self {
let chain_id = state.get_chain_id().unwrap().id();
let gas_params = StarcoinGasParameters::initial();
let native_params = gas_params.natives.clone();
let inner = MoveVmExt::new(native_params.clone())
.expect("should be able to create Move VM; check if there are duplicated natives");
// todo: double check if it's ok to use RemoteStorage as StarcoinMoveResolver
let resolver = RemoteStorage::new(state);
let inner = MoveVmExt::new(
native_params.clone(),
gas_params.vm.misc.clone(),
1,
chain_id,
Features::default(),
TimedFeaturesBuilder::enable_all().build(),
&resolver,
)
.expect("should be able to create Move VM; check if there are duplicated natives");
Self {
move_vm: Arc::new(inner),
vm_config: None,
Expand All @@ -111,11 +123,22 @@ impl StarcoinVM {
}
}
#[cfg(not(feature = "metrics"))]
pub fn new() -> Self {
pub fn new<S: StateView>(state: &S) -> Self {
let chain_id = state.get_chain_id().id();
let gas_params = StarcoinGasParameters::initial();
let native_params = gas_params.natives.clone();
let inner = MoveVmExt::new(native_params.clone())
.expect("should be able to create Move VM; check if there are duplicated natives");
// todo: double check if it's ok to use RemoteStorage as StarcoinMoveResolver
let resolver = RemoteStorage::new(state);
let inner = MoveVmExt::new(
native_params.clone(),
gas_params.vm.misc.clone(),
1,
chain_id,
Features::default(),
TimedFeaturesBuilder::enable_all().build(),
resolver,
)
.expect("should be able to create Move VM; check if there are duplicated natives");
Self {
move_vm: Arc::new(inner),
vm_config: None,
Expand Down Expand Up @@ -1467,7 +1490,7 @@ impl StarcoinVM {
block_gas_limit: Option<u64>,
metrics: Option<VMMetrics>,
) -> Result<Vec<(VMStatus, TransactionOutput)>, VMStatus> {
let mut vm = Self::new(metrics);
let mut vm = Self::new(metrics, state_view);
vm.execute_block_transactions(state_view, txns, block_gas_limit)
}

Expand Down

0 comments on commit 56c73e9

Please sign in to comment.