From 756d0645f54bd9ac5e3f44a54c77bf2a48a23ade Mon Sep 17 00:00:00 2001 From: Bai Chuan Date: Tue, 30 Apr 2024 22:11:23 +0800 Subject: [PATCH] [Bitcoin] Eliminate data import mode (#1645) * eliminate data import mode * fixup data import flag define * fixup need process ordinals flag * fixup need process ordinals flag * fixup fmt --- Cargo.lock | 1 + crates/rooch-benchmarks/README.md | 2 +- crates/rooch-benchmarks/config/bench_tx.toml | 2 +- crates/rooch-benchmarks/src/config.rs | 8 +- crates/rooch-benchmarks/src/tx.rs | 5 +- crates/rooch-benchmarks/src/tx_exec.rs | 4 +- crates/rooch-config/src/lib.rs | 8 +- .../rooch-framework-tests/src/binding_test.rs | 8 +- crates/rooch-genesis/src/lib.rs | 12 +- crates/rooch-rpc-server/src/lib.rs | 14 +- .../src/bitcoin/data_import_config.rs | 117 ------------ crates/rooch-types/src/bitcoin/genesis.rs | 10 +- .../rooch-types/src/bitcoin/light_client.rs | 2 +- crates/rooch-types/src/bitcoin/mod.rs | 1 - crates/rooch-types/src/bitcoin/network.rs | 2 +- crates/rooch/Cargo.toml | 1 + .../commands/statedb/commands/genesis_utxo.rs | 19 +- crates/testsuite/tests/integration.rs | 4 +- frameworks/bitcoin-move/doc/README.md | 1 - .../bitcoin-move/doc/data_import_config.md | 178 ------------------ frameworks/bitcoin-move/doc/genesis.md | 1 - frameworks/bitcoin-move/doc/light_client.md | 23 ++- .../sources/data_import_config.move | 63 ------- frameworks/bitcoin-move/sources/genesis.move | 5 +- .../bitcoin-move/sources/light_client.move | 32 ++-- 25 files changed, 83 insertions(+), 440 deletions(-) delete mode 100644 crates/rooch-types/src/bitcoin/data_import_config.rs delete mode 100644 frameworks/bitcoin-move/doc/data_import_config.md delete mode 100644 frameworks/bitcoin-move/sources/data_import_config.move diff --git a/Cargo.lock b/Cargo.lock index 274e1df24b..a08d0aa667 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8442,6 +8442,7 @@ dependencies = [ "framework-builder", "hex", "itertools 0.10.5", + "log", "move-binary-format", "move-bytecode-utils", "move-bytecode-verifier", diff --git a/crates/rooch-benchmarks/README.md b/crates/rooch-benchmarks/README.md index ffb96af609..a5a5ab8cff 100644 --- a/crates/rooch-benchmarks/README.md +++ b/crates/rooch-benchmarks/README.md @@ -44,7 +44,7 @@ is `rooch-benchmarks/config/bench_tx.toml`. pub struct BenchTxConfig { pub tx_type: Option, // empty(default)/transfer/btc-block - pub data_import_mode: Option, + pub data_import_flag: bool, // utxo(default)/ord/none/full pub btc_block_dir: Option, // btc block dir, file name: .hex diff --git a/crates/rooch-benchmarks/config/bench_tx.toml b/crates/rooch-benchmarks/config/bench_tx.toml index ee4b8d8372..732f8911f3 100644 --- a/crates/rooch-benchmarks/config/bench_tx.toml +++ b/crates/rooch-benchmarks/config/bench_tx.toml @@ -1,5 +1,5 @@ tx_type = "empty" pprof_output = "flamegraph" # when tx_type is "btc-block", the following two options are required -data_import_mode = "utxo" +data_import_flag = true btc_block_dir = "/home/rooch/btc/blk" \ No newline at end of file diff --git a/crates/rooch-benchmarks/src/config.rs b/crates/rooch-benchmarks/src/config.rs index 904640c674..54edc49363 100644 --- a/crates/rooch-benchmarks/src/config.rs +++ b/crates/rooch-benchmarks/src/config.rs @@ -12,8 +12,6 @@ use lazy_static::lazy_static; use pprof::criterion::{Output, PProfProfiler}; use serde::{Deserialize, Serialize}; -use rooch_types::bitcoin::data_import_config::DataImportMode; - lazy_static! { static ref BENCH_TX_CONFIG_PATH: String = std::env::var("ROOCH_BENCH_TX_CONFIG_PATH") .unwrap_or_else(|_| String::from("config/bench_tx.toml")); @@ -80,7 +78,7 @@ impl Display for TxType { #[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Parser, Eq)] pub struct BenchTxConfig { pub tx_type: Option, // empty(default)/transfer/btc-block - pub data_import_mode: Option, // utxo(default)/ord/none/full + pub data_import_flag: bool, pub btc_block_dir: Option, // btc block dir, file name: .hex pub pprof_output: Option, // flamegraph(default)/proto } @@ -89,7 +87,7 @@ impl Default for BenchTxConfig { fn default() -> Self { Self { tx_type: Some(TxType::Empty), - data_import_mode: Some(DataImportMode::UTXO), + data_import_flag: false, btc_block_dir: None, pprof_output: Some(PProfOutput::Flamegraph), } @@ -99,7 +97,7 @@ impl Default for BenchTxConfig { impl BenchTxConfig { pub fn adjust(&mut self) { self.tx_type.get_or_insert(TxType::Empty); - self.data_import_mode.get_or_insert(DataImportMode::UTXO); + self.data_import_flag = false; // if tx_type is btc_block, btc_block_dir must be existed, if not, panic if self.tx_type == Some(TxType::BtcBlock) { self.btc_block_dir diff --git a/crates/rooch-benchmarks/src/tx.rs b/crates/rooch-benchmarks/src/tx.rs index 9a608846fd..03ab575298 100644 --- a/crates/rooch-benchmarks/src/tx.rs +++ b/crates/rooch-benchmarks/src/tx.rs @@ -49,7 +49,6 @@ use rooch_sequencer::proxy::SequencerProxy; use rooch_store::RoochStore; use rooch_test_transaction_builder::TestTransactionBuilder; use rooch_types::address::RoochAddress; -use rooch_types::bitcoin::data_import_config::DataImportMode; use rooch_types::bitcoin::genesis::BitcoinGenesisContext; use rooch_types::bitcoin::network::Network; use rooch_types::chain_id::RoochChainID; @@ -100,10 +99,10 @@ pub async fn setup_service( // Init executor let btc_network = Network::default().to_num(); - let data_import_mode = DataImportMode::default().to_num(); + let _data_import_flag = false; let genesis_ctx = chain_id.genesis_ctx(rooch_account); - let bitcoin_genesis_ctx = BitcoinGenesisContext::new(btc_network, data_import_mode); + let bitcoin_genesis_ctx = BitcoinGenesisContext::new(btc_network); let genesis: RoochGenesis = RoochGenesis::build(genesis_ctx, bitcoin_genesis_ctx)?; let root = genesis.init_genesis(&mut moveos_store)?; diff --git a/crates/rooch-benchmarks/src/tx_exec.rs b/crates/rooch-benchmarks/src/tx_exec.rs index 5c8033f7a5..b2804b8196 100644 --- a/crates/rooch-benchmarks/src/tx_exec.rs +++ b/crates/rooch-benchmarks/src/tx_exec.rs @@ -16,9 +16,7 @@ use crate::tx::{create_btc_blk_tx, create_l2_tx, find_block_height}; pub fn tx_exec_benchmark(c: &mut Criterion) { let config = BenchTxConfig::load(); - let mut binding_test = - binding_test::RustBindingTest::new_with_mode(config.data_import_mode.unwrap().to_num()) - .unwrap(); + let mut binding_test = binding_test::RustBindingTest::new().unwrap(); let keystore = InMemKeystore::new_insecure_for_tests(10); let default_account = keystore.addresses()[0]; let mut test_transaction_builder = TestTransactionBuilder::new(default_account.into()); diff --git a/crates/rooch-config/src/lib.rs b/crates/rooch-config/src/lib.rs index ced8a81553..ce2ad6dedb 100644 --- a/crates/rooch-config/src/lib.rs +++ b/crates/rooch-config/src/lib.rs @@ -13,7 +13,6 @@ use rand::Rng; use serde::{Deserialize, Serialize}; use moveos_config::{temp_dir, DataDirPath}; -use rooch_types::bitcoin::data_import_config::DataImportMode; use rooch_types::bitcoin::network::Network; use rooch_types::chain_id::RoochChainID; use rooch_types::crypto::RoochKeyPair; @@ -142,10 +141,9 @@ pub struct RoochOpt { #[clap(long)] pub da: Option, - #[serde(skip_serializing_if = "Option::is_none")] #[clap(long)] - /// The data import mode. If true, may be ignore the indexer write - pub data_import_mode: Option, + /// The data import flag. If true, may be ignore the indexer write + pub data_import_flag: bool, } impl std::fmt::Display for RoochOpt { @@ -180,7 +178,7 @@ impl RoochOpt { proposer_account: None, relayer_account: None, da: None, - data_import_mode: Some(DataImportMode::default().to_num()), + data_import_flag: false, } } diff --git a/crates/rooch-framework-tests/src/binding_test.rs b/crates/rooch-framework-tests/src/binding_test.rs index 9692de1a3e..7cddd92c7c 100644 --- a/crates/rooch-framework-tests/src/binding_test.rs +++ b/crates/rooch-framework-tests/src/binding_test.rs @@ -19,7 +19,6 @@ use rooch_executor::actor::{executor::ExecutorActor, messages::ExecuteTransactio use rooch_genesis::RoochGenesis; use rooch_store::RoochStore; use rooch_types::address::RoochAddress; -use rooch_types::bitcoin::data_import_config::DataImportMode; use rooch_types::bitcoin::genesis::BitcoinGenesisContext; use rooch_types::bitcoin::network::Network; use rooch_types::chain_id::RoochChainID; @@ -52,10 +51,6 @@ pub struct RustBindingTest { impl RustBindingTest { pub fn new() -> Result { - Self::new_with_mode(DataImportMode::Ord.to_num()) - } - - pub fn new_with_mode(data_import_mode: u8) -> Result { let data_dir = get_data_dir(); let (rooch_db_path, moveos_db_path) = ( StoreConfig::get_mock_moveos_store_dir(&data_dir), @@ -75,7 +70,8 @@ impl RustBindingTest { let genesis = RoochGenesis::build( RoochChainID::LOCAL.genesis_ctx(sequencer), - BitcoinGenesisContext::new(Network::default().to_num(), data_import_mode), + BitcoinGenesisContext::new(Network::NetworkTestnet.to_num()), + // BitcoinGenesisContext::new(Network::default().to_num()), )?; let root = genesis.init_genesis(&mut moveos_store)?; diff --git a/crates/rooch-genesis/src/lib.rs b/crates/rooch-genesis/src/lib.rs index 588a4c54e7..05f9f00d30 100644 --- a/crates/rooch-genesis/src/lib.rs +++ b/crates/rooch-genesis/src/lib.rs @@ -20,7 +20,6 @@ use rooch_framework::natives::gas_parameter::gas_member::{ FromOnChainGasSchedule, InitialGasSchedule, ToOnChainGasSchedule, }; use rooch_framework::ROOCH_FRAMEWORK_ADDRESS; -use rooch_types::bitcoin::data_import_config::DataImportMode; use rooch_types::bitcoin::genesis::BitcoinGenesisContext; use rooch_types::bitcoin::network::Network; use rooch_types::error::GenesisError; @@ -43,10 +42,7 @@ pub static ROOCH_LOCAL_GENESIS: Lazy = Lazy::new(|| { let mock_sequencer = RoochAddress::from_str("0x0").expect("parse sequencer address failed"); // genesis for integration test, we need to build the stdlib every time for `private_generic` check // see moveos/moveos-verifier/src/metadata.rs#L27-L30 - let bitcoin_genesis_ctx = BitcoinGenesisContext::new( - Network::NetworkRegtest.to_num(), - DataImportMode::None.to_num(), - ); + let bitcoin_genesis_ctx = BitcoinGenesisContext::new(Network::NetworkRegtest.to_num()); RoochGenesis::build_with_option( RoochChainID::LOCAL.genesis_ctx(mock_sequencer), bitcoin_genesis_ctx, @@ -338,7 +334,6 @@ mod tests { use moveos_store::MoveOSStore; use moveos_types::moveos_std::move_module::ModuleStore; use moveos_types::state_resolver::{RootObjectResolver, StateResolver}; - use rooch_types::bitcoin::data_import_config::DataImportMode; use rooch_types::bitcoin::genesis::BitcoinGenesisContext; use rooch_types::bitcoin::network::{BitcoinNetwork, Network}; use rooch_types::chain_id::{BuiltinChainID, RoochChainID}; @@ -349,10 +344,7 @@ mod tests { fn test_genesis_init() { let _ = tracing_subscriber::fmt::try_init(); let sequencer = AccountAddress::ONE.into(); - let bitcoin_genesis_ctx = BitcoinGenesisContext::new( - Network::NetworkRegtest.to_num(), - DataImportMode::None.to_num(), - ); + let bitcoin_genesis_ctx = BitcoinGenesisContext::new(Network::NetworkRegtest.to_num()); let genesis = super::RoochGenesis::build_with_option( RoochChainID::LOCAL.genesis_ctx(sequencer), bitcoin_genesis_ctx, diff --git a/crates/rooch-rpc-server/src/lib.rs b/crates/rooch-rpc-server/src/lib.rs index 4bd1d565d8..cd042dbac7 100644 --- a/crates/rooch-rpc-server/src/lib.rs +++ b/crates/rooch-rpc-server/src/lib.rs @@ -47,7 +47,6 @@ use rooch_sequencer::actor::sequencer::SequencerActor; use rooch_sequencer::proxy::SequencerProxy; use rooch_store::RoochStore; use rooch_types::address::RoochAddress; -use rooch_types::bitcoin::data_import_config::DataImportMode; use rooch_types::bitcoin::genesis::BitcoinGenesisContext; use rooch_types::bitcoin::network::Network; use rooch_types::crypto::RoochKeyPair; @@ -219,22 +218,17 @@ pub async fn run_start_server(opt: &RoochOpt, mut server_opt: ServerOpt) -> Resu let sequencer_account: RoochAddress = (&sequencer_keypair.public()).into(); let btc_network = opt.btc_network.unwrap_or(Network::default().to_num()); - let data_import_mode = DataImportMode::try_from( - opt.data_import_mode - .unwrap_or(DataImportMode::None.to_num()), - )?; + let data_import_flag = opt.data_import_flag; if root.is_genesis() { let genesis_ctx = chain_id_opt.genesis_ctx(sequencer_account); - let bitcoin_genesis_ctx = - BitcoinGenesisContext::new(btc_network, data_import_mode.to_num()); + let bitcoin_genesis_ctx = BitcoinGenesisContext::new(btc_network); let genesis: RoochGenesis = RoochGenesis::build(genesis_ctx, bitcoin_genesis_ctx)?; root = genesis.init_genesis(&mut moveos_store)?; } else { //TODO if root is not genesis, we should load genesis from store let genesis_ctx = chain_id_opt.genesis_ctx(sequencer_account); - let bitcoin_genesis_ctx = - BitcoinGenesisContext::new(btc_network, data_import_mode.to_num()); + let bitcoin_genesis_ctx = BitcoinGenesisContext::new(btc_network); let genesis: RoochGenesis = RoochGenesis::build(genesis_ctx, bitcoin_genesis_ctx)?; genesis.check_genesis(moveos_store.get_config_store())?; }; @@ -301,7 +295,7 @@ pub async fn run_start_server(opt: &RoochOpt, mut server_opt: ServerOpt) -> Resu sequencer_proxy.clone(), proposer_proxy.clone(), indexer_proxy.clone(), - data_import_mode.is_data_import_flag(), + data_import_flag, ) .into_actor(Some("PipelineProcessor"), &actor_system) .await?; diff --git a/crates/rooch-types/src/bitcoin/data_import_config.rs b/crates/rooch-types/src/bitcoin/data_import_config.rs deleted file mode 100644 index d5e4eba182..0000000000 --- a/crates/rooch-types/src/bitcoin/data_import_config.rs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) RoochNetwork -// SPDX-License-Identifier: Apache-2.0 - -use crate::addresses::BITCOIN_MOVE_ADDRESS; -use move_core_types::{ident_str, identifier::IdentStr}; -use moveos_types::moveos_std::object; -use moveos_types::moveos_std::object::ObjectID; -use moveos_types::state::{MoveStructState, MoveStructType}; -#[cfg(any(test, feature = "fuzzing"))] -use proptest_derive::Arbitrary; -use serde::{Deserialize, Serialize}; -use std::str::FromStr; - -pub const MODULE_NAME: &IdentStr = ident_str!("data_import_config"); - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))] -#[repr(u8)] -#[serde(rename_all = "lowercase")] -pub enum DataImportMode { - None = 0, - UTXO = 1, - Ord = 2, - // Full mode will process full data and indexer - Full = 10, -} - -impl TryFrom for DataImportMode { - type Error = anyhow::Error; - - fn try_from(value: u8) -> Result { - match value { - 0 => Ok(DataImportMode::None), - 1 => Ok(DataImportMode::UTXO), - 2 => Ok(DataImportMode::Ord), - 10 => Ok(DataImportMode::Full), - _ => Err(anyhow::anyhow!( - "Bitcoin data import mode {} is invalid", - value - )), - } - } -} - -impl FromStr for DataImportMode { - type Err = anyhow::Error; - fn from_str(s: &str) -> Result { - match s { - "utxo mode" => Ok(DataImportMode::UTXO), - "ord mode" => Ok(DataImportMode::Ord), - "none mode" => Ok(DataImportMode::None), - _ => Err(anyhow::anyhow!("Invalid bitcoin data import mode {}", s)), - } - } -} - -impl std::fmt::Display for DataImportMode { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - DataImportMode::None => write!(f, "none mode"), - DataImportMode::UTXO => write!(f, "utxo mode"), - DataImportMode::Ord => write!(f, "ord mode"), - DataImportMode::Full => write!(f, "full mode"), - } - } -} - -impl DataImportMode { - pub fn to_num(self) -> u8 { - self as u8 - } - - pub fn is_ord_mode(&self) -> bool { - *self == DataImportMode::Ord || *self == DataImportMode::Full - } - - pub fn is_full_mode(&self) -> bool { - *self == DataImportMode::Full - } - - pub fn is_data_import_flag(&self) -> bool { - *self == DataImportMode::UTXO || *self == DataImportMode::Ord - } -} - -impl Default for DataImportMode { - // default bitcoin none modes - fn default() -> Self { - Self::None - } -} - -/// The Bitcoin data import mode onchain configuration. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct DataImportConfig { - pub data_import_mode: u8, -} - -impl MoveStructType for DataImportConfig { - const ADDRESS: move_core_types::account_address::AccountAddress = BITCOIN_MOVE_ADDRESS; - const MODULE_NAME: &'static IdentStr = MODULE_NAME; - const STRUCT_NAME: &'static IdentStr = ident_str!("DataImportConfig"); -} - -impl MoveStructState for DataImportConfig { - fn struct_layout() -> move_core_types::value::MoveStructLayout { - move_core_types::value::MoveStructLayout::new(vec![ - move_core_types::value::MoveTypeLayout::U8, - ]) - } -} - -impl DataImportConfig { - pub fn object_id() -> ObjectID { - object::named_object_id(&Self::struct_tag()) - } -} diff --git a/crates/rooch-types/src/bitcoin/genesis.rs b/crates/rooch-types/src/bitcoin/genesis.rs index cdbcf8e9fb..6b395594d2 100644 --- a/crates/rooch-types/src/bitcoin/genesis.rs +++ b/crates/rooch-types/src/bitcoin/genesis.rs @@ -12,8 +12,6 @@ pub const MODULE_NAME: &IdentStr = ident_str!("genesis"); pub struct BitcoinGenesisContext { /// The bitcoin network pub network: u8, - /// The bitcoin data import mode. 1 include UTXOs, 2 include UTXOs + Ord data. - pub data_import_mode: u8, } impl MoveStructType for BitcoinGenesisContext { @@ -26,16 +24,12 @@ impl MoveStructState for BitcoinGenesisContext { fn struct_layout() -> move_core_types::value::MoveStructLayout { move_core_types::value::MoveStructLayout::new(vec![ move_core_types::value::MoveTypeLayout::U8, - move_core_types::value::MoveTypeLayout::U8, ]) } } impl BitcoinGenesisContext { - pub fn new(network: u8, data_import_mode: u8) -> Self { - Self { - network, - data_import_mode, - } + pub fn new(network: u8) -> Self { + Self { network } } } diff --git a/crates/rooch-types/src/bitcoin/light_client.rs b/crates/rooch-types/src/bitcoin/light_client.rs index 7b128c3b56..a8117957d0 100644 --- a/crates/rooch-types/src/bitcoin/light_client.rs +++ b/crates/rooch-types/src/bitcoin/light_client.rs @@ -72,7 +72,7 @@ impl<'a> BitcoinLightClientModule<'a> { pub const GET_UTXO_FUNCTION_NAME: &'static IdentStr = ident_str!("get_utxo"); pub const SUBMIT_NEW_BLOCK_ENTRY_FUNCTION_NAME: &'static IdentStr = ident_str!("submit_new_block"); - pub const PROCESS_UTXOS_ENTRY_FUNCTION_NAME: &'static IdentStr = ident_str!("process_utxos"); + // pub const PROCESS_UTXOS_ENTRY_FUNCTION_NAME: &'static IdentStr = ident_str!("process_utxos"); pub fn get_block(&self, block_hash: BlockHash) -> Result> { let call = Self::create_function_call( diff --git a/crates/rooch-types/src/bitcoin/mod.rs b/crates/rooch-types/src/bitcoin/mod.rs index 73974aa853..21daee5d2c 100644 --- a/crates/rooch-types/src/bitcoin/mod.rs +++ b/crates/rooch-types/src/bitcoin/mod.rs @@ -4,7 +4,6 @@ /// Types mapping from Bitcoin Move types to Rust types /// Module binding for the Framework pub mod brc20; -pub mod data_import_config; pub mod genesis; pub mod light_client; pub mod network; diff --git a/crates/rooch-types/src/bitcoin/network.rs b/crates/rooch-types/src/bitcoin/network.rs index ede61dced6..b9cdf55993 100644 --- a/crates/rooch-types/src/bitcoin/network.rs +++ b/crates/rooch-types/src/bitcoin/network.rs @@ -83,7 +83,7 @@ impl Network { } impl Default for Network { - // default bitcoin regtest network + // default bitcoin main network fn default() -> Self { Self::NetworkBitcoin } diff --git a/crates/rooch/Cargo.toml b/crates/rooch/Cargo.toml index 9c150a0194..87dd1f1d76 100644 --- a/crates/rooch/Cargo.toml +++ b/crates/rooch/Cargo.toml @@ -39,6 +39,7 @@ parking_lot = { workspace = true } bcs-ext = { workspace = true } rpassword = { workspace = true } fastcrypto = { workspace = true } +log = { workspace = true } move-bytecode-utils = { workspace = true } move-binary-format = { workspace = true } diff --git a/crates/rooch/src/commands/statedb/commands/genesis_utxo.rs b/crates/rooch/src/commands/statedb/commands/genesis_utxo.rs index 0711e065cd..66f394c78d 100644 --- a/crates/rooch/src/commands/statedb/commands/genesis_utxo.rs +++ b/crates/rooch/src/commands/statedb/commands/genesis_utxo.rs @@ -37,6 +37,7 @@ use std::io::{BufRead, BufReader}; use std::path::PathBuf; use std::str::FromStr; use std::time::SystemTime; +use tracing::log; pub const BATCH_SIZE: usize = 5000; pub const SCRIPT_TYPE_P2MS: &str = "p2ms"; @@ -188,9 +189,10 @@ impl GenesisUTXOCommand { utxo_datas.clone(), )?; utxo_datas.clear(); - println!( + log::debug!( "process_utxos pre_utxostore_state_root: {:?}, new_utxostore_state_root: {:?}", - pre_utxostore_state_root, new_utxostore_state_root + pre_utxostore_state_root, + new_utxostore_state_root ); println!("process_utxos utxo count: {}", utxo_count); pre_utxostore_state_root = new_utxostore_state_root; @@ -206,11 +208,11 @@ impl GenesisUTXOCommand { address_mapping_datas, &mut address_mapping_checker, )?; - println!( + log::debug!( "process_address_mappings pre_address_mapping_state_root: {:?}, new_address_mapping_state_root: {:?}", pre_address_mapping_state_root, new_address_mapping_state_root ); - println!( + log::debug!( "process_address_mappings pre_reverse_address_mapping_state_root: {:?}, new_reverse_address_mapping_state_root: {:?}", pre_reverse_address_mapping_state_root, new_reverse_address_mapping_state_root ); @@ -225,9 +227,10 @@ impl GenesisUTXOCommand { let (new_utxostore_state_root, address_mapping_datas) = Self::process_utxos(&moveos_store, pre_utxostore_state_root, utxo_datas.clone())?; utxo_datas.clear(); - println!( + log::debug!( "process_utxos pre_utxostore_state_root: {:?}, new_utxostore_state_root: {:?}", - pre_utxostore_state_root, new_utxostore_state_root + pre_utxostore_state_root, + new_utxostore_state_root ); println!("process_utxos utxo count: {}", utxo_count); pre_utxostore_state_root = new_utxostore_state_root; @@ -243,11 +246,11 @@ impl GenesisUTXOCommand { address_mapping_datas, &mut address_mapping_checker, )?; - println!( + log::debug!( "process_address_mappings pre_address_mapping_state_root: {:?}, new_address_mapping_state_root: {:?}", pre_address_mapping_state_root, new_address_mapping_state_root ); - println!( + log::debug!( "process_address_mappings pre_reverse_address_mapping_state_root: {:?}, new_reverse_address_mapping_state_root: {:?}", pre_reverse_address_mapping_state_root, new_reverse_address_mapping_state_root ); diff --git a/crates/testsuite/tests/integration.rs b/crates/testsuite/tests/integration.rs index d339f3cc0d..e3a73998e4 100644 --- a/crates/testsuite/tests/integration.rs +++ b/crates/testsuite/tests/integration.rs @@ -16,6 +16,7 @@ use tracing::{debug, error, info}; use images::bitcoin::BitcoinD; use images::ord::Ord; +use rooch_types::bitcoin::network::Network; use std::time::Duration; use testcontainers::{ clients::Cli, @@ -69,7 +70,8 @@ async fn start_server(w: &mut World, _scenario: String) { opt.btc_rpc_username = Some(RPC_USER.to_string()); opt.btc_rpc_password = Some(RPC_PASS.to_string()); opt.btc_start_block_height = Some(0); - opt.data_import_mode = Some(0); // Enable data import without writing indexes + opt.data_import_flag = false; // Enable data import without writing indexes + opt.btc_network = Some(Network::NetworkTestnet.to_num()); info!("config btc rpc ok"); w.bitcoind = Some(bitcoind); diff --git a/frameworks/bitcoin-move/doc/README.md b/frameworks/bitcoin-move/doc/README.md index ef594bcc35..4135160e4f 100644 --- a/frameworks/bitcoin-move/doc/README.md +++ b/frameworks/bitcoin-move/doc/README.md @@ -14,7 +14,6 @@ This is the reference documentation of the Bitcoin Move Framework. - [`0x4::bitseed`](bitseed.md#0x4_bitseed) - [`0x4::brc20`](brc20.md#0x4_brc20) -- [`0x4::data_import_config`](data_import_config.md#0x4_data_import_config) - [`0x4::genesis`](genesis.md#0x4_genesis) - [`0x4::light_client`](light_client.md#0x4_light_client) - [`0x4::network`](network.md#0x4_network) diff --git a/frameworks/bitcoin-move/doc/data_import_config.md b/frameworks/bitcoin-move/doc/data_import_config.md deleted file mode 100644 index 6f926162a5..0000000000 --- a/frameworks/bitcoin-move/doc/data_import_config.md +++ /dev/null @@ -1,178 +0,0 @@ - - - -# Module `0x4::data_import_config` - - - -- [Resource `DataImportConfig`](#0x4_data_import_config_DataImportConfig) -- [Constants](#@Constants_0) -- [Function `genesis_init`](#0x4_data_import_config_genesis_init) -- [Function `data_import_mode`](#0x4_data_import_config_data_import_mode) -- [Function `data_import_mode_none`](#0x4_data_import_config_data_import_mode_none) -- [Function `data_import_mode_utxo`](#0x4_data_import_config_data_import_mode_utxo) -- [Function `data_import_mode_ord`](#0x4_data_import_config_data_import_mode_ord) -- [Function `data_import_mode_full`](#0x4_data_import_config_data_import_mode_full) -- [Function `is_data_import_mode`](#0x4_data_import_config_is_data_import_mode) -- [Function `is_ord_mode`](#0x4_data_import_config_is_ord_mode) - - -
use 0x2::object;
-
- - - - - -## Resource `DataImportConfig` - -Bitcoin data import mode onchain configuration. - - -
struct DataImportConfig has key
-
- - - - - -## Constants - - - - -Bitcoin's full data import mode. -All mode will process full data and indexer - - -
const DATA_IMPORT_MODE_FULL: u8 = 10;
-
- - - - - -Currently, Move does not support enum types, so we use constants to represent the data import mode type. -Bitcoin's none data import mode. - - -
const DATA_IMPORT_MODE_NONE: u8 = 0;
-
- - - - - -Bitcoin's ord data import mode. - - -
const DATA_IMPORT_MODE_ORD: u8 = 2;
-
- - - - - -Bitcoin's utxo data import mode. - - -
const DATA_IMPORT_MODE_UTXO: u8 = 1;
-
- - - - - - - -
const ErrorUnknownDataImportMode: u64 = 1;
-
- - - - - -## Function `genesis_init` - - - -
public(friend) fun genesis_init(data_import_mode: u8)
-
- - - - - -## Function `data_import_mode` - -Get the current data import mode from the onchain configuration. - - -
public fun data_import_mode(): u8
-
- - - - - -## Function `data_import_mode_none` - - - -
public fun data_import_mode_none(): u8
-
- - - - - -## Function `data_import_mode_utxo` - - - -
public fun data_import_mode_utxo(): u8
-
- - - - - -## Function `data_import_mode_ord` - - - -
public fun data_import_mode_ord(): u8
-
- - - - - -## Function `data_import_mode_full` - - - -
public fun data_import_mode_full(): u8
-
- - - - - -## Function `is_data_import_mode` - - - -
public fun is_data_import_mode(data_import_mode: u8): bool
-
- - - - - -## Function `is_ord_mode` - - - -
public fun is_ord_mode(data_import_mode: u8): bool
-
diff --git a/frameworks/bitcoin-move/doc/genesis.md b/frameworks/bitcoin-move/doc/genesis.md index 2272219dc7..539158ac6d 100644 --- a/frameworks/bitcoin-move/doc/genesis.md +++ b/frameworks/bitcoin-move/doc/genesis.md @@ -13,7 +13,6 @@ use 0x2::signer; use 0x2::tx_context; use 0x4::brc20; -use 0x4::data_import_config; use 0x4::light_client; use 0x4::network; use 0x4::ord; diff --git a/frameworks/bitcoin-move/doc/light_client.md b/frameworks/bitcoin-move/doc/light_client.md index 0401da0bcb..36fc7f96f0 100644 --- a/frameworks/bitcoin-move/doc/light_client.md +++ b/frameworks/bitcoin-move/doc/light_client.md @@ -14,6 +14,7 @@ - [Function `get_block_height`](#0x4_light_client_get_block_height) - [Function `get_block_by_height`](#0x4_light_client_get_block_by_height) - [Function `get_latest_block_height`](#0x4_light_client_get_latest_block_height) +- [Function `need_process_oridinals`](#0x4_light_client_need_process_oridinals)
use 0x1::option;
@@ -28,7 +29,7 @@
 use 0x2::type_info;
 use 0x3::bitcoin_address;
 use 0x3::timestamp;
-use 0x4::data_import_config;
+use 0x4::network;
 use 0x4::ord;
 use 0x4::types;
 use 0x4::utxo;
@@ -81,6 +82,15 @@
 
 
 
+
+
+
+
+
const ORDINAL_GENESIS_HEIGHT: u64 = 767430;
+
+ + + ## Function `genesis_init` @@ -147,3 +157,14 @@ Get latest block height
public fun get_latest_block_height(): option::Option<u64>
 
+ + + + + +## Function `need_process_oridinals` + + + +
public fun need_process_oridinals(block_height: u64): bool
+
diff --git a/frameworks/bitcoin-move/sources/data_import_config.move b/frameworks/bitcoin-move/sources/data_import_config.move deleted file mode 100644 index c1acf3c533..0000000000 --- a/frameworks/bitcoin-move/sources/data_import_config.move +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) RoochNetwork -// SPDX-License-Identifier: Apache-2.0 - -// Copyright (c) RoochDataImportMode -// SPDX-License-Identifier: Apache-2.0 - -module bitcoin_move::data_import_config{ - use moveos_std::object; - - const ErrorUnknownDataImportMode: u64 = 1; - - friend bitcoin_move::genesis; - - /// Bitcoin data import mode onchain configuration. - struct DataImportConfig has key{ - data_import_mode: u8 - } - - public(friend) fun genesis_init(data_import_mode: u8){ - let obj = object::new_named_object(DataImportConfig{data_import_mode}); - object::to_shared(obj); - } - - /// Get the current data import mode from the onchain configuration. - public fun data_import_mode() : u8 { - let id = object::named_object_id(); - object::borrow(object::borrow_object(id)).data_import_mode - } - - /// Currently, Move does not support enum types, so we use constants to represent the data import mode type. - /// Bitcoin's none data import mode. - const DATA_IMPORT_MODE_NONE: u8 = 0; - public fun data_import_mode_none(): u8 { - DATA_IMPORT_MODE_NONE - } - - /// Bitcoin's utxo data import mode. - const DATA_IMPORT_MODE_UTXO: u8 = 1; - public fun data_import_mode_utxo(): u8 { - DATA_IMPORT_MODE_UTXO - } - - /// Bitcoin's ord data import mode. - const DATA_IMPORT_MODE_ORD: u8 = 2; - public fun data_import_mode_ord(): u8 { - DATA_IMPORT_MODE_ORD - } - - /// Bitcoin's full data import mode. - /// All mode will process full data and indexer - const DATA_IMPORT_MODE_FULL: u8 = 10; - public fun data_import_mode_full(): u8 { - DATA_IMPORT_MODE_FULL - } - - public fun is_data_import_mode(data_import_mode: u8): bool { - data_import_mode == DATA_IMPORT_MODE_UTXO || data_import_mode == DATA_IMPORT_MODE_ORD - } - - public fun is_ord_mode(data_import_mode: u8): bool { - data_import_mode == DATA_IMPORT_MODE_ORD || data_import_mode == DATA_IMPORT_MODE_FULL - } -} diff --git a/frameworks/bitcoin-move/sources/genesis.move b/frameworks/bitcoin-move/sources/genesis.move index 83bff14e5e..9bc1965d80 100644 --- a/frameworks/bitcoin-move/sources/genesis.move +++ b/frameworks/bitcoin-move/sources/genesis.move @@ -3,7 +3,6 @@ module bitcoin_move::genesis{ use std::option; - use bitcoin_move::data_import_config; use moveos_std::tx_context; use moveos_std::signer; use bitcoin_move::light_client; @@ -17,7 +16,6 @@ module bitcoin_move::genesis{ /// BitcoinGenesisContext is a genesis init config in the TxContext. struct BitcoinGenesisContext has copy,store,drop{ network: u8, - data_import_mode: u8, } fun init(){ @@ -26,7 +24,6 @@ module bitcoin_move::genesis{ assert!(option::is_some(&genesis_context_option), ErrorGenesisInit); let genesis_context = option::destroy_some(genesis_context_option); network::genesis_init(genesis_context.network); - data_import_config::genesis_init(genesis_context.data_import_mode); utxo::genesis_init(); brc20::genesis_init(&genesis_account); ord::genesis_init(&genesis_account); @@ -37,7 +34,7 @@ module bitcoin_move::genesis{ /// init the genesis context for test public fun init_for_test(){ let genesis_account = moveos_std::signer::module_signer(); - tx_context::add_attribute_via_system(&genesis_account, BitcoinGenesisContext{network: network::network_signet(), data_import_mode: data_import_config::data_import_mode_none()}); + tx_context::add_attribute_via_system(&genesis_account, BitcoinGenesisContext{network: network::network_signet()}); init(); } diff --git a/frameworks/bitcoin-move/sources/light_client.move b/frameworks/bitcoin-move/sources/light_client.move index 8d1e73bdbb..629cf30d6e 100644 --- a/frameworks/bitcoin-move/sources/light_client.move +++ b/frameworks/bitcoin-move/sources/light_client.move @@ -5,8 +5,8 @@ module bitcoin_move::light_client{ use std::option::{Self, Option}; use std::vector; use std::string::{String}; + use bitcoin_move::network; use moveos_std::simple_multimap::SimpleMultiMap; - use bitcoin_move::data_import_config; use moveos_std::type_info; use moveos_std::table::{Self, Table}; use moveos_std::bcs; @@ -25,6 +25,8 @@ module bitcoin_move::light_client{ const ErrorBlockNotFound:u64 = 1; const ErrorBlockAlreadyProcessed:u64 = 2; + const ORDINAL_GENESIS_HEIGHT:u64 = 767430; + struct TxProgressErrorLogEvent has copy, drop{ txid: address, message: String, @@ -100,7 +102,7 @@ module bitcoin_move::light_client{ if(is_coinbase) { coinbase_tx_idx = idx; } else { - let tx_flotsams = process_tx(btc_block_store, tx); + let tx_flotsams = process_tx(btc_block_store, tx, block_height); vector::append(&mut flotsams, tx_flotsams); }; idx = idx + 1; @@ -123,8 +125,8 @@ module bitcoin_move::light_client{ is_coinbase } - fun process_tx(btc_block_store: &mut BitcoinBlockStore, tx: &Transaction): vector{ - let flotsams = process_utxo(tx); + fun process_tx(btc_block_store: &mut BitcoinBlockStore, tx: &Transaction, block_height: u64): vector{ + let flotsams = process_utxo(tx, block_height); let txid = types::tx_id(tx); table::add(&mut btc_block_store.txs, txid, *tx); table_vec::push_back(&mut btc_block_store.tx_ids, txid); @@ -138,7 +140,7 @@ module bitcoin_move::light_client{ table_vec::push_back(&mut btc_block_store.tx_ids, txid); } - fun process_utxo(tx: &Transaction): vector{ + fun process_utxo(tx: &Transaction, block_height: u64): vector{ let txinput = types::tx_input(tx); let flotsams = vector::empty(); @@ -160,14 +162,14 @@ module bitcoin_move::light_client{ let idx = 0; let output_seals = simple_multimap::new(); - let data_import_mode = data_import_config::data_import_mode(); + let need_process_oridinal = need_process_oridinals(block_height); while (idx < vector::length(txinput)) { let txin = vector::borrow(txinput, idx); let outpoint = *types::txin_previous_output(txin); if (utxo::exists_utxo(outpoint)) { let object_id = utxo::derive_utxo_id(outpoint); let (_owner, utxo_obj) = utxo::take(object_id); - if(data_import_config::is_ord_mode(data_import_mode)) { + if(need_process_oridinal) { let (sat_points, utxo_flotsams) = ord::spend_utxo(&mut utxo_obj, tx, input_utxo_values, idx); handle_sat_point(sat_points, &mut output_seals); vector::append(&mut flotsams, utxo_flotsams); @@ -184,7 +186,7 @@ module bitcoin_move::light_client{ }; // Transfer and inscribe may happen at the same transaction - if(data_import_config::is_ord_mode(data_import_mode)) { + if(need_process_oridinal) { let sat_points = ord::process_transaction(tx, input_utxo_values); let idx = 0; let protocol = type_info::type_name(); @@ -207,8 +209,7 @@ module bitcoin_move::light_client{ fun process_coinbase_utxo(tx: &Transaction, flotsams: vector, block_height: u64){ let output_seals = simple_multimap::new(); - let data_import_mode = data_import_config::data_import_mode(); - if(data_import_config::is_ord_mode(data_import_mode)) { + if(need_process_oridinals(block_height)) { let sat_points = ord::handle_coinbase_tx(tx, flotsams, block_height); handle_sat_point(sat_points, &mut output_seals); }; @@ -326,6 +327,15 @@ module bitcoin_move::light_client{ let btc_block_store_obj = borrow_block_store(); let btc_block_store = object::borrow(btc_block_store_obj); btc_block_store.latest_block_height - } + } + + public fun need_process_oridinals(block_height: u64) : bool { + let btc_network = network::network(); + if(network::is_mainnet(btc_network)){ + block_height >= ORDINAL_GENESIS_HEIGHT + }else{ + true + } + } } \ No newline at end of file