Skip to content

Commit 5362ab9

Browse files
committed
IndexerClient: Ignore invalid transactions instead of crashing
1 parent 13ea820 commit 5362ab9

4 files changed

Lines changed: 30 additions & 18 deletions

File tree

apps/ftso-data-provider/src/ftso-data-provider.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class FtsoDataProviderService {
4848
constructor(manager: EntityManager, configService: ConfigService) {
4949
const required_history_sec = configService.get<number>("required_indexer_history_time_sec");
5050
this.indexer_top_timeout = configService.get<number>("indexer_top_timeout");
51-
this.indexerClient = new IndexerClient(manager, required_history_sec);
51+
this.indexerClient = new IndexerClient(manager, required_history_sec, new Logger(IndexerClient.name));
5252
this.rewardEpochManager = new RewardEpochManager(this.indexerClient);
5353
this.priceProviderClient = new Api({ baseURL: configService.get<string>("price_provider_url") });
5454
this.dataManager = new DataManager(this.indexerClient, this.rewardEpochManager, this.logger);

apps/ftso-reward-calculator/src/protocol-services/ftso/ftso-reward.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class FtsoRewardingService extends BaseRewardingService {
2525
this.entityManager = manager;
2626
const required_history_sec = configService.get<number>("required_indexer_history_time_sec");
2727
this.indexer_top_timeout = configService.get<number>("indexer_top_timeout");
28-
this.indexerClient = new IndexerClient(manager, required_history_sec);
28+
this.indexerClient = new IndexerClient(manager, required_history_sec, new Logger(IndexerClient.name));
2929
this.rewardEpochManger = new RewardEpochManager(this.indexerClient);
3030
this.dataManager = new DataManager(this.indexerClient, this.rewardEpochManger, this.logger);
3131
}

libs/ftso-core/src/IndexerClient.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import {
2525
VoterRegistered,
2626
VoterRegistrationInfo,
2727
} from "./events";
28+
import { ILogger } from "./utils/ILogger";
29+
import { errorString } from "./utils/error";
2830

2931
/**
3032
* Generic object for submission data and finalization data.
@@ -132,7 +134,11 @@ export enum BlockAssuranceResult {
132134
* the protocol data provider to function properly.
133135
*/
134136
export class IndexerClient {
135-
constructor(private readonly entityManager: EntityManager, public readonly requiredHistoryTimeSec: number) {}
137+
constructor(
138+
private readonly entityManager: EntityManager,
139+
public readonly requiredHistoryTimeSec: number,
140+
private readonly logger: ILogger
141+
) {}
136142

137143
private readonly encoding = EncodingUtils.instance;
138144

@@ -477,20 +483,26 @@ export class IndexerClient {
477483
};
478484
}
479485
const transactionsResults = await this.queryTransactions(CONTRACTS.Submission, functionName, startTime, endTime);
480-
const submits: SubmissionData[] = transactionsResults.map(tx => {
481-
const timestamp = tx.timestamp;
482-
const votingEpochId = EPOCH_SETTINGS.votingEpochForTimeSec(timestamp);
483-
const messages = decodePayloadMessageCalldata(tx);
484-
return {
485-
submitAddress: "0x" + tx.from_address,
486-
relativeTimestamp: timestamp - EPOCH_SETTINGS.votingEpochStartSec(votingEpochId),
487-
votingEpochIdFromTimestamp: votingEpochId,
488-
transactionIndex: tx.transaction_index,
489-
timestamp,
490-
blockNumber: tx.block_number,
491-
messages,
492-
};
493-
});
486+
487+
const submits: SubmissionData[] = [];
488+
for (const tx of transactionsResults) {
489+
try {
490+
const timestamp = tx.timestamp;
491+
const votingEpochId = EPOCH_SETTINGS.votingEpochForTimeSec(timestamp);
492+
const messages = decodePayloadMessageCalldata(tx);
493+
submits.push({
494+
submitAddress: "0x" + tx.from_address,
495+
relativeTimestamp: timestamp - EPOCH_SETTINGS.votingEpochStartSec(votingEpochId),
496+
votingEpochIdFromTimestamp: votingEpochId,
497+
transactionIndex: tx.transaction_index,
498+
timestamp,
499+
blockNumber: tx.block_number,
500+
messages,
501+
});
502+
} catch (e) {
503+
this.logger.warn(`Error processing submission transaction ${tx.hash}, will ignore: ${errorString(e)}`);
504+
}
505+
}
494506

495507
return {
496508
status: ensureRange,

test/libs/integration/RewardEpochManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("RewardEpochManager", () => {
4343
const rewardEpochId = 1;
4444
await setUpRewardEpoch(rewardEpochId);
4545

46-
const epochManager = new RewardEpochManager(new IndexerClient(em, indexerHistorySec));
46+
const epochManager = new RewardEpochManager(new IndexerClient(em, indexerHistorySec, console));
4747
const votingRound = epochSettings.expectedFirstVotingRoundForRewardEpoch(rewardEpochId);
4848
const rewardEpoch = await epochManager.getRewardEpoch(votingRound);
4949

0 commit comments

Comments
 (0)