From d881df99b1cb6ce2eaaf105debc8d00e9ba0863d Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Mon, 8 Jan 2024 21:04:31 +0200 Subject: [PATCH] fix: no need to skip claims for after-fix epochs --- scripts/gas-refund-program/staking/2.0/fix.ts | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/gas-refund-program/staking/2.0/fix.ts b/scripts/gas-refund-program/staking/2.0/fix.ts index 853a08ad..a5311501 100644 --- a/scripts/gas-refund-program/staking/2.0/fix.ts +++ b/scripts/gas-refund-program/staking/2.0/fix.ts @@ -56,23 +56,30 @@ async function _loadEpochToStartFrom(): Promise<{ if (!lastEthereumDistribution) throw new Error('lastEthereumDistribution is undefined'); + // if last saved distribution is AFTER the fix was applied - no need to be in the compatibility mode, do count all claims + const isProcessingLegacyEpoch = + lastEthereumDistribution <= EPOCH_WHEN_FIX_WAS_APPLIED; + // after-fix epochs return { epochToStartFrom: lastEthereumDistribution + 1, // start from the currently indexed epoch (i.e. next one after the last indexed one) // this filter is intended to replicate legacy behaviour for past pre-fix epochs - filterSePSP1ClaimTimeseriesOnInit: item => { - // if it's root computation script - suppress claims before the epoch of the fix - if (IS_COMPUTATION_SCRIPT) - return EPOCH_WHEN_FIX_WAS_APPLIED_MS <= item.timestamp; + filterSePSP1ClaimTimeseriesOnInit: isProcessingLegacyEpoch + ? item => { + // if it's root computation script - suppress claims before the epoch of the fix + if (IS_COMPUTATION_SCRIPT) + return EPOCH_WHEN_FIX_WAS_APPLIED_MS <= item.timestamp; - // if it's indexing routine - suppress all claims between last distribution on fantom and the epoch of the fix - const shouldBeSkipped = - LAST_EPOCH_DISTRIBUTED_ON_FANTOM_MS <= item.timestamp && - item.timestamp <= EPOCH_WHEN_FIX_WAS_APPLIED_MS; + // if it's indexing routine - only count claims between last distribution on fantom and the epoch of the fix + const shouldCount = + LAST_EPOCH_DISTRIBUTED_ON_FANTOM_MS <= item.timestamp && + item.timestamp <= EPOCH_WHEN_FIX_WAS_APPLIED_MS; - return shouldBeSkipped; - }, + return shouldCount; + } + : // no need to skip any claims for after-fix epochs + () => true, }; } export const loadEpochToStartFromWithFix = pMemoize(_loadEpochToStartFrom, {