Skip to content

Commit

Permalink
[Framework] Config reorg blocks and release framework v10 (#2630)
Browse files Browse the repository at this point in the history
* simplify revert-tx

* provide reorg blocks update function

* reuse has_upgrade_permission by change private to public

* release framework v10

* release framework v10
  • Loading branch information
baichuan3 authored Sep 14, 2024
1 parent fa57474 commit 4f6dc10
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 19 deletions.
11 changes: 0 additions & 11 deletions crates/rooch-types/src/indexer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ pub fn handle_object_change(

pub fn handle_revert_object_change(
state_index_generator: &mut IndexerObjectStatesIndexGenerator,
// revert_state_index_generator: &mut IndexerObjectStatesIndexGenerator,
tx_order: u64,
indexer_object_state_change_set: &mut IndexerObjectStateChangeSet,
object_change: ObjectChange,
Expand Down Expand Up @@ -226,11 +225,8 @@ pub fn handle_revert_object_change(
);
indexer_object_state_change_set.update_object_states(state);
}
// let state = IndexerObjectState::new(metadata.clone(), tx_order, state_index);
// indexer_object_state_change_set.update_object_states(state);
}
Op::Delete => {
// indexer_object_state_change_set.remove_object_states(object_id, &object_type);
// Use the reverted tx_order and state index as the deleted restored tx_order and tx_order
if let Some(previous_object_meta) = object_mapping.get(&object_id) {
let state = IndexerObjectState::new(
Expand All @@ -242,16 +238,9 @@ pub fn handle_revert_object_change(
}
}
Op::New(_value) => {
// let state = IndexerObjectState::new(metadata.clone(), tx_order, state_index);
// indexer_object_state_change_set.new_object_states(state);

indexer_object_state_change_set.remove_object_states(object_id, &object_type);
}
}
} else {
//If value is not changed, do nothing.
// let state = IndexerObjectState::new(metadata.clone(), tx_order, state_index);
// indexer_object_state_change_set.update_object_states(state);
}

state_index_generator.incr(&object_type);
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch/src/commands/db/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rooch_types::rooch_network::RoochChainID;
use std::path::PathBuf;
use std::time::SystemTime;

pub mod revert_tx;
pub mod revert;
pub mod rollback;

fn init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::commands::db::commands::init;

/// Revert tx by db command.
#[derive(Debug, Parser)]
pub struct RevertTxCommand {
pub struct RevertCommand {
#[clap(long, short = 'o')]
/// tx order
pub tx_order: u64,
Expand All @@ -31,7 +31,7 @@ pub struct RevertTxCommand {
pub context_options: WalletContextOptions,
}

impl RevertTxCommand {
impl RevertCommand {
pub async fn execute(self) -> RoochResult<()> {
let tx_order = self.tx_order;
let (_root, rooch_db, _start_time) = init(self.base_data_dir, self.chain_id);
Expand Down
6 changes: 3 additions & 3 deletions crates/rooch/src/commands/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::cli_types::CommandAction;
use crate::commands::db::commands::revert_tx::RevertTxCommand;
use crate::commands::db::commands::revert::RevertCommand;
use async_trait::async_trait;
use clap::Parser;
use commands::rollback::RollbackCommand;
Expand All @@ -21,7 +21,7 @@ pub struct DB {
impl CommandAction<String> for DB {
async fn execute(self) -> RoochResult<String> {
match self.cmd {
DBCommand::RevertTx(revert_tx) => revert_tx.execute().await.map(|resp| {
DBCommand::Revert(revert) => revert.execute().await.map(|resp| {
serde_json::to_string_pretty(&resp).expect("Failed to serialize response")
}),
DBCommand::Rollback(rollback) => rollback.execute().await.map(|resp| {
Expand All @@ -34,6 +34,6 @@ impl CommandAction<String> for DB {
#[derive(clap::Subcommand)]
#[clap(name = "db")]
pub enum DBCommand {
RevertTx(RevertTxCommand),
Revert(RevertCommand),
Rollback(RollbackCommand),
}
15 changes: 15 additions & 0 deletions frameworks/bitcoin-move/doc/pending_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ PendingStore is used to store the pending blocks and txs, and handle the reorg
- [Function `get_ready_pending_txs`](#0x4_pending_block_get_ready_pending_txs)
- [Function `get_best_block`](#0x4_pending_block_get_best_block)
- [Function `get_reorg_block_count`](#0x4_pending_block_get_reorg_block_count)
- [Function `update_reorg_block_count`](#0x4_pending_block_update_reorg_block_count)
- [Function `update_reorg_block_count_for_local`](#0x4_pending_block_update_reorg_block_count_for_local)


<pre><code><b>use</b> <a href="">0x1::option</a>;
<b>use</b> <a href="">0x1::string</a>;
<b>use</b> <a href="">0x1::vector</a>;
<b>use</b> <a href="">0x2::event</a>;
<b>use</b> <a href="">0x2::module_store</a>;
<b>use</b> <a href="">0x2::object</a>;
<b>use</b> <a href="">0x2::signer</a>;
<b>use</b> <a href="">0x2::simple_map</a>;
<b>use</b> <a href="">0x2::type_info</a>;
<b>use</b> <a href="">0x3::chain_id</a>;
Expand Down Expand Up @@ -356,6 +359,18 @@ Get the pending txs which are ready to be processed



<a name="0x4_pending_block_update_reorg_block_count"></a>

## Function `update_reorg_block_count`

Update the <code>reorg_block_count</code> config


<pre><code><b>public</b> entry <b>fun</b> <a href="pending_block.md#0x4_pending_block_update_reorg_block_count">update_reorg_block_count</a>(<a href="">signer</a>: &<a href="">signer</a>, count: u64)
</code></pre>



<a name="0x4_pending_block_update_reorg_block_count_for_local"></a>

## Function `update_reorg_block_count_for_local`
Expand Down
15 changes: 14 additions & 1 deletion frameworks/bitcoin-move/sources/pending_block.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ module bitcoin_move::pending_block{

use std::vector;
use std::option::{Self, Option};

use moveos_std::signer;
use moveos_std::signer::module_signer;
use moveos_std::module_store::{ensure_upgrade_permission};

use moveos_std::object::{Self, Object, ObjectID};
use moveos_std::simple_map::{Self, SimpleMap};
use moveos_std::event;
Expand Down Expand Up @@ -328,6 +331,16 @@ module bitcoin_move::pending_block{

//====== Update functions ======

/// Update the `reorg_block_count` config
public entry fun update_reorg_block_count(signer: &signer, count: u64){
let module_signer = module_signer<PendingStore>();
let package_id = signer::address_of(&module_signer);
ensure_upgrade_permission(package_id, signer);

let store = borrow_mut_store();
store.reorg_block_count = count;
}

/// Update the `reorg_block_count` config for local env to testing
public entry fun update_reorg_block_count_for_local(count: u64){
assert!(rooch_framework::chain_id::is_local(), ErrorUnsupportedChain);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frameworks/framework-release/released/10/stdlib
Binary file not shown.
26 changes: 26 additions & 0 deletions frameworks/moveos-stdlib/doc/module_store.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
- [Function `add_to_allowlist`](#0x2_module_store_add_to_allowlist)
- [Function `remove_from_allowlist`](#0x2_module_store_remove_from_allowlist)
- [Function `is_in_allowlist`](#0x2_module_store_is_in_allowlist)
- [Function `has_upgrade_permission`](#0x2_module_store_has_upgrade_permission)
- [Function `ensure_upgrade_permission`](#0x2_module_store_ensure_upgrade_permission)


<pre><code><b>use</b> <a href="">0x1::string</a>;
Expand Down Expand Up @@ -358,3 +360,27 @@ Check if a package id is in the allowlist.

<pre><code><b>public</b> <b>fun</b> <a href="module_store.md#0x2_module_store_is_in_allowlist">is_in_allowlist</a>(package_id: <b>address</b>): bool
</code></pre>



<a name="0x2_module_store_has_upgrade_permission"></a>

## Function `has_upgrade_permission`

Check if the account has the permission to upgrade the package with the package_id.


<pre><code><b>public</b> <b>fun</b> <a href="module_store.md#0x2_module_store_has_upgrade_permission">has_upgrade_permission</a>(package_id: <b>address</b>, <a href="account.md#0x2_account">account</a>: <b>address</b>): bool
</code></pre>



<a name="0x2_module_store_ensure_upgrade_permission"></a>

## Function `ensure_upgrade_permission`

Ensure the account has the permission to upgrade the package with the package_id.


<pre><code><b>public</b> <b>fun</b> <a href="module_store.md#0x2_module_store_ensure_upgrade_permission">ensure_upgrade_permission</a>(package_id: <b>address</b>, <a href="account.md#0x2_account">account</a>: &<a href="">signer</a>)
</code></pre>
8 changes: 7 additions & 1 deletion frameworks/moveos-stdlib/sources/module_store.move
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ module moveos_std::module_store {
}

/// Check if the account has the permission to upgrade the package with the package_id.
fun has_upgrade_permission(package_id: address, account: address): bool {
public fun has_upgrade_permission(package_id: address, account: address): bool {
let id = object::account_named_object_id<UpgradeCap>(package_id);
if (!object::exists_object(id)) {
return false
Expand All @@ -328,6 +328,12 @@ module moveos_std::module_store {
object::owner(cap) == account
}

/// Ensure the account has the permission to upgrade the package with the package_id.
public fun ensure_upgrade_permission(package_id: address, account: &signer) {
let has_permission = Self::has_upgrade_permission(package_id, signer::address_of(account));
assert!(has_permission, ErrorNoUpgradePermission)
}

//The following is the bytes and hex of the compiled module: example/counter/sources/counter.move with account 0x42
// Run the follow commands to get the bytecode of the module
//./target/debug/rooch move build -p examples/counter -d
Expand Down

0 comments on commit 4f6dc10

Please sign in to comment.