Skip to content

Commit

Permalink
view: hack attempting to mitigate split-brain GRPC failures
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence authored and conorsch committed Dec 8, 2023
1 parent ec413ef commit 88fb275
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions crates/view/src/worker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
collections::BTreeSet,
sync::{Arc, Mutex},
time::Duration,
};

use anyhow::Context;
Expand Down Expand Up @@ -374,12 +375,24 @@ async fn fetch_transactions(
block_height: u64,
) -> anyhow::Result<Vec<Transaction>> {
let mut client = AppQueryServiceClient::new(channel);
let transactions = client
.transactions_by_height(TransactionsByHeightRequest {
block_height,
..Default::default()
})
.await?
let request = TransactionsByHeightRequest {
block_height,
..Default::default()
};
// HACK: this is not a robust long-term solution but may help
// avoid "split-brain" block fetch issues, where a client learns
// of a new block, then immediately tries to fetch it, but that
// fetch is load-balanced over a different node that hasn't yet
// learned about that block.
let response = match client.transactions_by_height(request.clone()).await {
Ok(rsp) => rsp,
Err(e) => {
tracing::warn!(?e, "failed to fetch block, waiting and retrying once");
tokio::time::sleep(Duration::from_secs(1)).await;
client.transactions_by_height(request).await?
}
};
let transactions = response
.into_inner()
.transactions
.into_iter()
Expand Down

0 comments on commit 88fb275

Please sign in to comment.