Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bridge): history latest log error if provider isn't giving new blocks #1148

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions portal-bridge/src/bridge/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ impl HistoryBridge {
let mut block_index = self.execution_api.get_latest_block_number().await.expect(
"Error launching bridge in latest mode. Unable to get latest block from provider.",
);
// If a provider returns the same block number and doesn't time out over and over.
// this indicates the provider is no longer in sync with the chain so we want to long an
// error
let mut last_seen_block_counter = 0;
loop {
sleep(Duration::from_secs(LATEST_BLOCK_POLL_RATE)).await;
let latest_block = match self.execution_api.get_latest_block_number().await {
Expand All @@ -111,7 +115,9 @@ impl HistoryBridge {
continue;
}
};
last_seen_block_counter += 1;
if latest_block > block_index {
last_seen_block_counter = 0;
let gossip_range = Range {
start: block_index,
end: latest_block + 1,
Expand All @@ -128,6 +134,11 @@ impl HistoryBridge {
}
block_index = gossip_range.end;
}
// Ethereum mainnet creates a new block every 15 seconds, if we don't get a new block
// within 1 minute. There is a problem with the provider so throw an error.
if last_seen_block_counter > 60 / LATEST_BLOCK_POLL_RATE {
tracing::error!("History Latest: Haven't received a new block in over 60 seconds. EL provider could be out of sync.");
}
}
}

Expand Down
Loading