From e5a024d7787f3b6ed4943e478b71e0d617a7b542 Mon Sep 17 00:00:00 2001 From: alenabelium <33514602+alenabelium@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:32:04 +0200 Subject: [PATCH 1/9] contract change handling --- libs/ftso-core/src/DataManagerForRewarding.ts | 10 ++ libs/ftso-core/src/IndexerClient.ts | 129 ++++++++++++++---- .../src/IndexerClientForRewarding.ts | 73 +++++++++- libs/ftso-core/src/configs/networks.ts | 36 ++--- .../reward-calculation/reward-calculation.ts | 40 +++++- .../reward-calculation/reward-fast-updates.ts | 1 + 6 files changed, 238 insertions(+), 51 deletions(-) diff --git a/libs/ftso-core/src/DataManagerForRewarding.ts b/libs/ftso-core/src/DataManagerForRewarding.ts index 3cebef63..bbb19ab4 100644 --- a/libs/ftso-core/src/DataManagerForRewarding.ts +++ b/libs/ftso-core/src/DataManagerForRewarding.ts @@ -318,6 +318,16 @@ export class DataManagerForRewarding extends DataManager { for (let votingRoundId = firstVotingRoundId; votingRoundId <= lastVotingRoundId; votingRoundId++) { const fastUpdateFeeds = feedValuesResponse.data[votingRoundId - firstVotingRoundId]; const fastUpdateSubmissions = feedUpdates.data[votingRoundId - firstVotingRoundId]; + // Handles the 'undefined' value in fastUpdateFeeds - this can happen on FastUpdater contract change + if(!fastUpdateFeeds) { + throw new Error(`FastUpdateFeeds is undefined for voting round ${votingRoundId}`); + } + + if (fastUpdateFeeds as any === "CONTRACT_CHANGE") { + result.push(undefined); + this.logger.error(`WARN: FastUpdateFeeds contract change for voting round ${votingRoundId}`); + continue; + } const value: FastUpdatesDataForVotingRound = { votingRoundId, feedValues: fastUpdateFeeds.feeds, diff --git a/libs/ftso-core/src/IndexerClient.ts b/libs/ftso-core/src/IndexerClient.ts index 0e7b9ac3..d727a281 100644 --- a/libs/ftso-core/src/IndexerClient.ts +++ b/libs/ftso-core/src/IndexerClient.ts @@ -5,6 +5,7 @@ import { Address, VotingEpochId } from "./voting-types"; import { IPayloadMessage } from "../../fsp-utils/src/PayloadMessage"; import { IRelayMessage } from "../../fsp-utils/src/RelayMessage"; +import { ContractDefinitions, ContractMethodNames } from "./configs/contracts"; import { CONTRACTS, EPOCH_SETTINGS, @@ -12,7 +13,6 @@ import { LAST_DATABASE_INDEX_STATE, networks, } from "./configs/networks"; -import { ContractDefinitions, ContractMethodNames } from "./configs/contracts"; import { FullVoterRegistrationInfo, InflationRewardsOffered, @@ -49,12 +49,14 @@ export type SubmissionData = GenericSubmissionData[]>; */ export interface FinalizationData extends GenericSubmissionData { successfulOnChain: boolean; + isOldRelay?: boolean; } /** * Parsed finalization data from finalization calls (relay()) on Relay contract. */ export interface ParsedFinalizationData extends GenericSubmissionData { successfulOnChain: boolean; + isOldRelay?: boolean; } /** @@ -137,7 +139,7 @@ export class IndexerClient { protected readonly entityManager: EntityManager, public readonly requiredHistoryTimeSec: number, protected readonly logger: ILogger - ) {} + ) { } protected readonly encoding = EncodingUtils.instance; @@ -394,17 +396,26 @@ export class IndexerClient { const result: TLPEvents[] = []; // TEMP CHANGE for upgrading Relay contract, can be removed in December 2024 - if (CONTRACTS.Relay.address == "0xA300E71257547e645CD7241987D3B75f2012E0E3") { - const oldRelay = { - ...CONTRACTS.Relay, - address: "0x32D46A1260BB2D8C9d5Ab1C9bBd7FF7D7CfaabCC", // Old Relay address for Coston - }; + const network = process.env.NETWORK as networks; - result.push(...(await this.queryEvents(oldRelay, eventName, fromStartTime))); + const oldSongbirdRelay = "0xbA35e39D01A3f5710d1e43FC61dbb738B68641c4"; + if (network == "songbird" && CONTRACTS.Relay.address != oldSongbirdRelay) { + this.logger.log(`Querying old Relay address for Songbird: ${oldSongbirdRelay}`); + result.push( + ...(await this.queryEvents({ ...CONTRACTS.Relay, address: oldSongbirdRelay }, eventName, fromStartTime)) + ); + } + const oldCostonRelay = "0x32D46A1260BB2D8C9d5Ab1C9bBd7FF7D7CfaabCC"; + if (network == "coston" && CONTRACTS.Relay.address != oldCostonRelay) { + this.logger.log(`Querying old Relay address for Coston: ${oldCostonRelay}`); + result.push( + ...(await this.queryEvents({ ...CONTRACTS.Relay, address: oldCostonRelay }, eventName, fromStartTime)) + ); } // END TEMP CHANGE result.push(...(await this.queryEvents(CONTRACTS.Relay, eventName, fromStartTime))); + IndexerClient.sortEvents(result); const data = result.map(event => SigningPolicyInitialized.fromRawEvent(event)); return { @@ -550,6 +561,7 @@ export class IndexerClient { /** * Queries indexer database for all finalization transactions on the Relay contract in a given timestamp range. * It returns the result if the indexer database ensures the data availability in the given timestamp range. + * The data may not be in order as it appears on blockchain. */ public async getFinalizationDataInRange( startTime: number, @@ -562,30 +574,101 @@ export class IndexerClient { data: [], }; } - const transactionsResults = await this.queryTransactions( + // TEMP CHANGE + let oldTransactionsResults: TLPTransaction[] = []; + let oldRelay: ContractDefinitions | undefined; + const network = process.env.NETWORK as networks; + + // Do this for every network with change + const oldCostonRelayAddress = "0x32D46A1260BB2D8C9d5Ab1C9bBd7FF7D7CfaabCC"; + if (network === "coston" && CONTRACTS.Relay.address != oldCostonRelayAddress) { + oldRelay = { + ...CONTRACTS.Relay, + address: oldCostonRelayAddress, + }; + } + + if (oldRelay !== undefined) { + oldTransactionsResults = await this.queryTransactions( + oldRelay, + ContractMethodNames.relay, + startTime, + endTime + ); + } + // END TEMP CHANGE + let newTransactionsResults = await this.queryTransactions( CONTRACTS.Relay, ContractMethodNames.relay, startTime, endTime ); - const finalizations: FinalizationData[] = transactionsResults.map(tx => { - const timestamp = tx.timestamp; - const votingEpochId = EPOCH_SETTINGS().votingEpochForTimeSec(timestamp); - return { - submitAddress: "0x" + tx.from_address, - relativeTimestamp: timestamp - EPOCH_SETTINGS().votingEpochStartSec(votingEpochId), - votingEpochIdFromTimestamp: votingEpochId, - transactionIndex: tx.transaction_index, - timestamp, - blockNumber: tx.block_number, - messages: tx.input, - successfulOnChain: tx.status > 0, - } as FinalizationData; - }); + + interface Pair { + address: string | undefined; + transactionsResults: TLPTransaction[]; + } + const jointTransactionResults: Pair[] = [ + { + address: oldRelay?.address, + transactionsResults: oldTransactionsResults + }, + { + address: CONTRACTS.Relay.address, + transactionsResults: newTransactionsResults + } + ]; + + let finalizations: FinalizationData[] = []; + for (let txListPair of jointTransactionResults) { + const { address, transactionsResults } = txListPair; + const isOldRelay = oldRelay !== undefined && address === oldRelay.address; + const tmpFinalizations: FinalizationData[] = transactionsResults.map(tx => { + const timestamp = tx.timestamp; + const votingEpochId = EPOCH_SETTINGS().votingEpochForTimeSec(timestamp); + return { + submitAddress: "0x" + tx.from_address, + relativeTimestamp: timestamp - EPOCH_SETTINGS().votingEpochStartSec(votingEpochId), + votingEpochIdFromTimestamp: votingEpochId, + transactionIndex: tx.transaction_index, + timestamp, + blockNumber: tx.block_number, + messages: tx.input, + successfulOnChain: tx.status > 0, + isOldRelay + } as FinalizationData; + }); + finalizations = finalizations.concat(tmpFinalizations); + } return { status: ensureRange, data: finalizations, }; } + + + public static sortEvents(events: TLPEvents[]): TLPEvents[] { + return events.sort((a, b) => { + if (a.timestamp < b.timestamp) { + return -1; + } + if (a.timestamp > b.timestamp) { + return 1; + } + if (a.block_number < b.block_number) { + return -1; + } + if (a.block_number > b.block_number) { + return 1; + } + if (a.log_index < b.log_index) { + return -1; + } + if (a.log_index > b.log_index) { + return 1; + } + return 0; + }); + } } diff --git a/libs/ftso-core/src/IndexerClientForRewarding.ts b/libs/ftso-core/src/IndexerClientForRewarding.ts index bedaf466..418abdbd 100644 --- a/libs/ftso-core/src/IndexerClientForRewarding.ts +++ b/libs/ftso-core/src/IndexerClientForRewarding.ts @@ -1,11 +1,12 @@ import { EntityManager } from "typeorm"; import { BlockAssuranceResult, IndexerClient, IndexerResponse } from "./IndexerClient"; import { ILogger } from "./utils/ILogger"; -import { CONTRACTS, EPOCH_SETTINGS } from "./configs/networks"; +import { CONTRACTS, EPOCH_SETTINGS, networks } from "./configs/networks"; import { FastUpdateFeeds } from "./events/FastUpdateFeeds"; import { FastUpdateFeedsSubmitted } from "./events/FastUpdateFeedsSubmitted"; import { IncentiveOffered } from "./events/IncentiveOffered"; import { FUInflationRewardsOffered } from "./events/FUInflationRewardsOffered"; +import { TLPEvents } from "./orm/entities"; export class IndexerClientForRewarding extends IndexerClient { constructor( @@ -28,12 +29,37 @@ export class IndexerClientForRewarding extends IndexerClient { const endTime = EPOCH_SETTINGS().votingEpochStartSec(endVotingRoundId + 2); const eventName = FastUpdateFeeds.eventName; const status = await this.ensureEventRange(startTime, endTime); - const result = await this.queryEvents(CONTRACTS.FastUpdater, eventName, startTime, endTime); - - const data: FastUpdateFeeds[] = []; if (status !== BlockAssuranceResult.OK) { return { status }; } + + const result: TLPEvents[] = []; + + // TEMP CHANGE for upgrading Relay contract, can be removed in December 2024 + const network = process.env.NETWORK as networks; + + const oldSongbirdFastUpdater = "0x70e8870ef234EcD665F96Da4c669dc12c1e1c116"; + if (network == "songbird" && CONTRACTS.Relay.address != oldSongbirdFastUpdater) { + this.logger.log(`Querying old FastUpdater address for Songbird: ${oldSongbirdFastUpdater}`); + result.push( + ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldSongbirdFastUpdater }, eventName, startTime, endTime)) + ); + } + + const oldCostonFastUpdater = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9"; + if (network == "coston" && CONTRACTS.Relay.address !== oldCostonFastUpdater) { + this.logger.log(`Querying old FastUpdater address for Coston: ${oldCostonFastUpdater}`); + result.push( + ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldCostonFastUpdater }, eventName, startTime, endTime)) + ); + } + + // END TEMP CHANGE + + result.push(...(await this.queryEvents(CONTRACTS.FastUpdater, eventName, startTime, endTime))); + IndexerClient.sortEvents(result); + + const data: FastUpdateFeeds[] = []; let processed = -1; for (let i = 0; i < result.length; i++) { const event = FastUpdateFeeds.fromRawEvent(result[i]); @@ -43,6 +69,18 @@ export class IndexerClientForRewarding extends IndexerClient { data.push(event); processed = event.votingRoundId; } else { + // this.logger.error(`Missing FastUpdateFeeds event: expected ${processed + 1}, got ${event.votingRoundId}`); + // processed++; + if(network == "coston" && processed + 1 == 779191) { + while(processed + 1 < event.votingRoundId) { + this.logger.error(`Missing FastUpdateFeeds event for Coston: ${processed + 1}`); + data.push("CONTRACT_CHANGE" as any); + processed++; + } + data.push(event); + processed++; + continue; + } throw new Error( `FastUpdateFeeds events are not continuous from ${startVotingRoundId} to ${endVotingRoundId}: expected ${ processed + 1 @@ -73,10 +111,35 @@ export class IndexerClientForRewarding extends IndexerClient { const endTime = EPOCH_SETTINGS().votingEpochStartSec(endVotingRoundId + 1); const eventName = FastUpdateFeedsSubmitted.eventName; const status = await this.ensureEventRange(startTime, endTime); - const result = await this.queryEvents(CONTRACTS.FastUpdater, eventName, startTime, endTime); if (status !== BlockAssuranceResult.OK) { return { status }; } + + const result: TLPEvents[] = []; + + // TEMP CHANGE for upgrading Relay contract, can be removed in December 2024 + const network = process.env.NETWORK as networks; + + const oldSongbirdFastUpdater = "0x70e8870ef234EcD665F96Da4c669dc12c1e1c116"; + if (network == "songbird" && CONTRACTS.Relay.address != oldSongbirdFastUpdater) { + this.logger.log(`Querying old FastUpdater address for Songbird: ${oldSongbirdFastUpdater}`); + result.push( + ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldSongbirdFastUpdater }, eventName, startTime, endTime)) + ); + } + + const oldCostonFastUpdater = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9"; + if (network == "coston" && CONTRACTS.Relay.address !== oldCostonFastUpdater) { + this.logger.log(`Querying old FastUpdater address for Coston: ${oldCostonFastUpdater}`); + result.push( + ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldCostonFastUpdater }, eventName, startTime, endTime)) + ); + } + + // END TEMP CHANGE + + result.push(...(await this.queryEvents(CONTRACTS.FastUpdater, eventName, startTime, endTime))); + IndexerClient.sortEvents(result); const votingRoundIdToEvents = new Map(); for (let i = 0; i < result.length; i++) { diff --git a/libs/ftso-core/src/configs/networks.ts b/libs/ftso-core/src/configs/networks.ts index 828d0fa0..78630c1a 100644 --- a/libs/ftso-core/src/configs/networks.ts +++ b/libs/ftso-core/src/configs/networks.ts @@ -27,7 +27,7 @@ const COSTON_CONFIG: NetworkContractAddresses = { VoterRegistry: { name: "VoterRegistry", address: "0xE2c06DF29d175Aa0EcfcD10134eB96f8C94448A3" }, FtsoMerkleStructs: { name: "FtsoMerkleStructs", address: "" }, ProtocolMerkleStructs: { name: "ProtocolMerkleStructs", address: "" }, - FastUpdater: { name: "FastUpdater", address: "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9" }, + FastUpdater: { name: "FastUpdater", address: "0xB8336A96b4b8af89f60EA080002214191Bc8293A" }, FastUpdateIncentiveManager: { name: "FastUpdateIncentiveManager", address: "0x8c45666369B174806E1AB78D989ddd79a3267F3b", @@ -54,14 +54,14 @@ const COSTON2_CONFIG: NetworkContractAddresses = { const SONGBIRD_CONFIG: NetworkContractAddresses = { FlareSystemsManager: { name: "FlareSystemsManager", address: "0x421c69E22f48e14Fc2d2Ee3812c59bfb81c38516" }, FtsoRewardOffersManager: { name: "FtsoRewardOffersManager", address: "0x5aB9cB258a342001C4663D9526A1c54cCcF8C545" }, - RewardManager: { name: "RewardManager", address: "0x8A80583BD5A5Cd8f68De585163259D61Ea8dc904" }, + RewardManager: { name: "RewardManager", address: "0xE26AD68b17224951b5740F33926Cc438764eB9a7" }, Submission: { name: "Submission", address: "0x2cA6571Daa15ce734Bbd0Bf27D5C9D16787fc33f" }, - Relay: { name: "Relay", address: "0xbA35e39D01A3f5710d1e43FC61dbb738B68641c4" }, + Relay: { name: "Relay", address: "0x0D462d2Fec11554D64F52D7c5A5C269d748037aD" }, FlareSystemsCalculator: { name: "FlareSystemsCalculator", address: "0x126FAeEc75601dA3354c0b5Cc0b60C85fCbC3A5e" }, VoterRegistry: { name: "VoterRegistry", address: "0x31B9EC65C731c7D973a33Ef3FC83B653f540dC8D" }, FtsoMerkleStructs: { name: "FtsoMerkleStructs", address: "" }, ProtocolMerkleStructs: { name: "ProtocolMerkleStructs", address: "" }, - FastUpdater: { name: "FastUpdater", address: "0x70e8870ef234EcD665F96Da4c669dc12c1e1c116" }, + FastUpdater: { name: "FastUpdater", address: "0x7D9F73FD9bC4607daCB618FF895585f98BFDD06B" }, FastUpdateIncentiveManager: { name: "FastUpdateIncentiveManager", address: "0x596C70Ad6fFFdb9b6158F1Dfd0bc32cc72B82006", @@ -159,7 +159,7 @@ const contracts = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -185,7 +185,7 @@ const ftso2ProtocolId = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -205,7 +205,7 @@ const ftso2FastUpdatesProtocolId = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -266,7 +266,7 @@ const epochSettings = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -310,7 +310,7 @@ const randomGenerationBenchingWindow = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -345,7 +345,7 @@ const initialRewardEpochId = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -364,7 +364,7 @@ const burnAddress = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -388,7 +388,7 @@ const additionalRewardFinalizationWindows = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -457,7 +457,7 @@ const penaltyFactor = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -493,7 +493,7 @@ const gracePeriodForSignaturesDurationSec = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -531,7 +531,7 @@ const gracePeriodForFinalizationDurationSec = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -584,7 +584,7 @@ const minimalRewardedNonConsensusDepositedSignaturesPerHashBips = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -619,7 +619,7 @@ const finalizationVoterSelectionThresholdWeightBips = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; @@ -658,7 +658,7 @@ export const CALCULATIONS_FOLDER = () => { default: // Ensure exhaustive checking // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars - ((_: never): void => {})(network); + ((_: never): void => { })(network); } }; diff --git a/libs/ftso-core/src/reward-calculation/reward-calculation.ts b/libs/ftso-core/src/reward-calculation/reward-calculation.ts index 2532feb9..3d37d4cc 100644 --- a/libs/ftso-core/src/reward-calculation/reward-calculation.ts +++ b/libs/ftso-core/src/reward-calculation/reward-calculation.ts @@ -1,11 +1,13 @@ import { DataAvailabilityStatus, DataManager } from "../DataManager"; import { RewardEpochManager } from "../RewardEpochManager"; import { + BURN_ADDRESS, CALCULATIONS_FOLDER, + FEEDS_RENAMING_FILE, FINALIZATION_VOTER_SELECTION_THRESHOLD_WEIGHT_BIPS, + FTSO2_FAST_UPDATES_PROTOCOL_ID, FTSO2_PROTOCOL_ID, PENALTY_FACTOR, - FEEDS_RENAMING_FILE, } from "../configs/networks"; import { calculateMedianResults } from "../ftso-calculation/ftso-median"; import { ClaimType, IMergeableRewardClaim, IPartialRewardClaim, IRewardClaim, RewardClaim } from "../utils/RewardClaim"; @@ -18,11 +20,13 @@ import { calculateFinalizationRewardClaims } from "./reward-finalization"; import { calculateMedianRewardClaims } from "./reward-median"; import { splitRewardOfferByTypes } from "./reward-offers"; +import { existsSync, readFileSync } from "fs"; import { DataManagerForRewarding } from "../DataManagerForRewarding"; import { RewardEpoch } from "../RewardEpoch"; import { FUFeedValue } from "../data-calculation-interfaces"; import { FastUpdateFeedConfiguration } from "../events/FUInflationRewardsOffered"; import { calculateRandom } from "../ftso-calculation/ftso-random"; +import { ILogger } from "../utils/ILogger"; import { MerkleTreeStructs } from "../utils/MerkleTreeStructs"; import { IPartialRewardOfferForRound } from "../utils/PartialRewardOffer"; import { @@ -46,11 +50,9 @@ import { serializeDataForRewardCalculation, } from "../utils/stat-info/reward-calculation-data"; import { deserializeRewardEpochInfo } from "../utils/stat-info/reward-epoch-info"; -import { calculateFastUpdatesClaims } from "./reward-fast-updates"; +import { FastUpdatesRewardClaimType, calculateFastUpdatesClaims } from "./reward-fast-updates"; import { calculatePenalties } from "./reward-penalties"; import { calculateSigningRewards } from "./reward-signing"; -import { ILogger } from "../utils/ILogger"; -import { existsSync, readFileSync } from "fs"; /** * Initializes reward epoch storage for the given reward epoch. @@ -230,7 +232,35 @@ export async function partialRewardClaimsForVotingRound( } } } - if (useFastUpdatesData) { + const network = process.env.NETWORK; + const isContractChange = network == "coston" && votingRoundId == 779191; + + if (useFastUpdatesData && isContractChange) { + const fuFeedOffers = deserializeGranulatedPartialOfferMapForFastUpdates( + rewardEpochId, + votingRoundId, + calculationFolder + ); + for (const [feedId, offers] of fuFeedOffers.entries()) { + for (const offer of offers) { + allRewardClaims.push({ + votingRoundId: offer.votingRoundId, + beneficiary: BURN_ADDRESS, + amount: offer.amount, + claimType: ClaimType.DIRECT, + offerIndex: 0, + // feedId: offer.feedId, // should be undefined + protocolTag: "" + FTSO2_FAST_UPDATES_PROTOCOL_ID, + rewardTypeTag: RewardTypePrefix.FULL_OFFER_CLAIM_BACK, + rewardDetailTag: FastUpdatesRewardClaimType.CONTRACT_CHANGE, + }); + } + } + if (merge) { + allRewardClaims = RewardClaim.merge(allRewardClaims); + } + } + if (useFastUpdatesData && !isContractChange) { const fuFeedOffers = deserializeGranulatedPartialOfferMapForFastUpdates( rewardEpochId, votingRoundId, diff --git a/libs/ftso-core/src/reward-calculation/reward-fast-updates.ts b/libs/ftso-core/src/reward-calculation/reward-fast-updates.ts index 4dcf3d04..a7b47874 100644 --- a/libs/ftso-core/src/reward-calculation/reward-fast-updates.ts +++ b/libs/ftso-core/src/reward-calculation/reward-fast-updates.ts @@ -15,6 +15,7 @@ export enum FastUpdatesRewardClaimType { MISSED_BAND = "MISSING_BAND", FEE = "FEE", PARTICIPATION = "PARTICIPATION", + CONTRACT_CHANGE = "CONTRACT_CHANGE", } /** From 69cf27ce3690df158003c0ae9c8981247d750ce8 Mon Sep 17 00:00:00 2001 From: alenabelium <33514602+alenabelium@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:16:49 +0200 Subject: [PATCH 2/9] filtering --- libs/ftso-core/src/IndexerClientForRewarding.ts | 9 ++++----- libs/ftso-core/src/configs/networks.ts | 4 +++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/ftso-core/src/IndexerClientForRewarding.ts b/libs/ftso-core/src/IndexerClientForRewarding.ts index 418abdbd..98e02ff6 100644 --- a/libs/ftso-core/src/IndexerClientForRewarding.ts +++ b/libs/ftso-core/src/IndexerClientForRewarding.ts @@ -1,13 +1,12 @@ import { EntityManager } from "typeorm"; import { BlockAssuranceResult, IndexerClient, IndexerResponse } from "./IndexerClient"; import { ILogger } from "./utils/ILogger"; -import { CONTRACTS, EPOCH_SETTINGS, networks } from "./configs/networks"; +import { CONTRACTS, COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID, EPOCH_SETTINGS, networks } from "./configs/networks"; import { FastUpdateFeeds } from "./events/FastUpdateFeeds"; import { FastUpdateFeedsSubmitted } from "./events/FastUpdateFeedsSubmitted"; import { IncentiveOffered } from "./events/IncentiveOffered"; import { FUInflationRewardsOffered } from "./events/FUInflationRewardsOffered"; import { TLPEvents } from "./orm/entities"; - export class IndexerClientForRewarding extends IndexerClient { constructor( protected readonly entityManager: EntityManager, @@ -47,7 +46,7 @@ export class IndexerClientForRewarding extends IndexerClient { } const oldCostonFastUpdater = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9"; - if (network == "coston" && CONTRACTS.Relay.address !== oldCostonFastUpdater) { + if (network == "coston" && CONTRACTS.Relay.address !== oldCostonFastUpdater && startVotingRoundId <= COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { this.logger.log(`Querying old FastUpdater address for Coston: ${oldCostonFastUpdater}`); result.push( ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldCostonFastUpdater }, eventName, startTime, endTime)) @@ -71,7 +70,7 @@ export class IndexerClientForRewarding extends IndexerClient { } else { // this.logger.error(`Missing FastUpdateFeeds event: expected ${processed + 1}, got ${event.votingRoundId}`); // processed++; - if(network == "coston" && processed + 1 == 779191) { + if(network == "coston" && processed + 1 == COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { while(processed + 1 < event.votingRoundId) { this.logger.error(`Missing FastUpdateFeeds event for Coston: ${processed + 1}`); data.push("CONTRACT_CHANGE" as any); @@ -129,7 +128,7 @@ export class IndexerClientForRewarding extends IndexerClient { } const oldCostonFastUpdater = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9"; - if (network == "coston" && CONTRACTS.Relay.address !== oldCostonFastUpdater) { + if (network == "coston" && CONTRACTS.Relay.address !== oldCostonFastUpdater && startVotingRoundId <= COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { this.logger.log(`Querying old FastUpdater address for Coston: ${oldCostonFastUpdater}`); result.push( ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldCostonFastUpdater }, eventName, startTime, endTime)) diff --git a/libs/ftso-core/src/configs/networks.ts b/libs/ftso-core/src/configs/networks.ts index 78630c1a..6e3ac3ac 100644 --- a/libs/ftso-core/src/configs/networks.ts +++ b/libs/ftso-core/src/configs/networks.ts @@ -20,7 +20,7 @@ const TEST_CONFIG: NetworkContractAddresses = { const COSTON_CONFIG: NetworkContractAddresses = { FlareSystemsManager: { name: "FlareSystemsManager", address: "0x85680Dd93755Fe5d0789773fd0896cEE51F9e358" }, FtsoRewardOffersManager: { name: "FtsoRewardOffersManager", address: "0xC9534cB913150aD3e98D792857689B55e2404212" }, - RewardManager: { name: "RewardManager", address: "0xA17197b7Bdff7Be7c3Da39ec08981FB716B70d3A" }, + RewardManager: { name: "RewardManager", address: "0x2ade9972E7f27200872D378acF7a1BaD8D696FC5" }, Submission: { name: "Submission", address: "0x2cA6571Daa15ce734Bbd0Bf27D5C9D16787fc33f" }, Relay: { name: "Relay", address: "0xA300E71257547e645CD7241987D3B75f2012E0E3" }, FlareSystemsCalculator: { name: "FlareSystemsCalculator", address: "0x43CBAB9C953F54533aadAf7ffCD13c30ec05Edc9" }, @@ -665,3 +665,5 @@ export const CALCULATIONS_FOLDER = () => { export const FEEDS_RENAMING_FILE = () => "libs/ftso-core/src/reward-calculation/feeds-renaming.json"; export const FUTURE_VOTING_ROUNDS = () => 30; + +export const COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID = 779191; From 8e816c241fcaf6511c052b63cf003d89ac755e9c Mon Sep 17 00:00:00 2001 From: alenabelium <33514602+alenabelium@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:01:45 +0200 Subject: [PATCH 3/9] fixes --- libs/ftso-core/src/IndexerClient.ts | 8 ++++++++ libs/ftso-core/src/IndexerClientForRewarding.ts | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/ftso-core/src/IndexerClient.ts b/libs/ftso-core/src/IndexerClient.ts index d727a281..5f791d35 100644 --- a/libs/ftso-core/src/IndexerClient.ts +++ b/libs/ftso-core/src/IndexerClient.ts @@ -588,6 +588,14 @@ export class IndexerClient { }; } + const oldSongbirdRelayAddress = "0xbA35e39D01A3f5710d1e43FC61dbb738B68641c4"; + if (network === "songbird" && CONTRACTS.Relay.address != oldSongbirdRelayAddress) { + oldRelay = { + ...CONTRACTS.Relay, + address: oldSongbirdRelayAddress, + }; + } + if (oldRelay !== undefined) { oldTransactionsResults = await this.queryTransactions( oldRelay, diff --git a/libs/ftso-core/src/IndexerClientForRewarding.ts b/libs/ftso-core/src/IndexerClientForRewarding.ts index 98e02ff6..b6779b89 100644 --- a/libs/ftso-core/src/IndexerClientForRewarding.ts +++ b/libs/ftso-core/src/IndexerClientForRewarding.ts @@ -38,7 +38,7 @@ export class IndexerClientForRewarding extends IndexerClient { const network = process.env.NETWORK as networks; const oldSongbirdFastUpdater = "0x70e8870ef234EcD665F96Da4c669dc12c1e1c116"; - if (network == "songbird" && CONTRACTS.Relay.address != oldSongbirdFastUpdater) { + if (network == "songbird" && CONTRACTS.FastUpdater.address != oldSongbirdFastUpdater) { this.logger.log(`Querying old FastUpdater address for Songbird: ${oldSongbirdFastUpdater}`); result.push( ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldSongbirdFastUpdater }, eventName, startTime, endTime)) @@ -46,7 +46,7 @@ export class IndexerClientForRewarding extends IndexerClient { } const oldCostonFastUpdater = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9"; - if (network == "coston" && CONTRACTS.Relay.address !== oldCostonFastUpdater && startVotingRoundId <= COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { + if (network == "coston" && CONTRACTS.FastUpdater.address !== oldCostonFastUpdater && startVotingRoundId <= COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { this.logger.log(`Querying old FastUpdater address for Coston: ${oldCostonFastUpdater}`); result.push( ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldCostonFastUpdater }, eventName, startTime, endTime)) @@ -120,7 +120,7 @@ export class IndexerClientForRewarding extends IndexerClient { const network = process.env.NETWORK as networks; const oldSongbirdFastUpdater = "0x70e8870ef234EcD665F96Da4c669dc12c1e1c116"; - if (network == "songbird" && CONTRACTS.Relay.address != oldSongbirdFastUpdater) { + if (network == "songbird" && CONTRACTS.FastUpdater.address != oldSongbirdFastUpdater) { this.logger.log(`Querying old FastUpdater address for Songbird: ${oldSongbirdFastUpdater}`); result.push( ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldSongbirdFastUpdater }, eventName, startTime, endTime)) @@ -128,7 +128,7 @@ export class IndexerClientForRewarding extends IndexerClient { } const oldCostonFastUpdater = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9"; - if (network == "coston" && CONTRACTS.Relay.address !== oldCostonFastUpdater && startVotingRoundId <= COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { + if (network == "coston" && CONTRACTS.FastUpdater.address !== oldCostonFastUpdater && startVotingRoundId <= COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { this.logger.log(`Querying old FastUpdater address for Coston: ${oldCostonFastUpdater}`); result.push( ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldCostonFastUpdater }, eventName, startTime, endTime)) From 21de0b3b248a710886c8b502fad1a52482e0bbcf Mon Sep 17 00:00:00 2001 From: alenabelium <33514602+alenabelium@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:19:30 +0200 Subject: [PATCH 4/9] fix for second relay contract --- libs/ftso-core/src/IndexerClient.ts | 55 +++++++++++++++++++++++++- libs/ftso-core/src/configs/networks.ts | 2 +- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/libs/ftso-core/src/IndexerClient.ts b/libs/ftso-core/src/IndexerClient.ts index 5f791d35..82510341 100644 --- a/libs/ftso-core/src/IndexerClient.ts +++ b/libs/ftso-core/src/IndexerClient.ts @@ -405,6 +405,15 @@ export class IndexerClient { ...(await this.queryEvents({ ...CONTRACTS.Relay, address: oldSongbirdRelay }, eventName, fromStartTime)) ); } + + // const secondOldSongbirdRelay = "0x0D462d2Fec11554D64F52D7c5A5C269d748037aD"; + // if (network == "songbird" && CONTRACTS.Relay.address != secondOldSongbirdRelay) { + // this.logger.log(`Querying second old Relay address for Songbird: ${secondOldSongbirdRelay}`); + // result.push( + // ...(await this.queryEvents({ ...CONTRACTS.Relay, address: secondOldSongbirdRelay }, eventName, fromStartTime)) + // ); + // } + const oldCostonRelay = "0x32D46A1260BB2D8C9d5Ab1C9bBd7FF7D7CfaabCC"; if (network == "coston" && CONTRACTS.Relay.address != oldCostonRelay) { this.logger.log(`Querying old Relay address for Coston: ${oldCostonRelay}`); @@ -412,6 +421,15 @@ export class IndexerClient { ...(await this.queryEvents({ ...CONTRACTS.Relay, address: oldCostonRelay }, eventName, fromStartTime)) ); } + + // const secondOldCostonRelay = "0xA300E71257547e645CD7241987D3B75f2012E0E3"; + // if (network == "coston" && CONTRACTS.Relay.address != secondOldCostonRelay) { + // this.logger.log(`Querying second old Relay address for Coston: ${secondOldCostonRelay}`); + // result.push( + // ...(await this.queryEvents({ ...CONTRACTS.Relay, address: secondOldCostonRelay }, eventName, fromStartTime)) + // ); + // } + // END TEMP CHANGE result.push(...(await this.queryEvents(CONTRACTS.Relay, eventName, fromStartTime))); @@ -576,7 +594,9 @@ export class IndexerClient { } // TEMP CHANGE let oldTransactionsResults: TLPTransaction[] = []; + let secondOldTransactionsResults: TLPTransaction[] = []; let oldRelay: ContractDefinitions | undefined; + let secondOldRelay: ContractDefinitions | undefined; const network = process.env.NETWORK as networks; // Do this for every network with change @@ -588,6 +608,15 @@ export class IndexerClient { }; } + // const secondOldCostonRelayAddress = "0xA300E71257547e645CD7241987D3B75f2012E0E3"; + // if (network === "coston" && CONTRACTS.Relay.address != secondOldCostonRelayAddress) { + // secondOldRelay = { + // ...CONTRACTS.Relay, + // address: secondOldCostonRelayAddress, + // }; + // } + + const oldSongbirdRelayAddress = "0xbA35e39D01A3f5710d1e43FC61dbb738B68641c4"; if (network === "songbird" && CONTRACTS.Relay.address != oldSongbirdRelayAddress) { oldRelay = { @@ -595,6 +624,13 @@ export class IndexerClient { address: oldSongbirdRelayAddress, }; } + // const secondOldSongbirdRelayAddress = "0x0D462d2Fec11554D64F52D7c5A5C269d748037aD"; + // if (network === "songbird" && CONTRACTS.Relay.address != secondOldSongbirdRelayAddress) { + // secondOldRelay = { + // ...CONTRACTS.Relay, + // address: secondOldSongbirdRelayAddress, + // }; + // } if (oldRelay !== undefined) { oldTransactionsResults = await this.queryTransactions( @@ -604,6 +640,16 @@ export class IndexerClient { endTime ); } + + if (secondOldRelay !== undefined) { + secondOldTransactionsResults = await this.queryTransactions( + secondOldRelay, + ContractMethodNames.relay, + startTime, + endTime + ); + } + // END TEMP CHANGE let newTransactionsResults = await this.queryTransactions( CONTRACTS.Relay, @@ -621,6 +667,10 @@ export class IndexerClient { address: oldRelay?.address, transactionsResults: oldTransactionsResults }, + { + address: secondOldRelay?.address, + transactionsResults: secondOldTransactionsResults + }, { address: CONTRACTS.Relay.address, transactionsResults: newTransactionsResults @@ -630,7 +680,8 @@ export class IndexerClient { let finalizations: FinalizationData[] = []; for (let txListPair of jointTransactionResults) { const { address, transactionsResults } = txListPair; - const isOldRelay = oldRelay !== undefined && address === oldRelay.address; + const isOldRelay = (oldRelay !== undefined && address === oldRelay.address) + || (secondOldRelay !== undefined && address === secondOldRelay.address); const tmpFinalizations: FinalizationData[] = transactionsResults.map(tx => { const timestamp = tx.timestamp; const votingEpochId = EPOCH_SETTINGS().votingEpochForTimeSec(timestamp); @@ -646,7 +697,7 @@ export class IndexerClient { isOldRelay } as FinalizationData; }); - finalizations = finalizations.concat(tmpFinalizations); + finalizations.push(...tmpFinalizations); } return { diff --git a/libs/ftso-core/src/configs/networks.ts b/libs/ftso-core/src/configs/networks.ts index 6e3ac3ac..8e08c847 100644 --- a/libs/ftso-core/src/configs/networks.ts +++ b/libs/ftso-core/src/configs/networks.ts @@ -22,7 +22,7 @@ const COSTON_CONFIG: NetworkContractAddresses = { FtsoRewardOffersManager: { name: "FtsoRewardOffersManager", address: "0xC9534cB913150aD3e98D792857689B55e2404212" }, RewardManager: { name: "RewardManager", address: "0x2ade9972E7f27200872D378acF7a1BaD8D696FC5" }, Submission: { name: "Submission", address: "0x2cA6571Daa15ce734Bbd0Bf27D5C9D16787fc33f" }, - Relay: { name: "Relay", address: "0xA300E71257547e645CD7241987D3B75f2012E0E3" }, + Relay: { name: "Relay", address: "0x92a6E1127262106611e1e129BB64B6D8654273F7" }, FlareSystemsCalculator: { name: "FlareSystemsCalculator", address: "0x43CBAB9C953F54533aadAf7ffCD13c30ec05Edc9" }, VoterRegistry: { name: "VoterRegistry", address: "0xE2c06DF29d175Aa0EcfcD10134eB96f8C94448A3" }, FtsoMerkleStructs: { name: "FtsoMerkleStructs", address: "" }, From 3ac5d65143b54f6f22ba7cdccf8b82479d21ea0f Mon Sep 17 00:00:00 2001 From: alenabelium <33514602+alenabelium@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:23:06 +0200 Subject: [PATCH 5/9] enabling coston second old relay --- libs/ftso-core/src/IndexerClient.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libs/ftso-core/src/IndexerClient.ts b/libs/ftso-core/src/IndexerClient.ts index 82510341..8e5b2aad 100644 --- a/libs/ftso-core/src/IndexerClient.ts +++ b/libs/ftso-core/src/IndexerClient.ts @@ -422,13 +422,13 @@ export class IndexerClient { ); } - // const secondOldCostonRelay = "0xA300E71257547e645CD7241987D3B75f2012E0E3"; - // if (network == "coston" && CONTRACTS.Relay.address != secondOldCostonRelay) { - // this.logger.log(`Querying second old Relay address for Coston: ${secondOldCostonRelay}`); - // result.push( - // ...(await this.queryEvents({ ...CONTRACTS.Relay, address: secondOldCostonRelay }, eventName, fromStartTime)) - // ); - // } + const secondOldCostonRelay = "0xA300E71257547e645CD7241987D3B75f2012E0E3"; + if (network == "coston" && CONTRACTS.Relay.address != secondOldCostonRelay) { + this.logger.log(`Querying second old Relay address for Coston: ${secondOldCostonRelay}`); + result.push( + ...(await this.queryEvents({ ...CONTRACTS.Relay, address: secondOldCostonRelay }, eventName, fromStartTime)) + ); + } // END TEMP CHANGE @@ -608,13 +608,13 @@ export class IndexerClient { }; } - // const secondOldCostonRelayAddress = "0xA300E71257547e645CD7241987D3B75f2012E0E3"; - // if (network === "coston" && CONTRACTS.Relay.address != secondOldCostonRelayAddress) { - // secondOldRelay = { - // ...CONTRACTS.Relay, - // address: secondOldCostonRelayAddress, - // }; - // } + const secondOldCostonRelayAddress = "0xA300E71257547e645CD7241987D3B75f2012E0E3"; + if (network === "coston" && CONTRACTS.Relay.address != secondOldCostonRelayAddress) { + secondOldRelay = { + ...CONTRACTS.Relay, + address: secondOldCostonRelayAddress, + }; + } const oldSongbirdRelayAddress = "0xbA35e39D01A3f5710d1e43FC61dbb738B68641c4"; From f689b584700876d94ff0c295e7a639eb95301922 Mon Sep 17 00:00:00 2001 From: alenabelium <33514602+alenabelium@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:10:41 +0200 Subject: [PATCH 6/9] songbird preparation --- .../src/IndexerClientForRewarding.ts | 21 ++++++++++--------- libs/ftso-core/src/configs/networks.ts | 1 + 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libs/ftso-core/src/IndexerClientForRewarding.ts b/libs/ftso-core/src/IndexerClientForRewarding.ts index b6779b89..08d843cf 100644 --- a/libs/ftso-core/src/IndexerClientForRewarding.ts +++ b/libs/ftso-core/src/IndexerClientForRewarding.ts @@ -1,7 +1,7 @@ import { EntityManager } from "typeorm"; import { BlockAssuranceResult, IndexerClient, IndexerResponse } from "./IndexerClient"; import { ILogger } from "./utils/ILogger"; -import { CONTRACTS, COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID, EPOCH_SETTINGS, networks } from "./configs/networks"; +import { CONTRACTS, COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID, EPOCH_SETTINGS, SONGBIRD_FAST_UPDATER_SWITCH_VOTING_ROUND_ID, networks } from "./configs/networks"; import { FastUpdateFeeds } from "./events/FastUpdateFeeds"; import { FastUpdateFeedsSubmitted } from "./events/FastUpdateFeedsSubmitted"; import { IncentiveOffered } from "./events/IncentiveOffered"; @@ -33,12 +33,13 @@ export class IndexerClientForRewarding extends IndexerClient { } const result: TLPEvents[] = []; - + // TEMP CHANGE for upgrading Relay contract, can be removed in December 2024 const network = process.env.NETWORK as networks; - + const oldSongbirdFastUpdater = "0x70e8870ef234EcD665F96Da4c669dc12c1e1c116"; - if (network == "songbird" && CONTRACTS.FastUpdater.address != oldSongbirdFastUpdater) { + if (network == "songbird" && CONTRACTS.FastUpdater.address != oldSongbirdFastUpdater + && startVotingRoundId <= SONGBIRD_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { this.logger.log(`Querying old FastUpdater address for Songbird: ${oldSongbirdFastUpdater}`); result.push( ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldSongbirdFastUpdater }, eventName, startTime, endTime)) @@ -70,8 +71,9 @@ export class IndexerClientForRewarding extends IndexerClient { } else { // this.logger.error(`Missing FastUpdateFeeds event: expected ${processed + 1}, got ${event.votingRoundId}`); // processed++; - if(network == "coston" && processed + 1 == COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { - while(processed + 1 < event.votingRoundId) { + if ((network == "coston" && processed + 1 == COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) + || (network == "songbird" && processed + 1 == SONGBIRD_FAST_UPDATER_SWITCH_VOTING_ROUND_ID)) { + while (processed + 1 < event.votingRoundId) { this.logger.error(`Missing FastUpdateFeeds event for Coston: ${processed + 1}`); data.push("CONTRACT_CHANGE" as any); processed++; @@ -81,8 +83,7 @@ export class IndexerClientForRewarding extends IndexerClient { continue; } throw new Error( - `FastUpdateFeeds events are not continuous from ${startVotingRoundId} to ${endVotingRoundId}: expected ${ - processed + 1 + `FastUpdateFeeds events are not continuous from ${startVotingRoundId} to ${endVotingRoundId}: expected ${processed + 1 }, got ${event.votingRoundId}` ); } @@ -118,9 +119,9 @@ export class IndexerClientForRewarding extends IndexerClient { // TEMP CHANGE for upgrading Relay contract, can be removed in December 2024 const network = process.env.NETWORK as networks; - + const oldSongbirdFastUpdater = "0x70e8870ef234EcD665F96Da4c669dc12c1e1c116"; - if (network == "songbird" && CONTRACTS.FastUpdater.address != oldSongbirdFastUpdater) { + if (network == "songbird" && CONTRACTS.FastUpdater.address != oldSongbirdFastUpdater && startVotingRoundId <= SONGBIRD_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { this.logger.log(`Querying old FastUpdater address for Songbird: ${oldSongbirdFastUpdater}`); result.push( ...(await this.queryEvents({ ...CONTRACTS.FastUpdater, address: oldSongbirdFastUpdater }, eventName, startTime, endTime)) diff --git a/libs/ftso-core/src/configs/networks.ts b/libs/ftso-core/src/configs/networks.ts index a6a8cac0..ed200296 100644 --- a/libs/ftso-core/src/configs/networks.ts +++ b/libs/ftso-core/src/configs/networks.ts @@ -667,3 +667,4 @@ export const FEEDS_RENAMING_FILE = () => "libs/ftso-core/src/reward-calculation/ export const FUTURE_VOTING_ROUNDS = () => 30; export const COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID = 779191; +export const SONGBIRD_FAST_UPDATER_SWITCH_VOTING_ROUND_ID = 99999999999999; // temporary set to very high to not have effect From a52ccd990d7af1b4f244ce6b3f22dff489b868a1 Mon Sep 17 00:00:00 2001 From: alenabelium <33514602+alenabelium@users.noreply.github.com> Date: Thu, 17 Oct 2024 23:07:34 +0200 Subject: [PATCH 7/9] interval fix --- libs/ftso-core/src/IndexerClientForRewarding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/ftso-core/src/IndexerClientForRewarding.ts b/libs/ftso-core/src/IndexerClientForRewarding.ts index 08d843cf..ed392a4a 100644 --- a/libs/ftso-core/src/IndexerClientForRewarding.ts +++ b/libs/ftso-core/src/IndexerClientForRewarding.ts @@ -108,7 +108,7 @@ export class IndexerClientForRewarding extends IndexerClient { endVotingRoundId: number ): Promise> { const startTime = EPOCH_SETTINGS().votingEpochStartSec(startVotingRoundId); - const endTime = EPOCH_SETTINGS().votingEpochStartSec(endVotingRoundId + 1); + const endTime = EPOCH_SETTINGS().votingEpochStartSec(endVotingRoundId + 1) - 1; const eventName = FastUpdateFeedsSubmitted.eventName; const status = await this.ensureEventRange(startTime, endTime); if (status !== BlockAssuranceResult.OK) { From ea3b95621212b960f26dbc83fbe9f1ea2a6b6b96 Mon Sep 17 00:00:00 2001 From: alenabelium <33514602+alenabelium@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:28:05 +0200 Subject: [PATCH 8/9] enabling second old relay --- libs/ftso-core/src/IndexerClient.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libs/ftso-core/src/IndexerClient.ts b/libs/ftso-core/src/IndexerClient.ts index fea7c88a..e83102d9 100644 --- a/libs/ftso-core/src/IndexerClient.ts +++ b/libs/ftso-core/src/IndexerClient.ts @@ -624,13 +624,14 @@ export class IndexerClient { address: oldSongbirdRelayAddress, }; } - // const secondOldSongbirdRelayAddress = "0x0D462d2Fec11554D64F52D7c5A5C269d748037aD"; - // if (network === "songbird" && CONTRACTS.Relay.address != secondOldSongbirdRelayAddress) { - // secondOldRelay = { - // ...CONTRACTS.Relay, - // address: secondOldSongbirdRelayAddress, - // }; - // } + + const secondOldSongbirdRelayAddress = "0x0D462d2Fec11554D64F52D7c5A5C269d748037aD"; + if (network === "songbird" && CONTRACTS.Relay.address != secondOldSongbirdRelayAddress) { + secondOldRelay = { + ...CONTRACTS.Relay, + address: secondOldSongbirdRelayAddress, + }; + } if (oldRelay !== undefined) { oldTransactionsResults = await this.queryTransactions( From 00303e96dc1e7ca4fd5427c30ed2c62ced3d05fe Mon Sep 17 00:00:00 2001 From: alenabelium <33514602+alenabelium@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:51:38 +0200 Subject: [PATCH 9/9] clean up --- libs/ftso-core/src/IndexerClientForRewarding.ts | 6 ++---- libs/ftso-core/src/configs/networks.ts | 7 ++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/ftso-core/src/IndexerClientForRewarding.ts b/libs/ftso-core/src/IndexerClientForRewarding.ts index ed392a4a..d47990ba 100644 --- a/libs/ftso-core/src/IndexerClientForRewarding.ts +++ b/libs/ftso-core/src/IndexerClientForRewarding.ts @@ -69,10 +69,8 @@ export class IndexerClientForRewarding extends IndexerClient { data.push(event); processed = event.votingRoundId; } else { - // this.logger.error(`Missing FastUpdateFeeds event: expected ${processed + 1}, got ${event.votingRoundId}`); - // processed++; - if ((network == "coston" && processed + 1 == COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) - || (network == "songbird" && processed + 1 == SONGBIRD_FAST_UPDATER_SWITCH_VOTING_ROUND_ID)) { + // On Coston one event is missing hence special handling + if (network == "coston" && processed + 1 == COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) { while (processed + 1 < event.votingRoundId) { this.logger.error(`Missing FastUpdateFeeds event for Coston: ${processed + 1}`); data.push("CONTRACT_CHANGE" as any); diff --git a/libs/ftso-core/src/configs/networks.ts b/libs/ftso-core/src/configs/networks.ts index ed200296..4e1ed611 100644 --- a/libs/ftso-core/src/configs/networks.ts +++ b/libs/ftso-core/src/configs/networks.ts @@ -666,5 +666,10 @@ export const FEEDS_RENAMING_FILE = () => "libs/ftso-core/src/reward-calculation/ export const FUTURE_VOTING_ROUNDS = () => 30; +// Used to limit querying of too old events and handling the missing event for the voting round export const COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID = 779191; -export const SONGBIRD_FAST_UPDATER_SWITCH_VOTING_ROUND_ID = 99999999999999; // temporary set to very high to not have effect + +// set to start voting round id of epoch 234 +// on Songbird there was no missing event for the voting round +// Only used to filter out the old events +export const SONGBIRD_FAST_UPDATER_SWITCH_VOTING_ROUND_ID = 786240;