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

Commit f0644fa

Browse files
authored
Merge pull request #2714 from w3f/will-v3.1.5
v3.1.5
2 parents f01b3ac + c36bd96 commit f0644fa

File tree

33 files changed

+216
-125
lines changed

33 files changed

+216
-125
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.1.4
20+
targetRevision: v3.1.5
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.1.4
20+
targetRevision: v3.1.5
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.1.4
4-
appVersion: v3.1.4
3+
version: v3.1.5
4+
appVersion: v3.1.5
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.1.4",
3+
"version": "3.1.5",
44
"description": "Services for running the Thousand Validator Program.",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",

packages/common/src/constants.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ export const defaultWsOptions = {
8181
debug: true,
8282
};
8383

84-
// 200 hours in milliseconds
85-
export const STALE_TELEMETRY_THRESHOLD = 720000000;
84+
// 2 days in milliseconds
85+
export const STALE_TELEMETRY_THRESHOLD = 172800000;
8686

8787
export const DEFAULT_TELEMETRY_ENDPONT =
8888
"wss://telemetry.w3f.community/submit/";
8989

9090
// List of log labels that are omitted from logging
9191
export const defaultExcludeLabels = [
92-
"Telemetry",
93-
"Location",
92+
// "Telemetry",
93+
// "Location",
9494
// "ValidatorPrefJob",
95-
// "Block",
95+
"Block",
9696
"Gateway",
9797
];
9898

packages/common/src/constraints/ScoreCandidates.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "../db";
1212
import { constraintsLabel, OTV } from "./constraints";
1313
import { percentage, timeRemaining } from "../utils/util";
14+
import { NoLocation } from "../types";
1415

1516
export const scoreCandidate = async (
1617
constraints: OTV,
@@ -94,7 +95,9 @@ export const scoreCandidate = async (
9495
(1 - scaledFaults) * constraints.WEIGHT_CONFIG.FAULTS_WEIGHT;
9596

9697
const latestCandidateLocation = await queries.getCandidateLocation(
98+
candidate.slotId,
9799
candidate.name,
100+
candidate.stash,
98101
);
99102

100103
const provider = latestCandidateLocation?.provider || "No Provider";
@@ -116,7 +119,9 @@ export const scoreCandidate = async (
116119
scaledDefined(candidateLocation, locationValues, 0, 1) || 0;
117120
const locationScore = bannedProvider
118121
? 0
119-
: latestCandidateLocation?.city == "No Location"
122+
: latestCandidateLocation?.city == NoLocation.NoLocation ||
123+
!latestCandidateLocation ||
124+
!latestCandidateLocation?.city
120125
? 0.25 * constraints.WEIGHT_CONFIG.LOCATION_WEIGHT
121126
: (1 - scaledLocation) * constraints.WEIGHT_CONFIG.LOCATION_WEIGHT || 0;
122127

@@ -135,7 +140,9 @@ export const scoreCandidate = async (
135140
scaledDefined(candidateRegion, regionValues, 0, 1) || 0;
136141
const regionScore = bannedProvider
137142
? 0
138-
: latestCandidateLocation?.region == "No Location"
143+
: latestCandidateLocation?.region == NoLocation.NoLocation ||
144+
!latestCandidateLocation ||
145+
!latestCandidateLocation?.region
139146
? 0.25 * constraints.WEIGHT_CONFIG.REGION_WEIGHT
140147
: (1 - scaledRegion) * constraints.WEIGHT_CONFIG.REGION_WEIGHT || 0;
141148

@@ -154,7 +161,9 @@ export const scoreCandidate = async (
154161
scaledDefined(candidateCountry, countryValues, 0, 1) || 0;
155162
const countryScore = bannedProvider
156163
? 0
157-
: latestCandidateLocation?.country == "No Location"
164+
: latestCandidateLocation?.country == NoLocation.NoLocation ||
165+
!latestCandidateLocation ||
166+
!latestCandidateLocation?.country
158167
? 0.25 * constraints.WEIGHT_CONFIG.COUNTRY_WEIGHT
159168
: (1 - scaledCountry) * constraints.WEIGHT_CONFIG.COUNTRY_WEIGHT || 0;
160169

@@ -173,7 +182,9 @@ export const scoreCandidate = async (
173182
scaledDefined(candidateProvider, providerValues, 0, 1) || 0;
174183
const providerScore = bannedProvider
175184
? 0
176-
: latestCandidateLocation?.provider == "No Location"
185+
: latestCandidateLocation?.provider == "No Location" ||
186+
!latestCandidateLocation ||
187+
!latestCandidateLocation?.provider
177188
? 0.25 * constraints.WEIGHT_CONFIG.PROVIDER_WEIGHT
178189
: (1 - scaledProvider) * constraints.WEIGHT_CONFIG.PROVIDER_WEIGHT || 0;
179190

packages/common/src/constraints/ValidityChecks.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,11 @@ export const checkProvider = async (
325325
candidate: Candidate,
326326
): Promise<boolean> => {
327327
try {
328-
const location = await queries.getCandidateLocation(candidate.name);
328+
const location = await queries.getCandidateLocation(
329+
candidate.slotId,
330+
candidate.name,
331+
candidate.stash,
332+
);
329333
if (location && location.provider) {
330334
const bannedProviders = config.telemetry?.blacklistedProviders;
331335
if (bannedProviders?.includes(location.provider)) {

packages/common/src/constraints/Values.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getLatestNominatorStake,
88
} from "../db";
99
import { constraintsLabel } from "./constraints";
10+
import { NoLocation } from "../types";
1011

1112
export const getBondedValues = (
1213
validCandidates: Candidate[],
@@ -116,8 +117,12 @@ export const getLocationValues = async (
116117
const locationMap = new Map<string, number>();
117118
const locationArr: { name: string; numberOfNodes: number }[] = [];
118119
for (const candidate of validCandidates) {
119-
const candidateLocation = await getCandidateLocation(candidate.name);
120-
const location = candidateLocation?.city || "No Location";
120+
const candidateLocation = await getCandidateLocation(
121+
candidate.slotId,
122+
candidate.name,
123+
candidate.stash,
124+
);
125+
const location = candidateLocation?.city || NoLocation.NoLocation;
121126

122127
const locationCount = locationMap.get(location);
123128
if (!locationCount) {
@@ -150,11 +155,15 @@ export const getRegionValues = async (
150155
const regionMap = new Map<string, number>();
151156
const regionArr: { name: string; numberOfNodes: number }[] = [];
152157
for (const candidate of validCandidates) {
153-
const candidateLocation = await getCandidateLocation(candidate.name);
158+
const candidateLocation = await getCandidateLocation(
159+
candidate.slotId,
160+
candidate.name,
161+
candidate.stash,
162+
);
154163
const region =
155164
candidateLocation && candidateLocation.region
156165
? candidateLocation.region
157-
: "No Location";
166+
: NoLocation.NoLocation;
158167

159168
const regionCount = regionMap.get(region);
160169
if (!regionCount) {
@@ -187,11 +196,15 @@ export const getCountryValues = async (
187196
const countryMap = new Map<string, number>();
188197
const countryArr: { name: string; numberOfNodes: number }[] = [];
189198
for (const candidate of validCandidates) {
190-
const candidateLocation = await getCandidateLocation(candidate.name);
199+
const candidateLocation = await getCandidateLocation(
200+
candidate.slotId,
201+
candidate.name,
202+
candidate.stash,
203+
);
191204
const country =
192205
candidateLocation && candidateLocation.country
193206
? candidateLocation.country
194-
: "No Location";
207+
: NoLocation.NoLocation;
195208

196209
const countryCount = countryMap.get(country);
197210
if (!countryCount) {
@@ -222,11 +235,15 @@ export const getProviderValues = async (
222235
const providerMap = new Map<string, number>();
223236
const providerArr: { name: string; numberOfNodes: number }[] = [];
224237
for (const candidate of validCandidates) {
225-
const candidateLocation = await getCandidateLocation(candidate.name);
238+
const candidateLocation = await getCandidateLocation(
239+
candidate.slotId,
240+
candidate.name,
241+
candidate.stash,
242+
);
226243
const provider =
227244
candidateLocation && candidateLocation.provider
228245
? candidateLocation.provider
229-
: "No Location";
246+
: NoLocation.NoProvider;
230247

231248
const providerCount = providerMap.get(provider);
232249
if (!providerCount) {

packages/common/src/db/models.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,13 @@ export const ValidatorSetModel = mongoose.model(
189189
);
190190

191191
export interface Location {
192+
// The SlotId of the candidate
193+
slotId: number;
194+
// The Telemetry name of the candidate
192195
name: string;
196+
// The stash address of the candidate
193197
address: string;
198+
// The IP address of the candidate
194199
addr: string;
195200
port: number;
196201
city: string;
@@ -208,6 +213,7 @@ export interface Location {
208213
}
209214

210215
export const LocationSchema = new Schema({
216+
slotId: { type: Number, index: true }, // The Candidate SlotId
211217
name: { type: String, index: true }, // The Telemetry name of the node
212218
address: { type: String, index: true }, // The Validator Address
213219
addr: { type: String, index: true },

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -887,22 +887,16 @@ export const invalidCandidates = async (): Promise<any[]> => {
887887
return CandidateModel.find({ valid: false }).lean<Candidate[]>();
888888
};
889889

890-
/**
891-
* Gets a candidate by its stash address.
892-
* @param stashOrName The DOT / KSM address or the name of the validator.
893-
*/
894890
export const getCandidate = async (
895-
stashOrName: string,
891+
slotId: number,
892+
stash?: string,
893+
address?: string,
896894
): Promise<Candidate | null> => {
897-
let data = await CandidateModel.findOne({
898-
stash: stashOrName,
899-
}).lean<Candidate>();
895+
const query: any = { slotId };
896+
if (stash) query.stash = stash;
897+
if (address) query.address = address;
900898

901-
if (!data) {
902-
data = await CandidateModel.findOne({
903-
name: stashOrName,
904-
}).lean<Candidate>();
905-
}
899+
const data = await CandidateModel.findOne(query).lean<Candidate>();
906900

907901
return data;
908902
};
@@ -919,6 +913,12 @@ export const getCandidateBySlotId = async (
919913
return CandidateModel.findOne({ slotId: id }).lean<Candidate>();
920914
};
921915

916+
export const getCandidateByStash = async (
917+
stash: string,
918+
): Promise<Candidate | null> => {
919+
return CandidateModel.findOne({ stash: stash }).lean<Candidate>();
920+
};
921+
922922
export const setInclusion = async (
923923
address: string,
924924
inclusion: number,
@@ -1709,7 +1709,7 @@ export const getUniqueStashSet = async (): Promise<any> => {
17091709
};
17101710

17111711
export const isKYC = async (stash: string): Promise<boolean | null> => {
1712-
const candidate = await getCandidate(stash);
1712+
const candidate = await getCandidateByStash(stash);
17131713
if (candidate) {
17141714
return candidate.kyc;
17151715
}

0 commit comments

Comments
 (0)