Skip to content

Commit 27e6144

Browse files
committed
chore: code review changes
1 parent 4fb7646 commit 27e6144

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

src/utils/block_watcher.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,7 @@ use tokio::{
1010
sync::{broadcast::error::RecvError, watch},
1111
task::JoinHandle,
1212
};
13-
use tracing::{debug, error, trace, warn};
14-
15-
/// Errors that can occur on the [`BlockWatcher`] task.
16-
#[derive(Debug, thiserror::Error)]
17-
pub enum BlockWatcherError {
18-
/// Failed to subscribe to host chain blocks.
19-
#[error("failed to subscribe to host chain blocks: {0}")]
20-
SubscribeError(TransportError),
21-
}
22-
23-
impl From<TransportError> for BlockWatcherError {
24-
fn from(err: TransportError) -> Self {
25-
BlockWatcherError::SubscribeError(err)
26-
}
27-
}
13+
use tracing::{debug, error, info, trace, warn};
2814

2915
/// Host chain block watcher that subscribes to new blocks and broadcasts
3016
/// updates via a watch channel.
@@ -50,7 +36,7 @@ impl BlockWatcher {
5036
/// Creates a new [`BlockWatcher`], fetching the current block number first.
5137
pub async fn with_current_block(
5238
host_provider: RootProvider<Ethereum>,
53-
) -> Result<Self, BlockWatcherError> {
39+
) -> Result<Self, TransportError> {
5440
let block_number = host_provider.get_block_number().await?;
5541
Ok(Self::new(host_provider, block_number))
5642
}
@@ -61,8 +47,8 @@ impl BlockWatcher {
6147
}
6248

6349
/// Spawns the block watcher task.
64-
pub fn spawn(self) -> JoinHandle<()> {
65-
tokio::spawn(self.task_future())
50+
pub fn spawn(self) -> (SharedBlockNumber, JoinHandle<()>) {
51+
(self.subscribe(), tokio::spawn(self.task_future()))
6652
}
6753

6854
async fn task_future(self) {
@@ -87,7 +73,7 @@ impl BlockWatcher {
8773
warn!(%missed, "block subscription lagged");
8874
}
8975
Err(RecvError::Closed) => {
90-
error!("block subscription closed");
76+
info!("block subscription closed");
9177
break;
9278
}
9379
}

0 commit comments

Comments
 (0)