diff --git a/Cargo.lock b/Cargo.lock index 4d7f97e4c0..e15fad1cb9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9605,6 +9605,7 @@ dependencies = [ "moveos-types", "moveos-wasm", "musig2", + "rooch-framework", "rooch-types", "serde_json", "smallvec", diff --git a/crates/rooch-genesis/src/lib.rs b/crates/rooch-genesis/src/lib.rs index 23a74d3aff..a6161d22a4 100644 --- a/crates/rooch-genesis/src/lib.rs +++ b/crates/rooch-genesis/src/lib.rs @@ -29,11 +29,6 @@ use rooch_framework::natives::gas_parameter::gas_member::{ }; use rooch_framework::ROOCH_FRAMEWORK_ADDRESS; use rooch_indexer::store::traits::IndexerStoreTrait; -use rooch_nursery::natives::gas_parameter::gas_member::InitialGasSchedule as RoochNurseryInitialGasSchedule; -use rooch_nursery::natives::gas_parameter::gas_member::{ - FromOnChainGasSchedule as RoochNurseryFromOnChainGasSchedule, - ToOnChainGasSchedule as RoochNurseryToOnChainGasSchedule, -}; use rooch_store::meta_store::MetaStore; use rooch_store::transaction_store::TransactionStore; use rooch_types::address::BitcoinAddress; diff --git a/frameworks/framework-release/released/8/stdlib b/frameworks/framework-release/released/8/stdlib index 2fb2d8c63e..85c0bb8320 100644 Binary files a/frameworks/framework-release/released/8/stdlib and b/frameworks/framework-release/released/8/stdlib differ diff --git a/frameworks/rooch-nursery/Cargo.toml b/frameworks/rooch-nursery/Cargo.toml index 0480361ec3..4a921d0674 100644 --- a/frameworks/rooch-nursery/Cargo.toml +++ b/frameworks/rooch-nursery/Cargo.toml @@ -39,4 +39,5 @@ moveos-stdlib = { workspace = true } moveos = { workspace = true } moveos-wasm = { workspace = true } -rooch-types = { workspace = true } \ No newline at end of file +rooch-types = { workspace = true } +rooch-framework = { workspace = true } \ No newline at end of file diff --git a/frameworks/rooch-nursery/src/natives/gas_parameter/gas_member.rs b/frameworks/rooch-nursery/src/natives/gas_parameter/gas_member.rs deleted file mode 100644 index f4d8989e56..0000000000 --- a/frameworks/rooch-nursery/src/natives/gas_parameter/gas_member.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) RoochNetwork -// SPDX-License-Identifier: Apache-2.0 - -use std::collections::BTreeMap; - -/// A trait for converting from a map representation of the on-chain gas schedule. -pub trait FromOnChainGasSchedule: Sized { - /// Constructs a value of this type from a map representation of the on-chain gas schedule. - /// `None` should be returned when the gas schedule is missing some required entries. - /// Unused entries should be safely ignored. - fn from_on_chain_gas_schedule(gas_schedule: &BTreeMap) -> Option; -} - -/// A trait for converting to a list of entries of the on-chain gas schedule. -pub trait ToOnChainGasSchedule { - /// Converts `self` into a list of entries of the on-chain gas schedule. - /// Each entry is a key-value pair where the key is a string representing the name of the - /// parameter, where the value is the gas parameter itself. - fn to_on_chain_gas_schedule(&self) -> Vec<(String, u64)>; -} - -/// A trait for defining an initial value to be used in the genesis. -pub trait InitialGasSchedule: Sized { - /// Returns the initial value of this type, which is used in the genesis. - fn initial() -> Self; -} diff --git a/frameworks/rooch-nursery/src/natives/gas_parameter/mod.rs b/frameworks/rooch-nursery/src/natives/gas_parameter/mod.rs index 25c236eeee..828224d05f 100644 --- a/frameworks/rooch-nursery/src/natives/gas_parameter/mod.rs +++ b/frameworks/rooch-nursery/src/natives/gas_parameter/mod.rs @@ -1,6 +1,4 @@ // Copyright (c) RoochNetwork // SPDX-License-Identifier: Apache-2.0 -pub mod gas_member; -pub mod native; pub mod wasm; diff --git a/frameworks/rooch-nursery/src/natives/gas_parameter/native.rs b/frameworks/rooch-nursery/src/natives/gas_parameter/native.rs deleted file mode 100644 index 36cee537af..0000000000 --- a/frameworks/rooch-nursery/src/natives/gas_parameter/native.rs +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) RoochNetwork -// SPDX-License-Identifier: Apache-2.0 - -// Copyright (c) The Starcoin Core Contributors -// SPDX-License-Identifier: Apache-2.0 -pub const MUL: u64 = 1; - -#[macro_export] -macro_rules! set_first_segment { - ($params: ident . $first:ident . $($rest:ident).*, $val: ident, $param_ty: ty) => { - $params .$first.$($rest)* = Some((*$val).into()); - }; -} - -#[macro_export] -macro_rules! expand_get_impl_for_native_gas_params { - ($params: ident $(.$field: ident)+, $map: ident, $prefix: literal, optional $key: literal) => { - if let Some(val) = $map.get(&format!("{}.{}", $prefix, $key)) { - $params $(.$field)+ = Some((*val).into()); - } - }; - ($params: ident $(.$field: ident)+, $map: ident, $prefix: literal, $key: literal) => { - $params $(.$field)+ = $map.get(&format!("{}.{}", $prefix, $key)).cloned()?.into(); - }; -} - -#[macro_export] -macro_rules! expand_get_for_native_gas_params { - (test_only $(.$field: ident)+, $(optional $($dummy: ident)?)? $key: literal, $initial_val: expr, $param_ty: ty, $package_name: literal, $params: ident, $gas_schedule: ident) => { - // TODO(Gas): this is a hack to work-around issue - // https://github.com/rust-lang/rust/issues/15701 - { - #[cfg(feature = "testing")] - fn assign(params: &mut $param_ty, gas_schedule: &std::collections::BTreeMap) -> Option<()> { - $crate::natives::gas_parameter::expand_get_impl_for_native_gas_params!(params $(.$field)+, gas_schedule, $package_name, $(optional $($dummy)?)? $key); - Some(()) - } - - #[cfg(not(feature = "testing"))] - fn assign(_params: &mut $param_ty, _gas_schedule: &std::collections::BTreeMap) -> Option<()> { - Some(()) - } - - assign(&mut $params, &$gas_schedule)?; - } - }; - ($(.$field: ident)+, $(optional $($dummy: ident)?)? $key: literal, $initial_val: expr, $param_ty: ty, $package_name: literal, $params: ident, $gas_schedule: ident) => { - $crate::natives::gas_parameter::native::expand_get_impl_for_native_gas_params!($params $(.$field)+, $gas_schedule, $package_name, $(optional $($dummy)?)? $key); - } -} - -#[macro_export] -macro_rules! expand_set_for_native_gas_params { - (test_only $(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr, $param_ty: ty, $package_name: literal, $params: ident) => { - { - #[cfg(feature = "testing")] - fn assign(params: &mut $param_ty) { - params $(.$field)+ = $initial_val.into(); - } - - #[cfg(not(feature = "testing"))] - fn assign(_params: &mut $param_ty) { - } - - assign(&mut $params); - } - }; - ($(.$field: ident)+, $key: literal, $initial_val: expr, $param_ty: ty, $package_name: literal, $params: ident) => { - $params $(.$field)+ = $initial_val.into() - }; - ($(.$field: ident)+, optional $key: literal, $initial_val: expr, $param_ty: ty, $package_name: literal, $params: ident) => { - $params $(.$field)+ = Some($initial_val.into()) - }; -} - -#[macro_export] -macro_rules! get_self_key_value { - (.$first:ident . $($rest:ident).*, $initial_val: expr, $self: ident, $key: literal) => { - ($key, u64::from($self .$first.$($rest)*.unwrap_or(0.into()))) - }; -} - -#[macro_export] -macro_rules! expand_kv_for_native_gas_params { - (test_only $(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr, $self: ident) => { - #[cfg(feature = "testing")] - ($key, u64::from($self $(.$field)+)) - }; - ($(.$field: ident)+, $key: literal, $initial_val: expr, $self: ident) => { - ($key, u64::from($self $(.$field)+)) - }; - ($(.$field: ident)+, optional $key: literal, $initial_val: expr, $self: ident) => { - $crate::natives::gas_parameter::native::get_self_key_value!($(.$field)+, $initial_val, $self, $key) - }; -} - -#[macro_export] -macro_rules! define_gas_parameters_for_natives { - ($param_ty: ty, $package_name: literal, [$([$($t: tt)*]),* $(,)?] $(, allow_unmapped = $allow_unmapped: expr)?) => { - impl $crate::natives::gas_parameter::gas_member::FromOnChainGasSchedule for $param_ty { - fn from_on_chain_gas_schedule(gas_schedule: &std::collections::BTreeMap) -> Option { - let mut params = <$param_ty>::zeros(); - - $( - $crate::natives::gas_parameter::native::expand_get_for_native_gas_params!($($t)*, $param_ty, $package_name, params, gas_schedule); - )* - - Some(params) - } - } - - impl $crate::natives::gas_parameter::gas_member::ToOnChainGasSchedule for $param_ty { - fn to_on_chain_gas_schedule(&self) -> Vec<(String, u64)> { - [$($crate::natives::gas_parameter::native::expand_kv_for_native_gas_params!($($t)*, self)),*] - .into_iter().filter(|(_, val)| *val > 0).map(|(key, val)| (format!("{}.{}", $package_name, key), val)).collect() - } - } - - impl $crate::natives::gas_parameter::gas_member::InitialGasSchedule for $param_ty { - fn initial() -> Self { - let mut params = <$param_ty>::zeros(); - - $( - $crate::natives::gas_parameter::native::expand_set_for_native_gas_params!($($t)*, $param_ty, $package_name, params); - )* - - params - } - } - - /* - #[test] - fn keys_should_be_unique() { - let mut map = std::collections::BTreeMap::<&str, ()>::new(); - - for key in [$(crate::natives::gas_parameter::native::extract_key_for_native_gas_params!($($t)*)),*] { - if map.insert(key.clone(), ()).is_some() { - panic!("duplicated key {}", key); - } - } - } - */ - }; -} - -pub use define_gas_parameters_for_natives; -pub use expand_get_for_native_gas_params; -pub use expand_get_impl_for_native_gas_params; -pub use expand_kv_for_native_gas_params; -pub use expand_set_for_native_gas_params; -pub use get_self_key_value; -pub use set_first_segment; diff --git a/frameworks/rooch-nursery/src/natives/gas_parameter/wasm.rs b/frameworks/rooch-nursery/src/natives/gas_parameter/wasm.rs index 7480bc47fe..cc3b94cb7b 100644 --- a/frameworks/rooch-nursery/src/natives/gas_parameter/wasm.rs +++ b/frameworks/rooch-nursery/src/natives/gas_parameter/wasm.rs @@ -3,7 +3,7 @@ use crate::natives::wasm::GasParameters; -crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "wasm", [ +rooch_framework::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "wasm", [ [.create_instance_gas_parameter.base_create_instance, "create_instance_gas_parameter.base_create_instance", 10000], [.create_instance_gas_parameter.per_byte_instance, "create_instance_gas_parameter.per_byte_instance", 100], diff --git a/frameworks/rooch-nursery/src/natives/mod.rs b/frameworks/rooch-nursery/src/natives/mod.rs index dc24c252ee..117fd3c073 100644 --- a/frameworks/rooch-nursery/src/natives/mod.rs +++ b/frameworks/rooch-nursery/src/natives/mod.rs @@ -1,10 +1,10 @@ // Copyright (c) RoochNetwork // SPDX-License-Identifier: Apache-2.0 -use crate::natives::gas_parameter::gas_member::{ +use move_vm_runtime::native_functions::{make_table_from_iter, NativeFunctionTable}; +use rooch_framework::natives::gas_parameter::gas_member::{ FromOnChainGasSchedule, InitialGasSchedule, ToOnChainGasSchedule, }; -use move_vm_runtime::native_functions::{make_table_from_iter, NativeFunctionTable}; use rooch_types::addresses::ROOCH_NURSERY_ADDRESS; use std::collections::BTreeMap;