Skip to content

Commit

Permalink
Merge pull request #463 from anoma/james/ethbridge/oracle-rate-limiting
Browse files Browse the repository at this point in the history
Add rate limiting to the Ethereum event oracle
  • Loading branch information
sug0 authored Sep 26, 2022
2 parents 777d8bb + fd9c4c0 commit 190bf02
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions apps/src/lib/node/ledger/ethereum_node/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,22 @@ async fn run_oracle_aux(oracle: Oracle) {
// Initialize our local state. This includes
// the latest block height seen and a queue of events
// awaiting a certain number of confirmations
let mut latest_block;
let mut pending: Vec<PendingEvent> = Vec::new();
const SLEEP_DUR: std::time::Duration = std::time::Duration::from_secs(1);
loop {
tokio::time::sleep(SLEEP_DUR).await;
// update the latest block height
latest_block = loop {
if let Ok(height) = oracle.eth_block_number().await {
break height;
let latest_block = loop {
match oracle.eth_block_number().await {
Ok(height) => break height,
Err(error) => {
tracing::warn!(
?error,
"Couldn't get the latest Ethereum block height, will \
keep trying"
);
tokio::time::sleep(SLEEP_DUR).await;
}
}
if !oracle.connected() {
tracing::info!(
Expand All @@ -139,6 +148,7 @@ async fn run_oracle_aux(oracle: Oracle) {
return;
}
};
tracing::debug!(?latest_block, "Got latest Ethereum block height");
// No blocks in existence yet with enough confirmations
if Uint256::from(MIN_CONFIRMATIONS) > latest_block {
if !oracle.connected() {
Expand Down

0 comments on commit 190bf02

Please sign in to comment.