Skip to content

Commit

Permalink
Split btcio config to reader and writer
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibek Pandey committed Jan 14, 2025
1 parent 1c48b76 commit 1c91a81
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bin/strata-client/src/l1_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
rpc_client,
ev_tx,
target_next_block,
Arc::new(config.btcio.clone()),
Arc::new(config.btcio.reader.clone()),
params.clone(),
status_channel,
),
Expand Down
2 changes: 1 addition & 1 deletion bin/strata-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ fn start_sequencer_tasks(
let envelope_handle = start_envelope_task(
executor,
bitcoin_client,
btcio_config,
Arc::new(btcio_config.writer.clone()),
params.clone(),
sequencer_bitcoin_address,
seq_db,
Expand Down
8 changes: 4 additions & 4 deletions crates/btcio/src/reader/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use anyhow::bail;
use bitcoin::{Block, BlockHash};
use strata_config::btcio::BtcioConfig;
use strata_config::btcio::ReaderConfig;
use strata_l1tx::{
filter::filter_protocol_op_tx_refs,
filter_types::TxFilterConfig,
Expand Down Expand Up @@ -34,7 +34,7 @@ struct ReaderContext<R: ReaderRpc> {
/// L1Event sender
event_tx: mpsc::Sender<L1Event>,
/// Config
config: Arc<BtcioConfig>,
config: Arc<ReaderConfig>,
/// Params
params: Arc<Params>,
/// Status transmitter
Expand All @@ -46,7 +46,7 @@ pub async fn bitcoin_data_reader_task(
client: Arc<impl ReaderRpc>,
event_tx: mpsc::Sender<L1Event>,
target_next_block: u64,
config: Arc<BtcioConfig>,
config: Arc<ReaderConfig>,
params: Arc<Params>,
status_channel: StatusChannel,
) -> anyhow::Result<()> {
Expand Down Expand Up @@ -441,7 +441,7 @@ mod test {
let l1status: L1Status = gen.generate();
let status_channel = StatusChannel::new(cls, l1status, Some(chs));
let params = Arc::new(gen_params());
let config = Arc::new(BtcioConfig::default());
let config = Arc::new(ReaderConfig::default());
let client = Arc::new(TestBitcoinClient::new(1));
ReaderContext {
event_tx,
Expand Down
4 changes: 2 additions & 2 deletions crates/btcio/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub(crate) mod test_context {
use std::sync::Arc;

use bitcoin::{Address, Network};
use strata_config::btcio::BtcioConfig;
use strata_config::btcio::WriterConfig;
use strata_status::StatusChannel;
use strata_test_utils::{l2::gen_params, ArbitraryGenerator};

Expand All @@ -304,7 +304,7 @@ pub(crate) mod test_context {
.unwrap()
.require_network(Network::Regtest)
.unwrap();
let cfg = Arc::new(BtcioConfig::default());
let cfg = Arc::new(WriterConfig::default());
let status_channel = StatusChannel::new(
ArbitraryGenerator::new().generate(),
ArbitraryGenerator::new().generate(),
Expand Down
6 changes: 3 additions & 3 deletions crates/btcio/src/writer/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use bitcoin::Address;
use strata_config::btcio::BtcioConfig;
use strata_config::btcio::WriterConfig;
use strata_primitives::params::Params;
use strata_status::StatusChannel;

Expand All @@ -13,7 +13,7 @@ pub struct WriterContext<W: WriterRpc> {
// Params for rollup.
pub params: Arc<Params>,
// Btcio specific configuration.
pub config: Arc<BtcioConfig>,
pub config: Arc<WriterConfig>,
// Sequencer's address to watch utxos for and spend change amount to.
pub sequencer_address: Address,
// Bitcoin client to sign and submit transactions.
Expand All @@ -25,7 +25,7 @@ pub struct WriterContext<W: WriterRpc> {
impl<W: WriterRpc> WriterContext<W> {
pub fn new(
params: Arc<Params>,
config: Arc<BtcioConfig>,
config: Arc<WriterConfig>,
sequencer_address: Address,
client: Arc<W>,
status_channel: StatusChannel,
Expand Down
4 changes: 2 additions & 2 deletions crates/btcio/src/writer/task.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{sync::Arc, time::Duration};

use bitcoin::Address;
use strata_config::btcio::BtcioConfig;
use strata_config::btcio::WriterConfig;
use strata_db::{
traits::SequencerDatabase,
types::{L1TxStatus, PayloadEntry, PayloadL1Status},
Expand Down Expand Up @@ -93,7 +93,7 @@ impl EnvelopeHandle {
pub fn start_envelope_task<D: SequencerDatabase + Send + Sync + 'static>(
executor: &TaskExecutor,
bitcoin_client: Arc<BitcoinClient>,
config: Arc<BtcioConfig>,
config: Arc<WriterConfig>,
params: Arc<Params>,
sequencer_address: Address,
db: Arc<D>,
Expand Down
25 changes: 22 additions & 3 deletions crates/config/src/btcio.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
use serde::Deserialize;

/// Configuration for btcio tasks.
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Default, Deserialize)]
pub struct BtcioConfig {
pub reader: ReaderConfig,
pub writer: WriterConfig,
}

/// Configuration for btcio reader.
#[derive(Debug, Clone, Deserialize)]
pub struct ReaderConfig {
/// How often to poll btc client
pub client_poll_dur_ms: u32,
}

/// Configuration for btcio writer/signer.
#[derive(Debug, Clone, Deserialize)]
pub struct WriterConfig {
/// How often to invoke the writer
pub write_poll_dur_ms: u64,
/// How the fees for are determined.
Expand All @@ -24,13 +36,20 @@ pub enum FeePolicy {
Fixed(u64),
}

impl Default for BtcioConfig {
impl Default for WriterConfig {
fn default() -> Self {
Self {
client_poll_dur_ms: 200,
write_poll_dur_ms: 1_000,
fee_policy: FeePolicy::Smart,
reveal_amount: 1_000,
}
}
}

impl Default for ReaderConfig {
fn default() -> Self {
Self {
client_poll_dur_ms: 1_000,
}
}
}

0 comments on commit 1c91a81

Please sign in to comment.