Skip to content

Commit

Permalink
Make an attempt to rate limit the oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
james-chf committed Oct 6, 2022
1 parent c85ed34 commit 1f75022
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions apps/src/lib/node/ledger/ethereum_node/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,21 @@ async fn run_oracle_aux(oracle: Oracle) {
// 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;
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 @@ -146,6 +156,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 1f75022

Please sign in to comment.