Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 8273e0a

Browse files
authored
Merge pull request #2898 from w3f/erastats-fix
fix bug | otimize call
2 parents a717271 + 2439db1 commit 8273e0a

File tree

5 files changed

+6
-10
lines changed

5 files changed

+6
-10
lines changed

packages/common/src/db/queries/Validators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ export const getValidatorActiveEras = async (
187187
// return the number of eras
188188
export const getIdentityValidatorActiveEras = async (
189189
address: string,
190+
validatorSets: ValidatorSet[],
190191
): Promise<number> => {
191192
const identityAddresses = await getIdentityAddresses(address);
192193
let count = 0;
193-
const validatorSets = await getAllValidatorSets();
194194
for (const era of validatorSets) {
195195
if (
196196
era.validators.some((validator) => identityAddresses.includes(validator))

packages/common/src/scorekeeper/jobs/specificJobs/EraStatsJob.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const eraStatsJob = async (
7676
updated: Date.now(),
7777
});
7878

79-
for (let i = currentEra; i > 20; i--) {
79+
for (let i = currentEra; i > currentEra - 20; i--) {
8080
if (await queries.validatorSetExistsForEra(i)) {
8181
continue;
8282
}

packages/common/src/utils/Validators.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { allCandidates, setRank } from "../db/queries";
1+
import { allCandidates, getAllValidatorSets, setRank } from "../db/queries";
22
import { queries } from "../index";
33

44
// Sets all validators ranks
55
export const setValidatorRanks = async () => {
66
const candidates = await allCandidates();
7+
const validatorSets = await getAllValidatorSets();
78
for (const candidate of candidates) {
89
const identityRank = await queries.getIdentityValidatorActiveEras(
910
candidate.stash,
11+
validatorSets,
1012
);
1113
await setRank(candidate.stash, identityRank);
1214
}

packages/common/test/utils/Validators.unit.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ describe("setValidatorRanks", () => {
120120

121121
const subNumEras = await getIdentityValidatorActiveEras(
122122
"HkJjBkX8fPBFJvTtAbUDKWZSsMrNFuMc7TrT8BqVS5YhZXg",
123+
validatorSets,
123124
);
124125
expect(subNumEras).toBe(5);
125126

packages/gateway/src/services/Validator.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,3 @@ export const getValidatorsNumActiveEras = async (
3131
const eras = await queries.getValidatorActiveEras(stash);
3232
return eras;
3333
};
34-
35-
export const getIdentityValidatorNumActiveEras = async (
36-
stash: string,
37-
): Promise<any> => {
38-
const eras = await queries.getIdentityValidatorActiveEras(stash);
39-
return eras;
40-
};

0 commit comments

Comments
 (0)