Skip to content

Commit

Permalink
fix(ampd): retry fetching blocking results on error (#265)
Browse files Browse the repository at this point in the history
* feat(ampd): retry event handling with timeout and max attempts
  • Loading branch information
cjcobb23 authored Feb 16, 2024
1 parent 360560d commit 671777b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions ampd/src/event_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use tracing::info;

use events::Event;

use crate::asyncutil::future::{self, RetryPolicy};
use crate::tm_client::TmClient;

pub struct EventPublisher<T: TmClient + Sync> {
Expand Down Expand Up @@ -130,13 +131,20 @@ impl<T: TmClient + Sync> EventPublisher<T> {
}

async fn events(&self, block_height: block::Height) -> Result<Vec<abci::Event>, EventSubError> {
let block_results = self
.client
.block_results(block_height)
.change_context(EventSubError::EventQuery {
block: block_height,
})
.await?;
let block_results = future::with_retry(
|| {
self.client
.block_results(block_height)
.change_context(EventSubError::EventQuery {
block: block_height,
})
},
RetryPolicy::RepeatConstant {
sleep: Duration::from_secs(1),
max_attempts: 3,
},
)
.await?;

let begin_block_events = block_results.begin_block_events.into_iter().flatten();
let tx_events = block_results
Expand Down

0 comments on commit 671777b

Please sign in to comment.