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

[genesis] Fix module store size bug #1703

Merged
merged 1 commit into from
May 18, 2024
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
6 changes: 5 additions & 1 deletion crates/rooch-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,14 @@ mod tests {
.get_object(&ModuleStore::module_store_id())
.unwrap();
assert!(module_store_state.is_some());
let _module_store_obj = module_store_state
let module_store_obj = module_store_state
.unwrap()
.into_object::<ModuleStore>()
.unwrap();
assert!(
module_store_obj.size > 0,
"module store fields size should > 0"
);
let chain_id_state = resolver
.get_object(&rooch_types::framework::chain_id::ChainID::chain_id_object_id())
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::cli_types::{CommandAction, TransactionOptions, WalletContextOptions};
use async_trait::async_trait;
use clap::Parser;

use move_core_types::{identifier::Identifier, language_storage::ModuleId};
use rooch_key::key_derive::verify_password;
use rooch_rpc_api::jsonrpc_types::ExecuteTransactionResponseView;
use rooch_types::transaction::rooch::RoochTransaction;
use rpassword::prompt_password;

use crate::cli_types::{CommandAction, TransactionOptions, WalletContextOptions};
use framework_builder::Stdlib;
use move_core_types::{identifier::Identifier, language_storage::ModuleId};
use moveos_types::addresses::{MOVEOS_STD_ADDRESS, MOVE_STD_ADDRESS};
use moveos_types::{move_types::FunctionId, transaction::MoveAction};
use rooch_key::key_derive::verify_password;
use rooch_key::keystore::account_keystore::AccountKeystore;
use rooch_rpc_api::jsonrpc_types::ExecuteTransactionResponseView;
use rooch_types::addresses::{BITCOIN_MOVE_ADDRESS, ROOCH_FRAMEWORK_ADDRESS};
use rooch_types::error::{RoochError, RoochResult};
use rooch_types::transaction::rooch::RoochTransaction;
use rpassword::prompt_password;
use std::collections::HashMap;
use std::path::PathBuf;

Expand Down
Binary file modified frameworks/framework-release/released/1/stdlib
Binary file not shown.
3 changes: 1 addition & 2 deletions frameworks/rooch-framework/doc/transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
- [Function `transfer_object`](#0x3_transfer_transfer_object)


<pre><code><b>use</b> <a href="">0x1::option</a>;
<b>use</b> <a href="">0x2::account</a>;
<pre><code><b>use</b> <a href="">0x2::account</a>;
<b>use</b> <a href="">0x2::object</a>;
<b>use</b> <a href="account.md#0x3_account">0x3::account</a>;
<b>use</b> <a href="account_coin_store.md#0x3_account_coin_store">0x3::account_coin_store</a>;
Expand Down
18 changes: 9 additions & 9 deletions frameworks/rooch-framework/sources/transfer.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

module rooch_framework::transfer {
use std::option;
use moveos_std::object::ObjectID;

use moveos_std::object;
use moveos_std::account;
use rooch_framework::account as account_entry;
Expand All @@ -17,30 +15,32 @@ module rooch_framework::transfer {
/// Transfer `amount` of coins `CoinType` from `from` to `to`.
/// This public entry function requires the `CoinType` to have `key` and `store` abilities.
public entry fun transfer_coin<CoinType: key + store>(

from: &signer,
to: address,
amount: u256,
) {
assert!(account::exists_at(to), ErrorAccountNotExists);
//assert!(account::exists_at(to), ErrorAccountNotExists);
//We auto create account if not exists temporarily for testing
//We can remove auto create account after https://github.com/rooch-network/rooch/issues/1669
if(!account::exists_at(to)) {
account_entry::create_account(to);
};
account_coin_store::transfer<CoinType>(from, to, amount)
}

/// Transfer `amount` of coins `CoinType` from `from` to a MultiChainAddress.
/// The MultiChainAddress is represented by `multichain_id` and `raw_address`.
/// This public entry function requires the `CoinType` to have `key` and `store` abilities.
public entry fun transfer_coin_to_multichain_address<CoinType: key + store>(

from: &signer,
multichain_id: u64,
raw_address: vector<u8>,
amount: u256,
) {
let maddress = multichain_address::new(multichain_id, raw_address);
let to = address_mapping::resolve(maddress);
assert!(option::is_some(&to), ErrorAccountNotExists);

let to = option::extract(&mut to);
let to = address_mapping::resolve_or_generate(maddress);
//We auto create account if not exists temporarily for testing
//We can remove auto create account after https://github.com/rooch-network/rooch/issues/1669
if(!account::exists_at(to)) {
account_entry::create_account(to);
};
Expand Down
18 changes: 18 additions & 0 deletions moveos/moveos-object-runtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,24 @@ impl ObjectRuntime {

module_field.move_to(runtime_field_value, value_layout, value_type)?;

if !is_republishing {
// If we directly publish module in Rust, not in Move, we need to increase the size of module store
// TODO we need to find a better way to handle this
let module_store_obj_value = module_store_obj.value.move_from()?;
let mut module_store_obj_entity = ObjectEntity::<ModuleStore>::from_runtime_value(
module_store_obj_value,
)
.map_err(|e| {
PartialVMError::new(StatusCode::TYPE_MISMATCH)
.with_message(format!("expect ObjectEntity<ModuleStore>, but got {:?}", e))
})?;
module_store_obj_entity.size += 1;
let module_store_obj_value = module_store_obj_entity.to_runtime_value();
module_store_obj
.value
.move_to(module_store_obj_value)
.map_err(|(e, _)| e)?;
}
Ok(())
}

Expand Down
Loading