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

[Framework] Config reorg blocks and release framework v10 #2630

Merged
merged 5 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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),
}
24 changes: 24 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 @@ -115,6 +118,15 @@ This is a hot potato struct, can not be store and drop



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



<pre><code><b>const</b> <a href="pending_block.md#0x4_pending_block_ErrorHasNoPermission">ErrorHasNoPermission</a>: u64 = 8;
</code></pre>



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


Expand Down Expand Up @@ -356,6 +368,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
16 changes: 15 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::has_upgrade_permission;

use moveos_std::object::{Self, Object, ObjectID};
use moveos_std::simple_map::{Self, SimpleMap};
use moveos_std::event;
Expand All @@ -25,6 +28,7 @@ module bitcoin_move::pending_block{
const ErrorNeedToWaitMoreBlocks:u64 = 5;
const ErrorPendingBlockNotFinished:u64 = 6;
const ErrorUnsupportedChain:u64 = 7;
const ErrorHasNoPermission:u64 = 8;

const TX_IDS_KEY: vector<u8> = b"tx_ids";

Expand Down Expand Up @@ -328,6 +332,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);
assert!(has_upgrade_permission(package_id, signer::address_of(signer)), ErrorHasNoPermission);

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 not shown.
13 changes: 13 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,7 @@
- [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)


<pre><code><b>use</b> <a href="">0x1::string</a>;
Expand Down Expand Up @@ -358,3 +359,15 @@ 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>
2 changes: 1 addition & 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 Down
Loading