From 58b7fcba2ac2eadbc2231789a37595a7fbcebd38 Mon Sep 17 00:00:00 2001 From: will pankiewicz Date: Sat, 2 Mar 2024 02:45:36 +0100 Subject: [PATCH 1/6] add nominator filtering --- packages/common/src/chaindata/chaindata.ts | 12 ++++++------ packages/common/src/constants.ts | 2 +- packages/common/src/nominator/nominator.ts | 19 ++++++++++++++++++- packages/common/src/scorekeeper/Nominating.ts | 1 - packages/common/src/scorekeeper/Round.ts | 12 +++++++++--- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/packages/common/src/chaindata/chaindata.ts b/packages/common/src/chaindata/chaindata.ts index 24addb53a..9debfe61d 100644 --- a/packages/common/src/chaindata/chaindata.ts +++ b/packages/common/src/chaindata/chaindata.ts @@ -83,19 +83,19 @@ export class ChainData { } checkApiConnection = async (retries = 0): Promise => { - if (!this.api?.isConnected) { + if (!this.handler.getApi()?.isConnected) { if (retries < CHAINDATA_RETRIES) { - logger.warn( - `Retries: ${retries} - API is not connected, waiting...`, - chaindataLabel, - ); + // logger.warn( + // `Retries: ${retries} - API is not connected, waiting...`, + // chaindataLabel, + // ); await sleep(CHAINDATA_SLEEP); retries++; return await this.checkApiConnection(retries); } else { logger.warn(`Performing health check on api...`, chaindataLabel); - await this.api?.disconnect(); + await this.handler.getApi()?.disconnect(); const healthy = await this.handler.healthCheck(); if (healthy) { this.api = this.handler.getApi(); diff --git a/packages/common/src/constants.ts b/packages/common/src/constants.ts index 7c3917541..060e83827 100644 --- a/packages/common/src/constants.ts +++ b/packages/common/src/constants.ts @@ -41,7 +41,7 @@ export const POLKADOT_API_TIMEOUT = 1000000; export const CHAINDATA_RETRIES = 20; -export const CHAINDATA_SLEEP = 10000; +export const CHAINDATA_SLEEP = 300; export const API_PROVIDER_TIMEOUT = 10000; diff --git a/packages/common/src/nominator/nominator.ts b/packages/common/src/nominator/nominator.ts index 56e537e7e..881baca06 100644 --- a/packages/common/src/nominator/nominator.ts +++ b/packages/common/src/nominator/nominator.ts @@ -61,6 +61,8 @@ export default class Nominator extends EventEmitter { reason: "", }; + public _shouldNominate = false; + private _status: NominatorStatus = { status: "Init", bondedAddress: "", @@ -130,12 +132,25 @@ export default class Nominator extends EventEmitter { this._status = { ...this._status, ...newStatus }; }; + public async shouldNominate(): Promise { + const stash = await this.stash(); + const isBonded = await this.chaindata.isBonded(stash); + const [bonded, err] = await this.chaindata.getDenomBondedAmount(stash); + + const currentEra = (await this.chaindata.getCurrentEra()) || 0; + const lastNominationEra = + (await this.chaindata.getNominatorLastNominationEra(stash)) || 0; + this._shouldNominate = isBonded && currentEra - lastNominationEra >= 1; + return this._shouldNominate; + } + public async init(): Promise { try { const stash = await this.stash(); const isBonded = await this.chaindata.isBonded(stash); const [bonded, err] = await this.chaindata.getDenomBondedAmount(stash); + const currentEra = (await this.chaindata.getCurrentEra()) || 0; const lastNominationEra = (await this.chaindata.getNominatorLastNominationEra(stash)) || 0; const currentTargets = @@ -163,8 +178,10 @@ export default class Nominator extends EventEmitter { this.signer.address, ); + this.shouldNominate = isBonded && currentEra - lastNominationEra >= 1; + const rewardDestination = await this.payee(); - const currentEra = (await this.chaindata.getCurrentEra()) || 0; + const stale = isBonded && currentEra - lastNominationEra > 8; const status: NominatorStatus = { status: "Init", diff --git a/packages/common/src/scorekeeper/Nominating.ts b/packages/common/src/scorekeeper/Nominating.ts index c5a1fdf69..29f1ecc19 100644 --- a/packages/common/src/scorekeeper/Nominating.ts +++ b/packages/common/src/scorekeeper/Nominating.ts @@ -45,7 +45,6 @@ export const doNominations = async ( return null; } - // ensure the group is sorted by least avg stake for (const nominator of nominatorGroups) { const nomStash = await nominator.stash(); const nominatorLastNominated = diff --git a/packages/common/src/scorekeeper/Round.ts b/packages/common/src/scorekeeper/Round.ts index 5ce6d01e8..b56f747ee 100644 --- a/packages/common/src/scorekeeper/Round.ts +++ b/packages/common/src/scorekeeper/Round.ts @@ -34,6 +34,12 @@ export const startRound = async ( if (nominating) return []; nominating = true; + const filteredNominators = await Promise.all( + nominatorGroups.filter(async (nom) => { + return await nom.shouldNominate(); + }), + ); + const now = new Date().getTime(); // The nominations sent now won't be active until the next era. @@ -48,7 +54,7 @@ export const startRound = async ( `New round is starting! Era ${newEra} will begin new nominations.`, ); - for (const nom of nominatorGroups) { + for (const nom of filteredNominators) { const nominatorStatus: NominatorStatus = { status: `Round Started`, updated: Date.now(), @@ -97,7 +103,7 @@ export const startRound = async ( } } - for (const nom of nominatorGroups) { + for (const nom of filteredNominators) { const nominatorStatus: NominatorStatus = { status: `Scoring Candidates...`, updated: Date.now(), @@ -135,7 +141,7 @@ export const startRound = async ( // TODO unit test that assets this value const numValidatorsNominated = await doNominations( sortedCandidates, - nominatorGroups, + filteredNominators, chaindata, handler, bot, From a59749802d54d32bec67bd1fe21a82e5a0eab6a7 Mon Sep 17 00:00:00 2001 From: will pankiewicz Date: Sat, 2 Mar 2024 02:49:10 +0100 Subject: [PATCH 2/6] add nominator filtering --- packages/common/src/nominator/nominator.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/common/src/nominator/nominator.ts b/packages/common/src/nominator/nominator.ts index 881baca06..059cd3966 100644 --- a/packages/common/src/nominator/nominator.ts +++ b/packages/common/src/nominator/nominator.ts @@ -36,6 +36,7 @@ export interface NominatorStatus { rewardDestination?: string; stale?: boolean; dryRun?: boolean; + shouldNominate?: boolean; } export default class Nominator extends EventEmitter { @@ -178,13 +179,13 @@ export default class Nominator extends EventEmitter { this.signer.address, ); - this.shouldNominate = isBonded && currentEra - lastNominationEra >= 1; + this._shouldNominate = isBonded && currentEra - lastNominationEra >= 1; const rewardDestination = await this.payee(); const stale = isBonded && currentEra - lastNominationEra > 8; const status: NominatorStatus = { - status: "Init", + status: this._shouldNominate ? "Initialized" : "Existing Nomination", bondedAddress: this.bondedAddress, stashAddress: await this.stash(), bondedAmount: Number(bonded), @@ -199,6 +200,7 @@ export default class Nominator extends EventEmitter { stale: stale, dryRun: this._dryRun, updated: Date.now(), + shouldNominate: this._shouldNominate, }; this.updateNominatorStatus(status); this._canNominate = { From 287c2457fe102882d87fc0d3298529e93d7d8916 Mon Sep 17 00:00:00 2001 From: will pankiewicz Date: Sat, 2 Mar 2024 02:56:04 +0100 Subject: [PATCH 3/6] add nominator filtering --- .../src/scorekeeper/jobs/specificJobs/MainScorekeeperJob.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/common/src/scorekeeper/jobs/specificJobs/MainScorekeeperJob.ts b/packages/common/src/scorekeeper/jobs/specificJobs/MainScorekeeperJob.ts index 6f63aecf5..fbb19c956 100644 --- a/packages/common/src/scorekeeper/jobs/specificJobs/MainScorekeeperJob.ts +++ b/packages/common/src/scorekeeper/jobs/specificJobs/MainScorekeeperJob.ts @@ -51,12 +51,12 @@ export const mainScorekeeperJob = async ( mainScoreKeeperLabel, ); const hasOld = await Promise.all( - nominatorGroups.map(async (nom) => { + nominatorGroups.filter(async (nom) => { const stash = await nom.stash(); if (!stash || stash === "0x") return false; const lastNominatedEra = await chaindata.getNominatorLastNominationEra(stash); - return lastNominatedEra < activeEra - eraBuffer; + return lastNominatedEra <= activeEra - 1; }), ); @@ -112,7 +112,7 @@ export const mainScorekeeperJob = async ( nominating, bot, constraints, - nominatorGroups, + hasOld, chaindata, handler, config, From fa84a3f4cce18c40373d0a82a544f9d76258b74d Mon Sep 17 00:00:00 2001 From: will pankiewicz Date: Sat, 2 Mar 2024 02:59:02 +0100 Subject: [PATCH 4/6] add nominator filtering --- packages/common/src/nominator/nominator.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/common/src/nominator/nominator.ts b/packages/common/src/nominator/nominator.ts index 059cd3966..7e53d2dc7 100644 --- a/packages/common/src/nominator/nominator.ts +++ b/packages/common/src/nominator/nominator.ts @@ -179,7 +179,8 @@ export default class Nominator extends EventEmitter { this.signer.address, ); - this._shouldNominate = isBonded && currentEra - lastNominationEra >= 1; + this._shouldNominate = + bonded > 50 && isBonded && currentEra - lastNominationEra >= 1; const rewardDestination = await this.payee(); From 70746003d5876e0cf6c4394c7c10abb93d0e1d66 Mon Sep 17 00:00:00 2001 From: will pankiewicz Date: Sat, 2 Mar 2024 03:08:28 +0100 Subject: [PATCH 5/6] add nominator filtering --- packages/common/src/scorekeeper/scorekeeper.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/common/src/scorekeeper/scorekeeper.ts b/packages/common/src/scorekeeper/scorekeeper.ts index 863d6b195..c1bba874b 100644 --- a/packages/common/src/scorekeeper/scorekeeper.ts +++ b/packages/common/src/scorekeeper/scorekeeper.ts @@ -246,17 +246,23 @@ export default class ScoreKeeper { await setAllIdentities(this.chaindata, scorekeeperLabel); + const filteredNominators = await Promise.all( + this.nominatorGroups.filter(async (nom) => { + return await nom.shouldNominate(); + }), + ); + // If force round is set in the configs - if (this.config.scorekeeper.forceRound) { + if (this.config.scorekeeper.forceRound || filteredNominators.length > 0) { logger.info( - `Force Round: ${this.config.scorekeeper.forceRound} starting round....`, + `Force Round: ${this.config.scorekeeper.forceRound} ${filteredNominators.length} nominators old - starting round....`, scorekeeperLabel, ); await startRound( this.nominating, this.bot, this.constraints, - this.nominatorGroups, + filteredNominators, this.chaindata, this.handler, this.config, From ade07a446fd1d13c9fb886b582d57f0024a788b4 Mon Sep 17 00:00:00 2001 From: will pankiewicz Date: Sat, 2 Mar 2024 03:09:50 +0100 Subject: [PATCH 6/6] bump version to v3.0.25 --- apps/1kv-backend/templates/kusama-otv-backend.yaml | 2 +- apps/1kv-backend/templates/polkadot-otv-backend.yaml | 2 +- charts/otv-backend/Chart.yaml | 4 ++-- packages/common/package.json | 2 +- packages/core/package.json | 2 +- packages/gateway/package.json | 2 +- packages/scorekeeper-status-ui/package.json | 2 +- packages/telemetry/package.json | 2 +- packages/worker/package.json | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/1kv-backend/templates/kusama-otv-backend.yaml b/apps/1kv-backend/templates/kusama-otv-backend.yaml index 78b6b6b9b..d2fafad6b 100644 --- a/apps/1kv-backend/templates/kusama-otv-backend.yaml +++ b/apps/1kv-backend/templates/kusama-otv-backend.yaml @@ -17,7 +17,7 @@ spec: source: repoURL: https://w3f.github.io/helm-charts/ chart: otv-backend - targetRevision: v3.0.24 + targetRevision: v3.0.25 plugin: env: - name: HELM_VALUES diff --git a/apps/1kv-backend/templates/polkadot-otv-backend.yaml b/apps/1kv-backend/templates/polkadot-otv-backend.yaml index 9787986f9..49c7d9698 100644 --- a/apps/1kv-backend/templates/polkadot-otv-backend.yaml +++ b/apps/1kv-backend/templates/polkadot-otv-backend.yaml @@ -17,7 +17,7 @@ spec: source: repoURL: https://w3f.github.io/helm-charts/ chart: otv-backend - targetRevision: v3.0.24 + targetRevision: v3.0.25 plugin: env: - name: HELM_VALUES diff --git a/charts/otv-backend/Chart.yaml b/charts/otv-backend/Chart.yaml index 3dbdc66f7..752a6e757 100644 --- a/charts/otv-backend/Chart.yaml +++ b/charts/otv-backend/Chart.yaml @@ -1,5 +1,5 @@ description: 1K Validators Backend name: otv-backend -version: v3.0.24 -appVersion: v3.0.24 +version: v3.0.25 +appVersion: v3.0.25 apiVersion: v2 diff --git a/packages/common/package.json b/packages/common/package.json index 8e8dd9b97..825182fbe 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/common", - "version": "3.0.24", + "version": "3.0.25", "description": "Services for running the Thousand Validator Program.", "main": "build/index.js", "types": "build/index.d.ts", diff --git a/packages/core/package.json b/packages/core/package.json index 63f836cc2..35c35c974 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/core", - "version": "3.0.24`", + "version": "3.0.25", "description": "Services for running the Thousand Validator Program.", "main": "index.js", "scripts": { diff --git a/packages/gateway/package.json b/packages/gateway/package.json index 52777744b..76ac0647a 100644 --- a/packages/gateway/package.json +++ b/packages/gateway/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/gateway", - "version": "3.0.23", + "version": "3.0.25", "description": "Services for running the Thousand Validator Program.", "main": "build/index.js", "types": "build/index.d.ts", diff --git a/packages/scorekeeper-status-ui/package.json b/packages/scorekeeper-status-ui/package.json index d64487418..e8fadd1c1 100644 --- a/packages/scorekeeper-status-ui/package.json +++ b/packages/scorekeeper-status-ui/package.json @@ -1,7 +1,7 @@ { "name": "@1kv/scorekeeper-status-ui", "private": true, - "version": "3.0.24", + "version": "3.0.25", "type": "module", "scripts": { "dev": "vite", diff --git a/packages/telemetry/package.json b/packages/telemetry/package.json index 184ca2372..a4e776fca 100644 --- a/packages/telemetry/package.json +++ b/packages/telemetry/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/telemetry", - "version": "3.0.24", + "version": "3.0.25", "description": "Services for running the Thousand Validator Program.", "main": "build/index.js", "types": "build/index.d.ts", diff --git a/packages/worker/package.json b/packages/worker/package.json index f4c58eab2..b975e6da0 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/worker", - "version": "3.0.24g", + "version": "3.0.25", "description": "Services for running the Thousand Validator Program.", "main": "build/index.js", "types": "build/index.d.ts",