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

Commit a6c5db4

Browse files
authored
Merge pull request #2676 from w3f/will-filtered
Add Nominator FIltering
2 parents 5762a38 + ade07a4 commit a6c5db4

File tree

16 files changed

+60
-29
lines changed

16 files changed

+60
-29
lines changed

apps/1kv-backend/templates/kusama-otv-backend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
source:
1818
repoURL: https://w3f.github.io/helm-charts/
1919
chart: otv-backend
20-
targetRevision: v3.0.24
20+
targetRevision: v3.0.25
2121
plugin:
2222
env:
2323
- name: HELM_VALUES

apps/1kv-backend/templates/polkadot-otv-backend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
source:
1818
repoURL: https://w3f.github.io/helm-charts/
1919
chart: otv-backend
20-
targetRevision: v3.0.24
20+
targetRevision: v3.0.25
2121
plugin:
2222
env:
2323
- name: HELM_VALUES

charts/otv-backend/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
description: 1K Validators Backend
22
name: otv-backend
3-
version: v3.0.24
4-
appVersion: v3.0.24
3+
version: v3.0.25
4+
appVersion: v3.0.25
55
apiVersion: v2

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@1kv/common",
3-
"version": "3.0.24",
3+
"version": "3.0.25",
44
"description": "Services for running the Thousand Validator Program.",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",

packages/common/src/chaindata/chaindata.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ export class ChainData {
8383
}
8484

8585
checkApiConnection = async (retries = 0): Promise<boolean> => {
86-
if (!this.api?.isConnected) {
86+
if (!this.handler.getApi()?.isConnected) {
8787
if (retries < CHAINDATA_RETRIES) {
88-
logger.warn(
89-
`Retries: ${retries} - API is not connected, waiting...`,
90-
chaindataLabel,
91-
);
88+
// logger.warn(
89+
// `Retries: ${retries} - API is not connected, waiting...`,
90+
// chaindataLabel,
91+
// );
9292
await sleep(CHAINDATA_SLEEP);
9393

9494
retries++;
9595
return await this.checkApiConnection(retries);
9696
} else {
9797
logger.warn(`Performing health check on api...`, chaindataLabel);
98-
await this.api?.disconnect();
98+
await this.handler.getApi()?.disconnect();
9999
const healthy = await this.handler.healthCheck();
100100
if (healthy) {
101101
this.api = this.handler.getApi();

packages/common/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const POLKADOT_API_TIMEOUT = 1000000;
4141

4242
export const CHAINDATA_RETRIES = 20;
4343

44-
export const CHAINDATA_SLEEP = 10000;
44+
export const CHAINDATA_SLEEP = 300;
4545

4646
export const API_PROVIDER_TIMEOUT = 10000;
4747

packages/common/src/nominator/nominator.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface NominatorStatus {
3636
rewardDestination?: string;
3737
stale?: boolean;
3838
dryRun?: boolean;
39+
shouldNominate?: boolean;
3940
}
4041

4142
export default class Nominator extends EventEmitter {
@@ -61,6 +62,8 @@ export default class Nominator extends EventEmitter {
6162
reason: "",
6263
};
6364

65+
public _shouldNominate = false;
66+
6467
private _status: NominatorStatus = {
6568
status: "Init",
6669
bondedAddress: "",
@@ -130,12 +133,25 @@ export default class Nominator extends EventEmitter {
130133
this._status = { ...this._status, ...newStatus };
131134
};
132135

136+
public async shouldNominate(): Promise<boolean> {
137+
const stash = await this.stash();
138+
const isBonded = await this.chaindata.isBonded(stash);
139+
const [bonded, err] = await this.chaindata.getDenomBondedAmount(stash);
140+
141+
const currentEra = (await this.chaindata.getCurrentEra()) || 0;
142+
const lastNominationEra =
143+
(await this.chaindata.getNominatorLastNominationEra(stash)) || 0;
144+
this._shouldNominate = isBonded && currentEra - lastNominationEra >= 1;
145+
return this._shouldNominate;
146+
}
147+
133148
public async init(): Promise<NominatorStatus> {
134149
try {
135150
const stash = await this.stash();
136151
const isBonded = await this.chaindata.isBonded(stash);
137152
const [bonded, err] = await this.chaindata.getDenomBondedAmount(stash);
138153

154+
const currentEra = (await this.chaindata.getCurrentEra()) || 0;
139155
const lastNominationEra =
140156
(await this.chaindata.getNominatorLastNominationEra(stash)) || 0;
141157
const currentTargets =
@@ -163,11 +179,14 @@ export default class Nominator extends EventEmitter {
163179
this.signer.address,
164180
);
165181

182+
this._shouldNominate =
183+
bonded > 50 && isBonded && currentEra - lastNominationEra >= 1;
184+
166185
const rewardDestination = await this.payee();
167-
const currentEra = (await this.chaindata.getCurrentEra()) || 0;
186+
168187
const stale = isBonded && currentEra - lastNominationEra > 8;
169188
const status: NominatorStatus = {
170-
status: "Init",
189+
status: this._shouldNominate ? "Initialized" : "Existing Nomination",
171190
bondedAddress: this.bondedAddress,
172191
stashAddress: await this.stash(),
173192
bondedAmount: Number(bonded),
@@ -182,6 +201,7 @@ export default class Nominator extends EventEmitter {
182201
stale: stale,
183202
dryRun: this._dryRun,
184203
updated: Date.now(),
204+
shouldNominate: this._shouldNominate,
185205
};
186206
this.updateNominatorStatus(status);
187207
this._canNominate = {

packages/common/src/scorekeeper/Nominating.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export const doNominations = async (
4545
return null;
4646
}
4747

48-
// ensure the group is sorted by least avg stake
4948
for (const nominator of nominatorGroups) {
5049
const nomStash = await nominator.stash();
5150
const nominatorLastNominated =

packages/common/src/scorekeeper/Round.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export const startRound = async (
3434
if (nominating) return [];
3535
nominating = true;
3636

37+
const filteredNominators = await Promise.all(
38+
nominatorGroups.filter(async (nom) => {
39+
return await nom.shouldNominate();
40+
}),
41+
);
42+
3743
const now = new Date().getTime();
3844

3945
// The nominations sent now won't be active until the next era.
@@ -48,7 +54,7 @@ export const startRound = async (
4854
`New round is starting! Era ${newEra} will begin new nominations.`,
4955
);
5056

51-
for (const nom of nominatorGroups) {
57+
for (const nom of filteredNominators) {
5258
const nominatorStatus: NominatorStatus = {
5359
status: `Round Started`,
5460
updated: Date.now(),
@@ -97,7 +103,7 @@ export const startRound = async (
97103
}
98104
}
99105

100-
for (const nom of nominatorGroups) {
106+
for (const nom of filteredNominators) {
101107
const nominatorStatus: NominatorStatus = {
102108
status: `Scoring Candidates...`,
103109
updated: Date.now(),
@@ -135,7 +141,7 @@ export const startRound = async (
135141
// TODO unit test that assets this value
136142
const numValidatorsNominated = await doNominations(
137143
sortedCandidates,
138-
nominatorGroups,
144+
filteredNominators,
139145
chaindata,
140146
handler,
141147
bot,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ export const mainScorekeeperJob = async (
5151
mainScoreKeeperLabel,
5252
);
5353
const hasOld = await Promise.all(
54-
nominatorGroups.map(async (nom) => {
54+
nominatorGroups.filter(async (nom) => {
5555
const stash = await nom.stash();
5656
if (!stash || stash === "0x") return false;
5757
const lastNominatedEra =
5858
await chaindata.getNominatorLastNominationEra(stash);
59-
return lastNominatedEra < activeEra - eraBuffer;
59+
return lastNominatedEra <= activeEra - 1;
6060
}),
6161
);
6262

@@ -112,7 +112,7 @@ export const mainScorekeeperJob = async (
112112
nominating,
113113
bot,
114114
constraints,
115-
nominatorGroups,
115+
hasOld,
116116
chaindata,
117117
handler,
118118
config,

0 commit comments

Comments
 (0)