Skip to content

Commit

Permalink
[Bitcoin] Eliminate data import mode (#1645)
Browse files Browse the repository at this point in the history
* eliminate data import mode

* fixup data import flag define

* fixup need process ordinals flag

* fixup need process ordinals flag

* fixup fmt
  • Loading branch information
baichuan3 authored Apr 30, 2024
1 parent d9d8217 commit 756d064
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 440 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rooch-benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ is `rooch-benchmarks/config/bench_tx.toml`.
pub struct BenchTxConfig {
pub tx_type: Option<TxType>,
// empty(default)/transfer/btc-block
pub data_import_mode: Option<DataImportMode>,
pub data_import_flag: bool,
// utxo(default)/ord/none/full
pub btc_block_dir: Option<String>,
// btc block dir, file name: <height>.hex
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-benchmarks/config/bench_tx.toml
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 3 additions & 5 deletions crates/rooch-benchmarks/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -80,7 +78,7 @@ impl Display for TxType {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Parser, Eq)]
pub struct BenchTxConfig {
pub tx_type: Option<TxType>, // empty(default)/transfer/btc-block
pub data_import_mode: Option<DataImportMode>, // utxo(default)/ord/none/full
pub data_import_flag: bool,
pub btc_block_dir: Option<String>, // btc block dir, file name: <height>.hex
pub pprof_output: Option<PProfOutput>, // flamegraph(default)/proto
}
Expand All @@ -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),
}
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions crates/rooch-benchmarks/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;

Expand Down
4 changes: 1 addition & 3 deletions crates/rooch-benchmarks/src/tx_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 3 additions & 5 deletions crates/rooch-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -142,10 +141,9 @@ pub struct RoochOpt {
#[clap(long)]
pub da: Option<DAConfig>,

#[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<u8>,
/// The data import flag. If true, may be ignore the indexer write
pub data_import_flag: bool,
}

impl std::fmt::Display for RoochOpt {
Expand Down Expand Up @@ -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,
}
}

Expand Down
8 changes: 2 additions & 6 deletions crates/rooch-framework-tests/src/binding_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,10 +51,6 @@ pub struct RustBindingTest {

impl RustBindingTest {
pub fn new() -> Result<Self> {
Self::new_with_mode(DataImportMode::Ord.to_num())
}

pub fn new_with_mode(data_import_mode: u8) -> Result<Self> {
let data_dir = get_data_dir();
let (rooch_db_path, moveos_db_path) = (
StoreConfig::get_mock_moveos_store_dir(&data_dir),
Expand All @@ -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)?;

Expand Down
12 changes: 2 additions & 10 deletions crates/rooch-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,10 +42,7 @@ pub static ROOCH_LOCAL_GENESIS: Lazy<RoochGenesis> = 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,
Expand Down Expand Up @@ -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};
Expand All @@ -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,
Expand Down
14 changes: 4 additions & 10 deletions crates/rooch-rpc-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())?;
};
Expand Down Expand Up @@ -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?;
Expand Down
117 changes: 0 additions & 117 deletions crates/rooch-types/src/bitcoin/data_import_config.rs

This file was deleted.

10 changes: 2 additions & 8 deletions crates/rooch-types/src/bitcoin/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 }
}
}
2 changes: 1 addition & 1 deletion crates/rooch-types/src/bitcoin/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<Header>> {
let call = Self::create_function_call(
Expand Down
1 change: 0 additions & 1 deletion crates/rooch-types/src/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 756d064

Please sign in to comment.