Skip to content

Commit

Permalink
return map indexed by validator index number instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed Sep 30, 2024
1 parent 1a70adf commit 19f0d4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions packages/brain/src/modules/apiClients/postgres/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,21 @@ WHERE ${Columns.validatorIndex} = ANY($1)
validatorIndexes: string[];
startEpoch: number;
endEpoch: number;
}): Promise<Map<string, ValidatorPerformance[]>> {
}): Promise<Map<number, ValidatorPerformance[]>> {
const query = `
SELECT * FROM ${this.tableName}
WHERE ${Columns.validatorIndex} = ANY($1)
AND ${Columns.epoch} >= $2
AND ${Columns.epoch} <= $3
`;

const result = await this.sql.unsafe(query, [validatorIndexes, startEpoch, endEpoch]);
const result = (await this.sql.unsafe(query, [
validatorIndexes,
startEpoch,
endEpoch
])) as ValidatorPerformancePostgres[];

return result.reduce((map: Map<string, ValidatorPerformance[]>, row) => {
return result.reduce((map: Map<number, ValidatorPerformance[]>, row) => {
const key = row.validator_index;

// print type ofs
Expand All @@ -279,7 +283,7 @@ AND ${Columns.epoch} <= $3
else map.set(key, [performanceData]);

return map;
}, new Map<string, ValidatorPerformance[]>());
}, new Map<number, ValidatorPerformance[]>());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/brain/src/modules/validatorsDataIngest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ export async function fetchAndProcessValidatorsData({
granularity?: Granularity;
}): Promise<
Map<
string, // validatorIndex
number, // validatorIndex
ValidatorsDataProcessed // processed data of the validator
>
> {
logger.info("Processing validators data");
const mapValidatorPerformance = new Map<string, ValidatorsDataProcessed>();
const mapValidatorPerformance = new Map<number, ValidatorsDataProcessed>();

// Get start timestamp and end timestamp
const endDate = new Date();
Expand Down

0 comments on commit 19f0d4d

Please sign in to comment.