Skip to content

Commit

Permalink
make broadcast poll duration configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sapinb committed Feb 3, 2025
1 parent 08ca7e1 commit b0f834d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
11 changes: 9 additions & 2 deletions bin/strata-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ fn main_inner(args: Args) -> anyhow::Result<()> {
&executor,
ctx.bitcoin_client.clone(),
params.clone(),
config.btcio.broadcaster.poll_interval_ms,

Check warning on line 143 in bin/strata-client/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-client/src/main.rs#L143

Added line #L143 was not covered by tests
);
let writer_db = init_writer_database(rbdb.clone(), ops_config);

Expand Down Expand Up @@ -477,15 +478,21 @@ fn start_broadcaster_tasks(
executor: &TaskExecutor,
bitcoin_client: Arc<BitcoinClient>,
params: Arc<Params>,
broadcast_poll_interval: u64,

Check warning on line 481 in bin/strata-client/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-client/src/main.rs#L481

Added line #L481 was not covered by tests
) -> Arc<L1BroadcastHandle> {
// Set up L1 broadcaster.
let broadcast_ctx = strata_storage::ops::l1tx_broadcast::Context::new(
broadcast_database.l1_broadcast_db().clone(),
);
let broadcast_ops = Arc::new(broadcast_ctx.into_ops(pool));
// start broadcast task
let broadcast_handle =
spawn_broadcaster_task(executor, bitcoin_client.clone(), broadcast_ops, params);
let broadcast_handle = spawn_broadcaster_task(
executor,
bitcoin_client.clone(),
broadcast_ops,
params,
broadcast_poll_interval,
);

Check warning on line 495 in bin/strata-client/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-client/src/main.rs#L489-L495

Added lines #L489 - L495 were not covered by tests
Arc::new(broadcast_handle)
}

Expand Down
13 changes: 10 additions & 3 deletions crates/btcio/src/broadcaster/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,23 @@ pub fn spawn_broadcaster_task<T>(
l1_rpc_client: Arc<T>,
broadcast_ops: Arc<BroadcastDbOps>,
params: Arc<Params>,
broadcast_poll_interval: u64,

Check warning on line 73 in crates/btcio/src/broadcaster/handle.rs

View check run for this annotation

Codecov / codecov/patch

crates/btcio/src/broadcaster/handle.rs#L73

Added line #L73 was not covered by tests
) -> L1BroadcastHandle
where
T: ReaderRpc + BroadcasterRpc + WalletRpc + SignerRpc + Send + Sync + 'static,
{
let (broadcast_entry_tx, broadcast_entry_rx) = mpsc::channel::<(u64, L1TxEntry)>(64);
let ops = broadcast_ops.clone();
executor.spawn_critical_async("l1_broadcaster_task", async move {
broadcaster_task(l1_rpc_client, ops, broadcast_entry_rx, params)
.await
.map_err(Into::into)
broadcaster_task(
l1_rpc_client,
ops,
broadcast_entry_rx,
params,
broadcast_poll_interval,
)
.await
.map_err(Into::into)

Check warning on line 89 in crates/btcio/src/broadcaster/handle.rs

View check run for this annotation

Codecov / codecov/patch

crates/btcio/src/broadcaster/handle.rs#L81-L89

Added lines #L81 - L89 were not covered by tests
});
L1BroadcastHandle::new(broadcast_entry_tx, broadcast_ops)
}
5 changes: 2 additions & 3 deletions crates/btcio/src/broadcaster/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ use crate::{
rpc::traits::{BroadcasterRpc, WalletRpc},
};

const BROADCAST_POLL_INTERVAL: u64 = 1_000; // millis

/// Broadcasts the next blob to be sent
pub async fn broadcaster_task(
rpc_client: Arc<impl BroadcasterRpc + WalletRpc>,
ops: Arc<l1tx_broadcast::BroadcastDbOps>,
mut entry_receiver: Receiver<(u64, L1TxEntry)>,
params: Arc<Params>,
broadcast_poll_interval: u64,

Check warning on line 24 in crates/btcio/src/broadcaster/task.rs

View check run for this annotation

Codecov / codecov/patch

crates/btcio/src/broadcaster/task.rs#L24

Added line #L24 was not covered by tests
) -> BroadcasterResult<()> {
info!("Starting Broadcaster task");
let interval = tokio::time::interval(Duration::from_millis(BROADCAST_POLL_INTERVAL));
let interval = tokio::time::interval(Duration::from_millis(broadcast_poll_interval));

Check warning on line 27 in crates/btcio/src/broadcaster/task.rs

View check run for this annotation

Codecov / codecov/patch

crates/btcio/src/broadcaster/task.rs#L27

Added line #L27 was not covered by tests
tokio::pin!(interval);

let mut state = BroadcasterState::initialize(&ops).await?;
Expand Down
16 changes: 16 additions & 0 deletions crates/config/src/btcio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::Deserialize;
pub struct BtcioConfig {
pub reader: ReaderConfig,
pub writer: WriterConfig,
pub broadcaster: BroadcasterConfig,
}

/// Configuration for btcio reader.
Expand Down Expand Up @@ -38,6 +39,13 @@ pub enum FeePolicy {
Fixed(u64),
}

/// Configuration for btcio broadcaster.
#[derive(Debug, Clone, Deserialize)]
pub struct BroadcasterConfig {
/// How often to invoke the broadcaster, in ms.
pub poll_interval_ms: u64,
}

impl Default for WriterConfig {
fn default() -> Self {
Self {
Expand All @@ -56,3 +64,11 @@ impl Default for ReaderConfig {
}
}
}

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

Check warning on line 73 in crates/config/src/btcio.rs

View check run for this annotation

Codecov / codecov/patch

crates/config/src/btcio.rs#L69-L73

Added lines #L69 - L73 were not covered by tests
}
6 changes: 6 additions & 0 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ mod test {
reveal_amount = 100
bundle_interval_ms = 1000
[btcio.broadcaster]
poll_interval_ms = 1000
[relayer]
refresh_interval = 10
stale_duration = 120
Expand Down Expand Up @@ -161,6 +164,9 @@ mod test {
reveal_amount = 100
bundle_interval_ms = 1000
[btcio.broadcaster]
poll_interval_ms = 1000
[exec.reth]
rpc_url = "http://localhost:8551"
secret = "1234567890abcdef"
Expand Down

0 comments on commit b0f834d

Please sign in to comment.