Skip to content

Commit

Permalink
feat(rooch): implement l1_block_tx execution at startup for catch up …
Browse files Browse the repository at this point in the history
…sequenced tx (#2961)

* feat(rooch): implement l1_block_tx execution at startup for catch up sequenced tx

1. move btc client out of relayer for fix cyclic deps issues
2. add btc client proxy for processors
3. get btc block from btc client proxy
4. execute l1_block_tx when necessary at startup
  • Loading branch information
popcnt1 authored Nov 27, 2024
1 parent b9beddd commit 3e42e67
Show file tree
Hide file tree
Showing 23 changed files with 246 additions and 151 deletions.
24 changes: 20 additions & 4 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"moveos/smt",
"moveos/moveos-eventbus",
"moveos/moveos-gas-profiling",
"crates/bitcoin-client",
"crates/data_verify",
"crates/rooch",
"crates/rooch-benchmarks",
Expand Down Expand Up @@ -59,7 +60,7 @@ members = [
"frameworks/framework-types",
"frameworks/moveos-stdlib",
"frameworks/rooch-framework",
"frameworks/rooch-nursery",
"frameworks/rooch-nursery", "crates/bitcoin-client",
]

default-members = [
Expand Down Expand Up @@ -108,6 +109,8 @@ accumulator = { path = "moveos/moveos-commons/accumulator" }
moveos-gas-profiling = { path = "moveos/moveos-gas-profiling" }

# crates for Rooch
bitcoin-client = { path = "crates/bitcoin-client" }
data-verify = { path = "crates/data_verify" }
rooch = { path = "crates/rooch" }
rooch-common = { path = "crates/rooch-common" }
rooch-key = { path = "crates/rooch-key" }
Expand Down Expand Up @@ -135,7 +138,6 @@ rooch-da = { path = "crates/rooch-da" }
rooch-benchmarks = { path = "crates/rooch-benchmarks" }
rooch-faucet = { path = "crates/rooch-faucet" }
rooch-test-transaction-builder = { path = "crates/rooch-test-transaction-builder" }
data-verify = { path = "crates/data_verify" }
rooch-db = { path = "crates/rooch-db" }
rooch-event = { path = "crates/rooch-event" }
rooch-ord = { path = "crates/rooch-ord" }
Expand Down
21 changes: 21 additions & 0 deletions crates/bitcoin-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "bitcoin-client"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
publish.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
bitcoin = { workspace = true }
bitcoincore-rpc = { workspace = true }
coerce = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { features = ["full"], workspace = true }
tracing = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use super::messages::{GetChainTipsMessage, GetRawTransactionMessage, GetTxOutMessage};
use crate::actor::messages::{
BroadcastTransactionMessage, GetBestBlockHashMessage, GetBlockHashMessage,
GetBlockHeaderInfoMessage, GetBlockMessage,
GetBlockHeaderInfoMessage, GetBlockMessage, GetChainTipsMessage, GetRawTransactionMessage,
GetTxOutMessage,
};
use anyhow::Result;
use async_trait::async_trait;
Expand All @@ -20,6 +20,22 @@ pub struct BitcoinClientActor {
retry_delay: Duration,
}

pub struct BitcoinClientConfig {
pub btc_rpc_url: String,
pub btc_rpc_user_name: String,
pub btc_rpc_password: String,
}

impl BitcoinClientConfig {
pub fn build(&self) -> Result<BitcoinClientActor> {
BitcoinClientActor::new(
&self.btc_rpc_url,
&self.btc_rpc_user_name,
&self.btc_rpc_password,
)
}
}

impl BitcoinClientActor {
pub fn new(btc_rpc_url: &str, btc_rpc_user_name: &str, btc_rpc_password: &str) -> Result<Self> {
let rpc_client = Client::new(
Expand Down
91 changes: 91 additions & 0 deletions crates/bitcoin-client/src/actor/messages.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use bitcoin::Transaction;
use bitcoincore_rpc::bitcoin::Txid;
use bitcoincore_rpc::json;
use coerce::actor::message::Message;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct GetBlockMessage {
pub hash: bitcoin::BlockHash,
}

impl Message for GetBlockMessage {
type Result = Result<bitcoin::Block>;
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetBestBlockHashMessage {}

impl Message for GetBestBlockHashMessage {
type Result = Result<bitcoin::BlockHash>;
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetBlockHashMessage {
pub height: u64,
}

impl Message for GetBlockHashMessage {
type Result = Result<bitcoin::BlockHash>;
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetBlockHeaderInfoMessage {
pub hash: bitcoin::BlockHash,
}

impl Message for GetBlockHeaderInfoMessage {
type Result = Result<json::GetBlockHeaderResult>;
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetChainTipsMessage {}

impl Message for GetChainTipsMessage {
type Result = Result<json::GetChainTipsResult>;
}

#[derive(Debug, Serialize, Deserialize)]
pub struct BroadcastTransactionMessage {
pub hex: String,
pub maxfeerate: Option<f64>,
pub maxburnamount: Option<f64>,
}

impl Message for BroadcastTransactionMessage {
type Result = Result<Txid>;
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetTxOutMessage {
pub txid: Txid,
pub vout: u32,
pub include_mempool: Option<bool>,
}

impl GetTxOutMessage {
pub fn new(txid: Txid, vout: u32) -> Self {
Self {
txid,
vout,
include_mempool: Some(false),
}
}
}

impl Message for GetTxOutMessage {
type Result = Result<Option<json::GetTxOutResult>>;
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetRawTransactionMessage {
pub txid: Txid,
}

impl Message for GetRawTransactionMessage {
type Result = Result<Transaction>;
}
5 changes: 5 additions & 0 deletions crates/bitcoin-client/src/actor/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

pub mod client;
pub mod messages;
5 changes: 5 additions & 0 deletions crates/bitcoin-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

pub mod actor;
pub mod proxy;
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::actor::bitcoin_client::BitcoinClientActor;
use crate::actor::client::BitcoinClientActor;
use crate::actor::messages::{
BroadcastTransactionMessage, GetBestBlockHashMessage, GetBlockHashMessage,
GetBlockHeaderInfoMessage, GetBlockMessage,
GetBlockHeaderInfoMessage, GetBlockMessage, GetChainTipsMessage, GetRawTransactionMessage,
GetTxOutMessage,
};
use anyhow::Result;
use bitcoin::Transaction;
use bitcoincore_rpc::bitcoin::Txid;
use bitcoincore_rpc::json;
use coerce::actor::ActorRef;

use super::messages::{GetChainTipsMessage, GetRawTransactionMessage, GetTxOutMessage};

#[derive(Clone)]
pub struct BitcoinClientProxy {
pub actor: ActorRef<BitcoinClientActor>,
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ repository = { workspace = true }
rust-version = { workspace = true }

[dependencies]
libc = { workspace = true }
libc = { workspace = true }
2 changes: 1 addition & 1 deletion crates/rooch-framework-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ moveos-store = { workspace = true }
moveos-config = { workspace = true }
metrics = { workspace = true }

bitcoin-client = { workspace = true }
rooch-genesis = { workspace = true }
rooch-types = { workspace = true }
rooch-key = { workspace = true }
rooch-executor = { workspace = true }
rooch-config = { workspace = true }
rooch-db = { workspace = true }
rooch-relayer = { workspace = true }
rooch-ord = { workspace = true }

framework-builder = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-framework-tests/src/bitcoin_block_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::{bbn_tx_loader::BBNStakingTxRecord, binding_test::RustBindingTest};
use anyhow::{anyhow, bail, ensure, Result};
use bitcoin::{hashes::Hash, Block, OutPoint, TxOut, Txid};
use bitcoin_client::proxy::BitcoinClientProxy;
use framework_builder::stdlib_version::StdlibVersion;
use move_core_types::{account_address::AccountAddress, u256::U256, vm_status::KeptVMStatus};
use moveos_types::{
Expand All @@ -16,7 +17,6 @@ use moveos_types::{
state_resolver::StateResolver,
};
use rooch_ord::ord_client::Charm;
use rooch_relayer::actor::bitcoin_client_proxy::BitcoinClientProxy;
use rooch_types::{
bitcoin::{
bbn::{
Expand Down
5 changes: 2 additions & 3 deletions crates/rooch-framework-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
use std::path::PathBuf;

use anyhow::Result;
use bitcoin_client::actor::client::BitcoinClientActor;
use bitcoin_client::proxy::BitcoinClientProxy;
use clap::Parser;
use coerce::actor::{system::ActorSystem, IntoActor};
use rooch_framework_tests::bitcoin_block_tester::TesterGenesisBuilder;
use rooch_relayer::actor::{
bitcoin_client::BitcoinClientActor, bitcoin_client_proxy::BitcoinClientProxy,
};

#[derive(Parser)]
#[clap(name = "test_builder", author = "The Rooch Core Contributors")]
Expand Down
10 changes: 6 additions & 4 deletions crates/rooch-pipeline-processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rust-version = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
bcs = { workspace = true }
bitcoin = { workspace = true }
coerce = { workspace = true }
function_name = { workspace = true }
hex = { workspace = true }
Expand All @@ -25,10 +26,11 @@ moveos = { workspace = true }
metrics = { workspace = true }
moveos-types = { workspace = true }

bitcoin-client = { workspace = true }
rooch-da = { workspace = true }
rooch-types = { workspace = true }
rooch-sequencer = { workspace = true }
rooch-db = { workspace = true }
rooch-executor = { workspace = true }
rooch-indexer = { workspace = true }
rooch-event = { workspace = true }
rooch-db = { workspace = true }
rooch-indexer = { workspace = true }
rooch-sequencer = { workspace = true }
rooch-types = { workspace = true }
Loading

0 comments on commit 3e42e67

Please sign in to comment.