From dea804380688207566e1a759e9a882cc5d03d6c8 Mon Sep 17 00:00:00 2001 From: Pasha8914 Date: Tue, 14 Jun 2022 21:57:41 +1000 Subject: [PATCH] fix: incorrect calculation of rpc requests chunks count --- modules/account/store/actions/utils.js | 7 ++++++- store/application.js | 14 +++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/account/store/actions/utils.js b/modules/account/store/actions/utils.js index 68b2280..5e6047a 100644 --- a/modules/account/store/actions/utils.js +++ b/modules/account/store/actions/utils.js @@ -54,7 +54,12 @@ async function getEventsFromBlockPart({ echoContract, address, currentBlockNumbe address }) if (partOfEvents) { - events = events.concat(partOfEvents) + events = events.concat( + partOfEvents.map((event) => ({ + address: event.returnValues.who, + encryptedAccount: event.returnValues.data + })) + ) } fromBlock = toBlock toBlock += part diff --git a/store/application.js b/store/application.js index ec147e0..296832c 100644 --- a/store/application.js +++ b/store/application.js @@ -488,23 +488,27 @@ const actions = { deployedBlock = lastSyncBlock } - let NUMBER_PARTS = hasCache ? 2 : 10 + const blockDifference = Math.ceil(currentBlockNumber - deployedBlock) + const divisor = hasCache ? 2 : 10 + + let blockRange = blockDifference > divisor ? blockDifference / divisor : blockDifference if (Number(netId) === 56) { - NUMBER_PARTS = parseInt((currentBlockNumber - deployedBlock) / 4950) || 1 + blockRange = 4950 } - const part = parseInt((currentBlockNumber - deployedBlock) / NUMBER_PARTS) + let numberParts = blockDifference === 0 ? 1 : Math.ceil(blockDifference / blockRange) + const part = Math.ceil(blockDifference / numberParts) let fromBlock = deployedBlock let toBlock = deployedBlock + part if (toBlock >= currentBlockNumber || toBlock === deployedBlock) { toBlock = 'latest' - NUMBER_PARTS = 1 + numberParts = 1 } - for (let i = 0; i < NUMBER_PARTS; i++) { + for (let i = 0; i < numberParts; i++) { const partOfEvents = await contractInstance.getPastEvents('EncryptedNote', { toBlock, fromBlock