From 38d9eec934a4949c347862e705e4ac2b47d14a70 Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Wed, 22 May 2024 08:52:19 +0200 Subject: [PATCH 1/4] contracts: update wait after fetch --- lib/contracts.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/contracts.js b/lib/contracts.js index e6450b9b..be166b41 100644 --- a/lib/contracts.js +++ b/lib/contracts.js @@ -10,6 +10,10 @@ const { export const runUpdateContractsLoop = async ({ provider, abi, contracts }) => { while (true) { + const newContracts = await getContractsWithRetry({ provider, abi }) + contracts.splice(0) + contracts.push(...newContracts) + const delay = 10 * 60 * 1000 // 10 minutes const jitter = Math.random() * 20_000 - 10_000 // +- 10 seconds try { @@ -18,9 +22,6 @@ export const runUpdateContractsLoop = async ({ provider, abi, contracts }) => { if (err.name === 'AbortError') return throw err } - const newContracts = await getContractsWithRetry({ provider, abi }) - contracts.splice(0) - contracts.push(...newContracts) } } From 8889226597ab8161cf0995090439f3656d09bb5f Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Wed, 22 May 2024 01:09:41 -0700 Subject: [PATCH 2/4] Update lib/contracts.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Miroslav Bajtoš --- lib/contracts.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/contracts.js b/lib/contracts.js index be166b41..1775d829 100644 --- a/lib/contracts.js +++ b/lib/contracts.js @@ -9,6 +9,7 @@ const { } = process.env export const runUpdateContractsLoop = async ({ provider, abi, contracts }) => { + await timers.setTimeout(2_000) while (true) { const newContracts = await getContractsWithRetry({ provider, abi }) contracts.splice(0) From 57648369c2902283fe26a8934e3158076b524b2d Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Wed, 22 May 2024 10:12:16 +0200 Subject: [PATCH 3/4] fix --- lib/contracts.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/contracts.js b/lib/contracts.js index fe9640c8..98523d0a 100644 --- a/lib/contracts.js +++ b/lib/contracts.js @@ -8,6 +8,8 @@ const { CONTRACT_ADDRESSES_IPNS_KEY = 'k51qzi5uqu5dmaqrefqazad0ca8b24fb79zlacfjw2awdt5gjf2cr6jto5jyqe' } = process.env +const DELAY_IN_MINUTES = 10 + export const runUpdateContractsLoop = async ({ provider, abi, contracts, onActivity }) => { await timers.setTimeout(2_000) while (true) { @@ -19,11 +21,11 @@ export const runUpdateContractsLoop = async ({ provider, abi, contracts, onActiv console.error('Failed to update the list of contract addresses. Will retry later.', err) onActivity({ type: 'error', - message: `Cannot update scheduled rewards. Will retry in ${delayInMinutes} minutes.` + message: `Cannot update scheduled rewards. Will retry in ${DELAY_IN_MINUTES} minutes.` }) } - const delay = 10 * 60 * 1000 // 10 minutes + const delay = DELAY_IN_MINUTES * 60 * 1000 // 10 minutes const jitter = Math.random() * 20_000 - 10_000 // +- 10 seconds try { await timers.setTimeout(delay + jitter) From c7276175dc1fcda66cfdb725e80a54b748074f8d Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Wed, 22 May 2024 10:12:46 +0200 Subject: [PATCH 4/4] clean up --- lib/contracts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/contracts.js b/lib/contracts.js index 98523d0a..ebba88c4 100644 --- a/lib/contracts.js +++ b/lib/contracts.js @@ -25,7 +25,7 @@ export const runUpdateContractsLoop = async ({ provider, abi, contracts, onActiv }) } - const delay = DELAY_IN_MINUTES * 60 * 1000 // 10 minutes + const delay = DELAY_IN_MINUTES * 60 * 1000 const jitter = Math.random() * 20_000 - 10_000 // +- 10 seconds try { await timers.setTimeout(delay + jitter)