Skip to content

Commit

Permalink
Merge pull request #152 from hive-engine/find_divergent_block_retries
Browse files Browse the repository at this point in the history
Find divergent block retries
  • Loading branch information
bt-cryptomancer authored Jul 25, 2022
2 parents 0bb3c76 + cfc72bf commit 810062b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions find_divergent_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { node } = program;

let id = 1;

async function getBlock(blockNumber) {
async function getBlock(blockNumber, tries=1) {
id += 1;
try {
return (await axios({
Expand All @@ -32,8 +32,14 @@ async function getBlock(blockNumber) {
},
})).data.result;
} catch (error) {
console.error(error);
return null;
if (tries >= 3) {
console.error(error);
return null;
} else {
console.log(`Attempt #${tries} failed, retrying...`);
await new Promise((r) => setTimeout(() => r(), 500));
return await getBlock(blockNumber, tries + 1);
}
}
}

Expand Down

0 comments on commit 810062b

Please sign in to comment.