Skip to content

Commit

Permalink
use Option directly
Browse files Browse the repository at this point in the history
  • Loading branch information
steelgeek091 committed Aug 31, 2024
1 parent 9d8f10c commit 43aac9f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
Binary file modified crates/rooch-genesis/released/main
Binary file not shown.
Binary file modified crates/rooch-genesis/released/test
Binary file not shown.
35 changes: 23 additions & 12 deletions crates/rooch-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use rooch_store::transaction_store::TransactionStore;
use rooch_types::address::BitcoinAddress;
use rooch_types::bitcoin::genesis::BitcoinGenesisContext;
use rooch_types::error::GenesisError;
use rooch_types::framework::chain_id::ChainID;
use rooch_types::indexer::event::IndexerEvent;
use rooch_types::indexer::state::{
handle_object_change, IndexerObjectStateChangeSet, IndexerObjectStatesIndexGenerator,
Expand Down Expand Up @@ -86,7 +87,7 @@ pub struct FrameworksGasParameters {
pub vm_gas_params: VMGasParameters,
pub rooch_framework_gas_params: rooch_framework::natives::NativeGasParameters,
pub bitcoin_move_gas_params: bitcoin_move::natives::GasParameters,
pub rooch_nursery_gas_params: rooch_nursery::natives::GasParameters,
pub rooch_nursery_gas_params: Option<rooch_nursery::natives::GasParameters>,
}

impl FrameworksGasParameters {
Expand All @@ -96,7 +97,7 @@ impl FrameworksGasParameters {
vm_gas_params: VMGasParameters::initial(),
rooch_framework_gas_params: rooch_framework::natives::NativeGasParameters::initial(),
bitcoin_move_gas_params: bitcoin_move::natives::GasParameters::initial(),
rooch_nursery_gas_params: rooch_nursery::natives::GasParameters::initial(),
rooch_nursery_gas_params: Some(rooch_nursery::natives::GasParameters::initial()),
}
}

Expand All @@ -106,7 +107,7 @@ impl FrameworksGasParameters {
vm_gas_params: VMGasParameters::initial(),
rooch_framework_gas_params: rooch_framework::natives::NativeGasParameters::initial(),
bitcoin_move_gas_params: bitcoin_move::natives::GasParameters::initial(),
rooch_nursery_gas_params: rooch_nursery::natives::GasParameters::initial(),
rooch_nursery_gas_params: Some(rooch_nursery::natives::GasParameters::initial()),
};

if LATEST_GAS_SCHEDULE_VERSION >= GAS_SCHEDULE_RELEASE_V1 {
Expand Down Expand Up @@ -143,11 +144,19 @@ impl FrameworksGasParameters {
gas_parameter
}

pub fn to_gas_schedule_config(&self) -> GasScheduleConfig {
pub fn to_gas_schedule_config(&self, chain_id: ChainID) -> GasScheduleConfig {
let mut entries = self.vm_gas_params.to_on_chain_gas_schedule();
entries.extend(self.rooch_framework_gas_params.to_on_chain_gas_schedule());
entries.extend(self.bitcoin_move_gas_params.to_on_chain_gas_schedule());
entries.extend(self.rooch_nursery_gas_params.to_on_chain_gas_schedule());

if chain_id == BuiltinChainID::Dev.chain_id()
|| chain_id == BuiltinChainID::Local.chain_id()
{
if let Some(gas_params) = self.rooch_nursery_gas_params.clone() {
entries.extend(gas_params.to_on_chain_gas_schedule());
}
}

GasScheduleConfig {
max_gas_amount: self.max_gas_amount,
entries: entries
Expand Down Expand Up @@ -189,8 +198,7 @@ impl FrameworksGasParameters {
bitcoin_move::natives::GasParameters::from_on_chain_gas_schedule(&entries)
.ok_or_else(|| anyhow::anyhow!("Failed to load bitcoin move gas parameters"))?;
let rooch_nursery_gas_params =
rooch_nursery::natives::GasParameters::from_on_chain_gas_schedule(&entries)
.ok_or_else(|| anyhow::anyhow!("Failed to load rooch nursery gas parameters"))?;
rooch_nursery::natives::GasParameters::from_on_chain_gas_schedule(&entries);
Ok(Self {
max_gas_amount,
vm_gas_params: vm_gas_parameter,
Expand All @@ -205,10 +213,13 @@ impl FrameworksGasParameters {
rooch_framework::natives::all_natives(self.rooch_framework_gas_params.clone());
let bitcoin_move_native_table =
bitcoin_move::natives::all_natives(self.bitcoin_move_gas_params.clone());
let rooch_nursery_native_table =
rooch_nursery::natives::all_natives(self.rooch_nursery_gas_params.clone());

if let Some(gas_params) = self.rooch_nursery_gas_params.clone() {
let rooch_nursery_native_table = rooch_nursery::natives::all_natives(gas_params);
rooch_framework_native_tables.extend(rooch_nursery_native_table);
}

rooch_framework_native_tables.extend(bitcoin_move_native_table);
rooch_framework_native_tables.extend(rooch_nursery_native_table);
rooch_framework_native_tables
}
}
Expand Down Expand Up @@ -269,7 +280,7 @@ impl RoochGenesis {
FrameworksGasParameters::initial()
}
};
let gas_config = gas_parameter.to_gas_schedule_config();
let gas_config = gas_parameter.to_gas_schedule_config(network.chain_id);
genesis_moveos_tx.ctx.add(genesis_ctx.clone())?;
genesis_moveos_tx.ctx.add(moveos_genesis_ctx.clone())?;
genesis_moveos_tx.ctx.add(bitcoin_genesis_ctx.clone())?;
Expand Down Expand Up @@ -562,7 +573,7 @@ mod tests {
.map(|entry| (entry.key, entry.val))
.collect::<BTreeMap<_, _>>(),
gas_parameter
.to_gas_schedule_config()
.to_gas_schedule_config(network.chain_id.clone())
.entries
.into_iter()
.map(|entry| (entry.key, entry.val))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rooch_framework::natives::gas_parameter::gas_member::ToOnChainGasSchedule;
use rooch_genesis::{FrameworksGasParameters, LATEST_GAS_SCHEDULE_VERSION};
use rooch_rpc_api::jsonrpc_types::ExecuteTransactionResponseView;
use rooch_types::error::{RoochError, RoochResult};
use rooch_types::rooch_network::BuiltinChainID;
use rooch_types::transaction::RoochTransaction;

use crate::cli_types::{CommandAction, TransactionOptions, WalletContextOptions};
Expand Down Expand Up @@ -135,7 +136,8 @@ impl CommandAction<ExecuteTransactionResponseView> for UpgradeGasConfigCommand {
}
};

let latest_gas_schedule = local_latest_gas_parameters.to_gas_schedule_config();
let latest_gas_schedule =
local_latest_gas_parameters.to_gas_schedule_config(BuiltinChainID::Test.chain_id());
let gas_schedule_bytes = latest_gas_schedule
.to_move_value()
.simple_serialize()
Expand Down
4 changes: 1 addition & 3 deletions frameworks/rooch-nursery/src/natives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ impl GasParameters {

impl FromOnChainGasSchedule for GasParameters {
fn from_on_chain_gas_schedule(gas_schedule: &BTreeMap<String, u64>) -> Option<Self> {
Some(Self {
wasm: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(),
})
FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).map(|v| Self { wasm: v })
}
}

Expand Down

0 comments on commit 43aac9f

Please sign in to comment.