Skip to content

Commit 2014345

Browse files
committed
Merge branch 'network-gap-fix' into 'main'
fix in rewarding for network being down See merge request flarenetwork/ftso/ftso-scaling!162
2 parents 7ab832f + 9ff9ace commit 2014345

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

libs/fsp-rewards/src/DataManagerForRewarding.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,12 @@ export class DataManagerForRewarding extends DataManager {
759759
throw new Error(`FastUpdateFeeds is undefined for voting round ${votingRoundId}`);
760760
}
761761

762-
if ((fastUpdateFeeds as any) === "CONTRACT_CHANGE") {
762+
if ((fastUpdateFeeds as any) === "MISSING_FAST_UPDATE_FEEDS") {
763763
result.push(undefined);
764-
this.logger.error(`WARN: FastUpdateFeeds contract change for voting round ${votingRoundId}`);
764+
this.logger.error(`WARN: FastUpdateFeeds missing for voting round ${votingRoundId}`);
765765
continue;
766766
}
767+
767768
const value: FastUpdatesDataForVotingRound = {
768769
votingRoundId,
769770
feedValues: fastUpdateFeeds.feeds,

libs/fsp-rewards/src/IndexerClientForRewarding.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ export class IndexerClientForRewarding extends IndexerClient {
221221

222222
const data: FastUpdateFeeds[] = [];
223223
let processed = -1;
224+
// The batch is fully devoid of FastUpdateFeeds events
225+
if (result.length === 0) {
226+
this.logger.error(`Missing FastUpdateFeeds events: ${startVotingRoundId} to ${endVotingRoundId}`);
227+
228+
for (let i = startVotingRoundId; i <= endVotingRoundId; i++) {
229+
data.push("MISSING_FAST_UPDATE_FEEDS" as any);
230+
}
231+
processed = endVotingRoundId;
232+
}
224233
for (let i = 0; i < result.length; i++) {
225234
const event = FastUpdateFeeds.fromRawEvent(result[i]);
226235
// queryEvents returns blockchain chronologically ordered events
@@ -229,28 +238,40 @@ export class IndexerClientForRewarding extends IndexerClient {
229238
data.push(event);
230239
processed = event.votingRoundId;
231240
} else {
232-
// On Coston one event is missing hence special handling
233-
if (network == "coston" && processed + 1 == COSTON_FAST_UPDATER_SWITCH_VOTING_ROUND_ID) {
234-
while (processed + 1 < event.votingRoundId) {
235-
this.logger.error(`Missing FastUpdateFeeds event for Coston: ${processed + 1}`);
236-
data.push("CONTRACT_CHANGE" as any);
237-
processed++;
238-
}
239-
data.push(event);
241+
// Gaps in events
242+
let start = -1;
243+
// no first voting round event
244+
if (processed === -1) {
245+
processed = startVotingRoundId - 1;
246+
}
247+
// remember the start position for logging
248+
if (processed + 1 < event.votingRoundId) {
249+
start = processed + 1;
250+
}
251+
// jump over missing events
252+
while (processed + 1 < event.votingRoundId) {
253+
data.push("MISSING_FAST_UPDATE_FEEDS" as any);
240254
processed++;
241-
continue;
242255
}
243-
throw new Error(
244-
`FastUpdateFeeds events are not continuous from ${startVotingRoundId} to ${endVotingRoundId}: expected ${processed + 1
245-
}, got ${event.votingRoundId}`
246-
);
256+
// one error log for the whole gap
257+
if (start !== -1) {
258+
this.logger.error(
259+
`Missing FastUpdateFeeds events (gap): ${start} to ${event.votingRoundId - 1}`
260+
);
261+
}
262+
data.push(event);
263+
processed++;
264+
continue;
247265
}
248266
}
249267
}
250268
if (processed !== endVotingRoundId) {
251-
throw new Error(
252-
`Cannot get all FastUpdateFeeds events from ${startVotingRoundId} to ${endVotingRoundId}: last processed ${processed}`
253-
);
269+
// process the gap at the end of the range
270+
this.logger.error(`Missing FastUpdateFeeds events (end gap): ${processed + 1} to ${endVotingRoundId}`);
271+
while (processed !== endVotingRoundId) {
272+
data.push("MISSING_FAST_UPDATE_FEEDS" as any);
273+
processed++;
274+
}
254275
}
255276
return {
256277
status,
@@ -419,11 +440,11 @@ export class IndexerClientForRewarding extends IndexerClient {
419440
// strictly containing in the range
420441
const endTime = EPOCH_SETTINGS().votingEpochStartSec(endVotingRoundId + 1) - 1;
421442
const eventName = FDCInflationRewardsOffered.eventName;
422-
const status = await this.ensureEventRange(startTime, endTime);
443+
const status = await this.ensureEventRange(startTime, endTime);
423444
if (status !== BlockAssuranceResult.OK) {
424445
return { status };
425446
}
426-
const result = await this.queryEvents(CONTRACTS.FdcHub, eventName, startTime, endTime);
447+
const result = await this.queryEvents(CONTRACTS.FdcHub, eventName, startTime, endTime);
427448
const data = result.map(event => FDCInflationRewardsOffered.fromRawEvent(event));
428449
return {
429450
status,

libs/fsp-rewards/src/reward-calculation/reward-calculation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ export async function partialRewardClaimsForVotingRound(
241241
}
242242
}
243243
}
244-
const network = process.env.NETWORK;
245-
const isContractChange = network == "coston" && votingRoundId == 779191;
244+
const isMissingFastUpdateFeeds = data.fastUpdatesData === undefined;
246245

247-
if (useFastUpdatesData && isContractChange) {
246+
if (useFastUpdatesData && isMissingFastUpdateFeeds) {
247+
logger.error(`WARN: Missing FastUpdateFeeds event for ${votingRoundId}`);
248248
const fuFeedOffers = deserializeGranulatedPartialOfferMapForFastUpdates(
249249
rewardEpochId,
250250
votingRoundId,
@@ -261,15 +261,15 @@ export async function partialRewardClaimsForVotingRound(
261261
// feedId: offer.feedId, // should be undefined
262262
protocolTag: "" + FTSO2_FAST_UPDATES_PROTOCOL_ID,
263263
rewardTypeTag: RewardTypePrefix.FULL_OFFER_CLAIM_BACK,
264-
rewardDetailTag: FastUpdatesRewardClaimType.CONTRACT_CHANGE,
264+
rewardDetailTag: FastUpdatesRewardClaimType.MISSING_FAST_UPDATE_FEEDS,
265265
});
266266
}
267267
}
268268
if (merge) {
269269
allRewardClaims = RewardClaim.merge(allRewardClaims);
270270
}
271271
}
272-
if (useFastUpdatesData && !isContractChange) {
272+
if (useFastUpdatesData && !isMissingFastUpdateFeeds) {
273273
const fuFeedOffers = deserializeGranulatedPartialOfferMapForFastUpdates(
274274
rewardEpochId,
275275
votingRoundId,

libs/fsp-rewards/src/reward-calculation/reward-fast-updates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export enum FastUpdatesRewardClaimType {
1515
MISSED_BAND = "MISSING_BAND",
1616
FEE = "FEE",
1717
PARTICIPATION = "PARTICIPATION",
18-
CONTRACT_CHANGE = "CONTRACT_CHANGE",
18+
MISSING_FAST_UPDATE_FEEDS = "MISSING_FAST_UPDATE_FEEDS",
1919
}
2020

2121
/**

scripts/rewards/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ When finalizing the following [reward detail tags](../../libs/fsp-rewards/src/re
244244
- `MISSED_BAND` - burn claim for total voting round rewards, when the benchmark fast update price misses the prescribed band around the FTSO scaling price for specific voting round.
245245
- `FEE` - fee part of the reward claim of a data provider.
246246
- `PARTICIPATION` - community reward for delegators earned by a data provider.
247-
- `CONTRACT_CHANGE` - special case, happening only when changing FastUpdater smart contract if a version of it is not available, so system is temporarily unusable, hence the rewards for specific voting round(s) get burned.
247+
- `MISSING_FAST_UPDATE_FEEDS` - special case, when network is down and no FastUpdateFeeds events are available.
248248

249249
## Reward calculation and data
250250

0 commit comments

Comments
 (0)