From 667ffe8c45f6439d43e25a615e9337a5768419bc Mon Sep 17 00:00:00 2001 From: Michalis Fragkiadakis Date: Thu, 11 Apr 2024 15:25:26 +0300 Subject: [PATCH 1/8] New sanctions validity check --- charts/otv-backend/values.yaml | 3 +- packages/common/src/config.ts | 3 ++ .../common/src/constraints/CheckCandidates.ts | 10 ++++- .../common/src/constraints/ValidityChecks.ts | 43 +++++++++++++++++++ packages/common/src/db/models.ts | 2 + packages/common/src/db/queries/Candidate.ts | 15 +++++++ .../config/kusama.current.dev.sample.json | 5 ++- .../core/config/kusama.current.sample.json | 5 ++- .../kusama.microservice.dev.sample.json | 5 ++- .../config/kusama.microservice.sample.json | 5 ++- packages/core/config/main.sample.json | 5 ++- .../config/polkadot.current.dev.sample.json | 5 ++- .../core/config/polkadot.current.sample.json | 5 ++- .../polkadot.microservice.dev.sample.json | 5 ++- .../config/polkadot.microservice.sample.json | 5 ++- 15 files changed, 110 insertions(+), 11 deletions(-) diff --git a/charts/otv-backend/values.yaml b/charts/otv-backend/values.yaml index 570a50a45..a554c72e8 100644 --- a/charts/otv-backend/values.yaml +++ b/charts/otv-backend/values.yaml @@ -48,7 +48,8 @@ config: | }, "constraints": { "skipConnectionTime": false, - "skipIdentity": false + "skipIdentity": false, + "skipSanctionedGeoArea": false }, "db": { "mongo": { diff --git a/packages/common/src/config.ts b/packages/common/src/config.ts index eb8aea873..e6cec2992 100644 --- a/packages/common/src/config.ts +++ b/packages/common/src/config.ts @@ -27,10 +27,13 @@ export type ConfigSchema = { skipClientUpgrade: boolean; skipUnclaimed: boolean; skipClaiming: boolean; + skipSanctionedGeoArea: boolean; forceClientVersion: string; minSelfStake: number; commission: number; unclaimedEraThreshold: number; + sanctionedCountries: string[]; + sanctionedRegions: string[]; }; cron: { monitor: string; diff --git a/packages/common/src/constraints/CheckCandidates.ts b/packages/common/src/constraints/CheckCandidates.ts index 81e4deb87..10a559934 100644 --- a/packages/common/src/constraints/CheckCandidates.ts +++ b/packages/common/src/constraints/CheckCandidates.ts @@ -15,6 +15,7 @@ import { checkSelfStake, checkUnclaimed, checkValidateIntention, + checkSanctionedGeoArea, } from "./ValidityChecks"; import { percentage, timeRemaining } from "../utils/util"; @@ -129,6 +130,12 @@ export const checkCandidate = async ( logger.info(`${candidate.name} beefy keys not valid`, constraintsLabel); } + const sanctionedGeoAreaValid = + constraints.config?.constraints?.skipSanctionedGeoArea == true + ? true + : (await checkSanctionedGeoArea(constraints.config, candidate)) || + false; + valid = onlineValid && validateValid && @@ -142,7 +149,8 @@ export const checkCandidate = async ( blockedValid && kusamaValid && providerValid && - beefyValid; + beefyValid && + sanctionedGeoAreaValid; await setValid(candidate.stash, valid); diff --git a/packages/common/src/constraints/ValidityChecks.ts b/packages/common/src/constraints/ValidityChecks.ts index 0e812e87c..3894d068b 100644 --- a/packages/common/src/constraints/ValidityChecks.ts +++ b/packages/common/src/constraints/ValidityChecks.ts @@ -15,6 +15,7 @@ import { setSelfStakeInvalidity, setUnclaimedInvalidity, setValidateIntentionValidity, + setSanctionedGeoAreaValidity, } from "../db"; import { ChainData, Config, Constants, queries, Util } from "../index"; import axios from "axios"; @@ -438,3 +439,45 @@ export const checkBeefyKeys = async ( throw new Error("could not make validity check"); } }; + +// Checks if the candidate is in a sanctioned location +export const checkSanctionedGeoArea = async ( + config: Config.ConfigSchema, + candidate: Candidate, +): Promise => { + try { + const location = await queries.getCandidateLocation( + candidate.slotId, + candidate.name, + ); + if (location && location.region && location.country) { + const sanctionedCountries = config.constraints?.sanctionedCountries; + const sanctionedRegions = config.constraints?.sanctionedRegions; + if ( + sanctionedCountries.includes(location.country) || + sanctionedRegions.includes(location.region) + ) { + logger.info( + `${candidate.name} is in a sanctioned location: Country: ${location.country}, Region: ${location.region}`, + { + label: "Constraints", + }, + ); + await setSanctionedGeoAreaValidity(candidate.slotId, false); + return false; + } else { + await setSanctionedGeoAreaValidity(candidate.slotId, true); + return true; + } + } else { + await setSanctionedGeoAreaValidity(candidate.slotId, true); + return true; + } + } catch (e) { + logger.error( + `Error checking location for sanctions: ${e}`, + constraintsLabel, + ); + throw new Error("could not make validity check"); + } +}; diff --git a/packages/common/src/db/models.ts b/packages/common/src/db/models.ts index 799e6483e..33cf506bb 100644 --- a/packages/common/src/db/models.ts +++ b/packages/common/src/db/models.ts @@ -88,6 +88,7 @@ export enum InvalidityReasonType { KUSAMA_RANK = "KUSAMA_RANK", PROVIDER = "PROVIDER", BEEFY = "BEEFY", + SANCTIONED_GEO_AREA = "SANCTIONED_GEO_AREA", } export interface InvalidityReason { @@ -117,6 +118,7 @@ export const InvalidityReason = new Schema({ "KUSAMA_RANK", "PROVIDER", "BEEFY", + "SANCTIONED_GEO_AREA", ], default: "NEW", }, diff --git a/packages/common/src/db/queries/Candidate.ts b/packages/common/src/db/queries/Candidate.ts index f698e78a6..b9e03cbf2 100644 --- a/packages/common/src/db/queries/Candidate.ts +++ b/packages/common/src/db/queries/Candidate.ts @@ -1435,6 +1435,21 @@ export const setBeefyKeysInvalidity = async ( ).exec(); }; +// Set Sanctions Validity Status +export const setSanctionedGeoAreaValidity = async ( + slotId: number, + isValid: boolean, +): Promise => { + const candidate = await getCandidateBySlotId(slotId); + const invalidityMessage = `${candidate.name} in sanctioned area.`; + setCandidateInvalidity( + candidate, + InvalidityReasonType.SANCTIONED_GEO_AREA, + isValid, + invalidityMessage, + ); +}; + // Sets valid boolean for node export const setValid = async ( address: string, diff --git a/packages/core/config/kusama.current.dev.sample.json b/packages/core/config/kusama.current.dev.sample.json index 50606cb0a..908823431 100644 --- a/packages/core/config/kusama.current.dev.sample.json +++ b/packages/core/config/kusama.current.dev.sample.json @@ -18,10 +18,13 @@ "skipIdentity": false, "skipClientUpgrade": false, "skipUnclaimed": false, + "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.30", "minSelfStake": 10000000000000, "commission": 150000000, - "unclaimedEraThreshold": 4 + "unclaimedEraThreshold": 4, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] }, "cron": { "monitor": "0 */15 * * * *", diff --git a/packages/core/config/kusama.current.sample.json b/packages/core/config/kusama.current.sample.json index a1efba2a8..3f5ede9e2 100644 --- a/packages/core/config/kusama.current.sample.json +++ b/packages/core/config/kusama.current.sample.json @@ -39,10 +39,13 @@ "skipIdentity": false, "skipClientUpgrade": false, "skipUnclaimed": false, + "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.30", "minSelfStake": 10000000000000, "commission": 150000000, - "unclaimedEraThreshold": 4 + "unclaimedEraThreshold": 4, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] }, "db": { "mongo": { diff --git a/packages/core/config/kusama.microservice.dev.sample.json b/packages/core/config/kusama.microservice.dev.sample.json index 70615363e..36858a93f 100644 --- a/packages/core/config/kusama.microservice.dev.sample.json +++ b/packages/core/config/kusama.microservice.dev.sample.json @@ -40,10 +40,13 @@ "skipIdentity": false, "skipClientUpgrade": false, "skipUnclaimed": false, + "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.30", "minSelfStake": 10000000000000, "commission": 150000000, - "unclaimedEraThreshold": 4 + "unclaimedEraThreshold": 4, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] }, "db": { "mongo": { diff --git a/packages/core/config/kusama.microservice.sample.json b/packages/core/config/kusama.microservice.sample.json index a948ebdcc..45a794365 100644 --- a/packages/core/config/kusama.microservice.sample.json +++ b/packages/core/config/kusama.microservice.sample.json @@ -19,10 +19,13 @@ "skipIdentity": false, "skipClientUpgrade": false, "skipUnclaimed": false, + "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.30", "minSelfStake": 10000000000000, "commission": 150000000, - "unclaimedEraThreshold": 4 + "unclaimedEraThreshold": 4, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] }, "db": { "mongo": { diff --git a/packages/core/config/main.sample.json b/packages/core/config/main.sample.json index 7658082e5..5a46e6f41 100644 --- a/packages/core/config/main.sample.json +++ b/packages/core/config/main.sample.json @@ -23,10 +23,13 @@ "skipIdentity": false, "skipStakedDestination": true, "skipClientUpgrade": true, + "skipSanctionedGeoArea": false, "skipUnclaimed": true, "minSelfStake": 100000, "commission": 150000000, - "unclaimedEraThreshold": 4 + "unclaimedEraThreshold": 4, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] }, "proxy": { "timeDelayBlocks": "35" diff --git a/packages/core/config/polkadot.current.dev.sample.json b/packages/core/config/polkadot.current.dev.sample.json index 3b1954b80..81df1127a 100644 --- a/packages/core/config/polkadot.current.dev.sample.json +++ b/packages/core/config/polkadot.current.dev.sample.json @@ -37,11 +37,14 @@ "skipConnectionTime": true, "skipIdentity": false, "skipClientUpgrade": false, + "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.39", "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, - "unclaimedEraThreshold": 1 + "unclaimedEraThreshold": 1, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] }, "db": { "mongo": { diff --git a/packages/core/config/polkadot.current.sample.json b/packages/core/config/polkadot.current.sample.json index 4819472f0..0a8142b41 100644 --- a/packages/core/config/polkadot.current.sample.json +++ b/packages/core/config/polkadot.current.sample.json @@ -14,11 +14,14 @@ "skipConnectionTime": false, "skipIdentity": false, "skipClientUpgrade": false, + "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.39", "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, - "unclaimedEraThreshold": 1 + "unclaimedEraThreshold": 1, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] }, "cron": { "monitorEnabled": true, diff --git a/packages/core/config/polkadot.microservice.dev.sample.json b/packages/core/config/polkadot.microservice.dev.sample.json index e40880060..fbb945c15 100644 --- a/packages/core/config/polkadot.microservice.dev.sample.json +++ b/packages/core/config/polkadot.microservice.dev.sample.json @@ -16,11 +16,14 @@ "skipConnectionTime": false, "skipIdentity": false, "skipClientUpgrade": false, + "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.39", "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, - "unclaimedEraThreshold": 1 + "unclaimedEraThreshold": 1, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] }, "db": { "mongo": { diff --git a/packages/core/config/polkadot.microservice.sample.json b/packages/core/config/polkadot.microservice.sample.json index 465ac5d3f..1d296521d 100644 --- a/packages/core/config/polkadot.microservice.sample.json +++ b/packages/core/config/polkadot.microservice.sample.json @@ -16,11 +16,14 @@ "skipConnectionTime": false, "skipIdentity": false, "skipClientUpgrade": false, + "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.39", "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, - "unclaimedEraThreshold": 1 + "unclaimedEraThreshold": 1, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] }, "db": { "mongo": { From a5c838647a0102556836fdc2ed113deb875d3ee0 Mon Sep 17 00:00:00 2001 From: Michalis Fragkiadakis Date: Thu, 11 Apr 2024 16:50:30 +0300 Subject: [PATCH 2/8] Format location to match arrays is config --- packages/common/src/constraints/ValidityChecks.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/common/src/constraints/ValidityChecks.ts b/packages/common/src/constraints/ValidityChecks.ts index 3894d068b..4ad301de9 100644 --- a/packages/common/src/constraints/ValidityChecks.ts +++ b/packages/common/src/constraints/ValidityChecks.ts @@ -454,8 +454,11 @@ export const checkSanctionedGeoArea = async ( const sanctionedCountries = config.constraints?.sanctionedCountries; const sanctionedRegions = config.constraints?.sanctionedRegions; if ( - sanctionedCountries.includes(location.country) || - sanctionedRegions.includes(location.region) + sanctionedCountries.includes(location.country.trim().toUpperCase()) || + sanctionedRegions.includes( + location.region.trim().charAt(0).toUpperCase() + + location.region.trim().slice(1).toLowerCase(), + ) ) { logger.info( `${candidate.name} is in a sanctioned location: Country: ${location.country}, Region: ${location.region}`, From 3df6be919d4b0c0ff8a794d98f2dd434d749dc8c Mon Sep 17 00:00:00 2001 From: Michalis Fragkiadakis Date: Thu, 11 Apr 2024 19:54:27 +0300 Subject: [PATCH 3/8] Convert country and region to lowercase for comparison --- .../common/src/constraints/ValidityChecks.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/common/src/constraints/ValidityChecks.ts b/packages/common/src/constraints/ValidityChecks.ts index 4ad301de9..bb3e50843 100644 --- a/packages/common/src/constraints/ValidityChecks.ts +++ b/packages/common/src/constraints/ValidityChecks.ts @@ -451,14 +451,16 @@ export const checkSanctionedGeoArea = async ( candidate.name, ); if (location && location.region && location.country) { - const sanctionedCountries = config.constraints?.sanctionedCountries; - const sanctionedRegions = config.constraints?.sanctionedRegions; + const sanctionedCountries = config.constraints?.sanctionedCountries.map( + (x) => x.trim().toLowerCase(), + ); + const sanctionedRegions = config.constraints?.sanctionedRegions.map((x) => + x.trim().toLowerCase(), + ); + if ( - sanctionedCountries.includes(location.country.trim().toUpperCase()) || - sanctionedRegions.includes( - location.region.trim().charAt(0).toUpperCase() + - location.region.trim().slice(1).toLowerCase(), - ) + sanctionedCountries.includes(location.country.trim().toLowerCase()) || + sanctionedRegions.includes(location.region.trim().toLowerCase()) ) { logger.info( `${candidate.name} is in a sanctioned location: Country: ${location.country}, Region: ${location.region}`, From d071ec57398e3613f25356d1e03a90211b07ddcf Mon Sep 17 00:00:00 2001 From: Michalis Fragkiadakis Date: Fri, 12 Apr 2024 12:41:23 +0300 Subject: [PATCH 4/8] Updated regions array --- packages/core/config/kusama.current.dev.sample.json | 2 +- packages/core/config/kusama.current.sample.json | 2 +- packages/core/config/kusama.microservice.dev.sample.json | 2 +- packages/core/config/kusama.microservice.sample.json | 2 +- packages/core/config/main.sample.json | 2 +- packages/core/config/polkadot.current.dev.sample.json | 2 +- packages/core/config/polkadot.current.sample.json | 2 +- packages/core/config/polkadot.microservice.dev.sample.json | 2 +- packages/core/config/polkadot.microservice.sample.json | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/core/config/kusama.current.dev.sample.json b/packages/core/config/kusama.current.dev.sample.json index 908823431..2da4a436c 100644 --- a/packages/core/config/kusama.current.dev.sample.json +++ b/packages/core/config/kusama.current.dev.sample.json @@ -24,7 +24,7 @@ "commission": 150000000, "unclaimedEraThreshold": 4, "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] }, "cron": { "monitor": "0 */15 * * * *", diff --git a/packages/core/config/kusama.current.sample.json b/packages/core/config/kusama.current.sample.json index 3f5ede9e2..e9419ac80 100644 --- a/packages/core/config/kusama.current.sample.json +++ b/packages/core/config/kusama.current.sample.json @@ -45,7 +45,7 @@ "commission": 150000000, "unclaimedEraThreshold": 4, "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] }, "db": { "mongo": { diff --git a/packages/core/config/kusama.microservice.dev.sample.json b/packages/core/config/kusama.microservice.dev.sample.json index 36858a93f..eabcf8f0d 100644 --- a/packages/core/config/kusama.microservice.dev.sample.json +++ b/packages/core/config/kusama.microservice.dev.sample.json @@ -46,7 +46,7 @@ "commission": 150000000, "unclaimedEraThreshold": 4, "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] }, "db": { "mongo": { diff --git a/packages/core/config/kusama.microservice.sample.json b/packages/core/config/kusama.microservice.sample.json index 45a794365..f981d0921 100644 --- a/packages/core/config/kusama.microservice.sample.json +++ b/packages/core/config/kusama.microservice.sample.json @@ -25,7 +25,7 @@ "commission": 150000000, "unclaimedEraThreshold": 4, "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] }, "db": { "mongo": { diff --git a/packages/core/config/main.sample.json b/packages/core/config/main.sample.json index 5a46e6f41..02b140f91 100644 --- a/packages/core/config/main.sample.json +++ b/packages/core/config/main.sample.json @@ -29,7 +29,7 @@ "commission": 150000000, "unclaimedEraThreshold": 4, "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] }, "proxy": { "timeDelayBlocks": "35" diff --git a/packages/core/config/polkadot.current.dev.sample.json b/packages/core/config/polkadot.current.dev.sample.json index 81df1127a..b6a09d93b 100644 --- a/packages/core/config/polkadot.current.dev.sample.json +++ b/packages/core/config/polkadot.current.dev.sample.json @@ -44,7 +44,7 @@ "commission": 50000000, "unclaimedEraThreshold": 1, "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] }, "db": { "mongo": { diff --git a/packages/core/config/polkadot.current.sample.json b/packages/core/config/polkadot.current.sample.json index 0a8142b41..5365c97b2 100644 --- a/packages/core/config/polkadot.current.sample.json +++ b/packages/core/config/polkadot.current.sample.json @@ -21,7 +21,7 @@ "commission": 50000000, "unclaimedEraThreshold": 1, "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] }, "cron": { "monitorEnabled": true, diff --git a/packages/core/config/polkadot.microservice.dev.sample.json b/packages/core/config/polkadot.microservice.dev.sample.json index fbb945c15..0cb1893f8 100644 --- a/packages/core/config/polkadot.microservice.dev.sample.json +++ b/packages/core/config/polkadot.microservice.dev.sample.json @@ -23,7 +23,7 @@ "commission": 50000000, "unclaimedEraThreshold": 1, "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] }, "db": { "mongo": { diff --git a/packages/core/config/polkadot.microservice.sample.json b/packages/core/config/polkadot.microservice.sample.json index 1d296521d..ebb5854ec 100644 --- a/packages/core/config/polkadot.microservice.sample.json +++ b/packages/core/config/polkadot.microservice.sample.json @@ -23,7 +23,7 @@ "commission": 50000000, "unclaimedEraThreshold": 1, "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Luhansk", "Donetsk"] + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] }, "db": { "mongo": { From 944206a4aeb2ad0da8c05c68975fd0eb37236f73 Mon Sep 17 00:00:00 2001 From: Alessio Onori Date: Mon, 15 Apr 2024 14:39:16 +0200 Subject: [PATCH 5/8] refactor config shape --- .../templates/kusama-otv-backend.yaml | 7 +- .../templates/polkadot-otv-backend.yaml | 7 +- .../templates/kusama-otv-backend.yaml | 7 +- .../templates/polkadot-otv-backend.yaml | 7 +- charts/otv-backend/values.yaml | 6 +- packages/common/src/config.ts | 8 ++- .../common/src/constraints/CheckCandidates.ts | 2 +- .../common/src/constraints/ValidityChecks.ts | 69 +++++++++++-------- packages/common/src/db/queries/Candidate.ts | 3 +- .../config/kusama.current.dev.sample.json | 8 ++- .../core/config/kusama.current.sample.json | 8 ++- .../kusama.microservice.dev.sample.json | 8 ++- .../config/kusama.microservice.sample.json | 8 ++- packages/core/config/main.sample.json | 8 ++- .../config/polkadot.current.dev.sample.json | 8 ++- .../core/config/polkadot.current.sample.json | 8 ++- .../polkadot.microservice.dev.sample.json | 8 ++- .../config/polkadot.microservice.sample.json | 8 ++- 18 files changed, 121 insertions(+), 67 deletions(-) diff --git a/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml b/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml index 390752c88..43f17a41f 100644 --- a/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml +++ b/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml @@ -60,7 +60,12 @@ spec: "skipUnclaimed": true, "minSelfStake": 10000000000000, "commission": 150000000, - "unclaimedEraThreshold": 4 + "unclaimedEraThreshold": 4, + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + } }, "cron": { "monitor": "0 */15 * * * *", diff --git a/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml b/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml index c804f49b3..ffb636811 100644 --- a/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml +++ b/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml @@ -59,7 +59,12 @@ spec: "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, - "unclaimedEraThreshold": 1 + "unclaimedEraThreshold": 1, + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + } }, "cron": { "monitor": "0 */15 * * * *", diff --git a/apps/1kv-backend/templates/kusama-otv-backend.yaml b/apps/1kv-backend/templates/kusama-otv-backend.yaml index 791f8ad7e..ea7ae2da1 100644 --- a/apps/1kv-backend/templates/kusama-otv-backend.yaml +++ b/apps/1kv-backend/templates/kusama-otv-backend.yaml @@ -58,7 +58,12 @@ spec: "skipUnclaimed": true, "minSelfStake": 10000000000000, "commission": 150000000, - "unclaimedEraThreshold": 4 + "unclaimedEraThreshold": 4, + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + } }, "cron": { "monitor": "0 */15 * * * *", diff --git a/apps/1kv-backend/templates/polkadot-otv-backend.yaml b/apps/1kv-backend/templates/polkadot-otv-backend.yaml index 41d5f6065..409a13b0a 100644 --- a/apps/1kv-backend/templates/polkadot-otv-backend.yaml +++ b/apps/1kv-backend/templates/polkadot-otv-backend.yaml @@ -57,7 +57,12 @@ spec: "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, - "unclaimedEraThreshold": 1 + "unclaimedEraThreshold": 1, + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], + "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + } }, "cron": { "monitor": "0 */15 * * * *", diff --git a/charts/otv-backend/values.yaml b/charts/otv-backend/values.yaml index 53c1ec6e4..861175842 100644 --- a/charts/otv-backend/values.yaml +++ b/charts/otv-backend/values.yaml @@ -49,7 +49,11 @@ config: | "constraints": { "skipConnectionTime": false, "skipIdentity": false, - "skipSanctionedGeoArea": false + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX" ] + } }, "db": { "mongo": { diff --git a/packages/common/src/config.ts b/packages/common/src/config.ts index e6cec2992..015a700e4 100644 --- a/packages/common/src/config.ts +++ b/packages/common/src/config.ts @@ -27,13 +27,15 @@ export type ConfigSchema = { skipClientUpgrade: boolean; skipUnclaimed: boolean; skipClaiming: boolean; - skipSanctionedGeoArea: boolean; forceClientVersion: string; minSelfStake: number; commission: number; unclaimedEraThreshold: number; - sanctionedCountries: string[]; - sanctionedRegions: string[]; + sanctionedGeoArea?: { + skip: boolean; + sanctionedCountries: string[]; + sanctionedRegions: string[]; + }; }; cron: { monitor: string; diff --git a/packages/common/src/constraints/CheckCandidates.ts b/packages/common/src/constraints/CheckCandidates.ts index 515369b62..2d1492598 100644 --- a/packages/common/src/constraints/CheckCandidates.ts +++ b/packages/common/src/constraints/CheckCandidates.ts @@ -131,7 +131,7 @@ export const checkCandidate = async ( } const sanctionedGeoAreaValid = - constraints.config?.constraints?.skipSanctionedGeoArea == true + constraints.config?.constraints?.sanctionedGeoArea?.skip == true ? true : (await checkSanctionedGeoArea(constraints.config, candidate)) || false; diff --git a/packages/common/src/constraints/ValidityChecks.ts b/packages/common/src/constraints/ValidityChecks.ts index bf9db869b..eccb0da19 100644 --- a/packages/common/src/constraints/ValidityChecks.ts +++ b/packages/common/src/constraints/ValidityChecks.ts @@ -442,38 +442,49 @@ export const checkSanctionedGeoArea = async ( candidate: Candidate, ): Promise => { try { - const location = await queries.getCandidateLocation( - candidate.slotId, - candidate.name, - ); - if (location && location.region && location.country) { - const sanctionedCountries = config.constraints?.sanctionedCountries.map( - (x) => x.trim().toLowerCase(), - ); - const sanctionedRegions = config.constraints?.sanctionedRegions.map((x) => - x.trim().toLowerCase(), - ); + if ( + !config.constraints?.sanctionedGeoArea?.sanctionedCountries?.length && + !config.constraints?.sanctionedGeoArea?.sanctionedRegions?.length + ) { + setSanctionedGeoAreaValidity(candidate, true); + return true; + } - if ( - sanctionedCountries.includes(location.country.trim().toLowerCase()) || - sanctionedRegions.includes(location.region.trim().toLowerCase()) - ) { - logger.info( - `${candidate.name} is in a sanctioned location: Country: ${location.country}, Region: ${location.region}`, - { - label: "Constraints", - }, - ); - await setSanctionedGeoAreaValidity(candidate.slotId, false); - return false; - } else { - await setSanctionedGeoAreaValidity(candidate.slotId, true); - return true; - } - } else { - await setSanctionedGeoAreaValidity(candidate.slotId, true); + const location = await queries.getCandidateLocation(candidate.slotId); + if (!location?.region || !location?.country) { + setSanctionedGeoAreaValidity(candidate, true); return true; } + + const sanctionedCountries = config.constraints?.sanctionedGeoArea + ?.sanctionedCountries + ? config.constraints.sanctionedGeoArea.sanctionedCountries.map((x) => + x.trim().toLowerCase(), + ) + : []; + const sanctionedRegions = config.constraints?.sanctionedGeoArea + ?.sanctionedRegions + ? config.constraints.sanctionedGeoArea.sanctionedRegions.map((x) => + x.trim().toLowerCase(), + ) + : []; + + if ( + sanctionedCountries.includes(location.country.trim().toLowerCase()) || + sanctionedRegions.includes(location.region.trim().toLowerCase()) + ) { + logger.info( + `${candidate.name} is in a sanctioned location: Country: ${location.country}, Region: ${location.region}`, + { + label: "Constraints", + }, + ); + await setSanctionedGeoAreaValidity(candidate, false); + return false; + } + + await setSanctionedGeoAreaValidity(candidate, true); + return true; } catch (e) { logger.error( `Error checking location for sanctions: ${e}`, diff --git a/packages/common/src/db/queries/Candidate.ts b/packages/common/src/db/queries/Candidate.ts index 18e6eb9a5..ca3282426 100644 --- a/packages/common/src/db/queries/Candidate.ts +++ b/packages/common/src/db/queries/Candidate.ts @@ -1055,10 +1055,9 @@ export const setBeefyKeysInvalidity = async ( // Set Sanctions Validity Status export const setSanctionedGeoAreaValidity = async ( - slotId: number, + candidate: Candidate, isValid: boolean, ): Promise => { - const candidate = await getCandidateBySlotId(slotId); const invalidityMessage = `${candidate.name} in sanctioned area.`; setCandidateInvalidity( candidate, diff --git a/packages/core/config/kusama.current.dev.sample.json b/packages/core/config/kusama.current.dev.sample.json index 2da4a436c..28370f684 100644 --- a/packages/core/config/kusama.current.dev.sample.json +++ b/packages/core/config/kusama.current.dev.sample.json @@ -18,13 +18,15 @@ "skipIdentity": false, "skipClientUpgrade": false, "skipUnclaimed": false, - "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.30", "minSelfStake": 10000000000000, "commission": 150000000, "unclaimedEraThreshold": 4, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX"] + } }, "cron": { "monitor": "0 */15 * * * *", diff --git a/packages/core/config/kusama.current.sample.json b/packages/core/config/kusama.current.sample.json index e9419ac80..371dbeb13 100644 --- a/packages/core/config/kusama.current.sample.json +++ b/packages/core/config/kusama.current.sample.json @@ -39,13 +39,15 @@ "skipIdentity": false, "skipClientUpgrade": false, "skipUnclaimed": false, - "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.30", "minSelfStake": 10000000000000, "commission": 150000000, "unclaimedEraThreshold": 4, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX"] + } }, "db": { "mongo": { diff --git a/packages/core/config/kusama.microservice.dev.sample.json b/packages/core/config/kusama.microservice.dev.sample.json index eabcf8f0d..2fdcd6fa1 100644 --- a/packages/core/config/kusama.microservice.dev.sample.json +++ b/packages/core/config/kusama.microservice.dev.sample.json @@ -40,13 +40,15 @@ "skipIdentity": false, "skipClientUpgrade": false, "skipUnclaimed": false, - "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.30", "minSelfStake": 10000000000000, "commission": 150000000, "unclaimedEraThreshold": 4, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX"] + } }, "db": { "mongo": { diff --git a/packages/core/config/kusama.microservice.sample.json b/packages/core/config/kusama.microservice.sample.json index f981d0921..d25cb275d 100644 --- a/packages/core/config/kusama.microservice.sample.json +++ b/packages/core/config/kusama.microservice.sample.json @@ -19,13 +19,15 @@ "skipIdentity": false, "skipClientUpgrade": false, "skipUnclaimed": false, - "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.30", "minSelfStake": 10000000000000, "commission": 150000000, "unclaimedEraThreshold": 4, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX"] + } }, "db": { "mongo": { diff --git a/packages/core/config/main.sample.json b/packages/core/config/main.sample.json index 02b140f91..6bc510aec 100644 --- a/packages/core/config/main.sample.json +++ b/packages/core/config/main.sample.json @@ -23,13 +23,15 @@ "skipIdentity": false, "skipStakedDestination": true, "skipClientUpgrade": true, - "skipSanctionedGeoArea": false, "skipUnclaimed": true, "minSelfStake": 100000, "commission": 150000000, "unclaimedEraThreshold": 4, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX"] + } }, "proxy": { "timeDelayBlocks": "35" diff --git a/packages/core/config/polkadot.current.dev.sample.json b/packages/core/config/polkadot.current.dev.sample.json index b6a09d93b..5ae6c494a 100644 --- a/packages/core/config/polkadot.current.dev.sample.json +++ b/packages/core/config/polkadot.current.dev.sample.json @@ -37,14 +37,16 @@ "skipConnectionTime": true, "skipIdentity": false, "skipClientUpgrade": false, - "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.39", "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, "unclaimedEraThreshold": 1, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX"] + } }, "db": { "mongo": { diff --git a/packages/core/config/polkadot.current.sample.json b/packages/core/config/polkadot.current.sample.json index 5365c97b2..3912aac70 100644 --- a/packages/core/config/polkadot.current.sample.json +++ b/packages/core/config/polkadot.current.sample.json @@ -14,14 +14,16 @@ "skipConnectionTime": false, "skipIdentity": false, "skipClientUpgrade": false, - "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.39", "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, "unclaimedEraThreshold": 1, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX"] + } }, "cron": { "monitorEnabled": true, diff --git a/packages/core/config/polkadot.microservice.dev.sample.json b/packages/core/config/polkadot.microservice.dev.sample.json index 0cb1893f8..9c542ccea 100644 --- a/packages/core/config/polkadot.microservice.dev.sample.json +++ b/packages/core/config/polkadot.microservice.dev.sample.json @@ -16,14 +16,16 @@ "skipConnectionTime": false, "skipIdentity": false, "skipClientUpgrade": false, - "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.39", "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, "unclaimedEraThreshold": 1, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX"] + } }, "db": { "mongo": { diff --git a/packages/core/config/polkadot.microservice.sample.json b/packages/core/config/polkadot.microservice.sample.json index ebb5854ec..603658eb7 100644 --- a/packages/core/config/polkadot.microservice.sample.json +++ b/packages/core/config/polkadot.microservice.sample.json @@ -16,14 +16,16 @@ "skipConnectionTime": false, "skipIdentity": false, "skipClientUpgrade": false, - "skipSanctionedGeoArea": false, "forceClientVersion": "v0.9.39", "skipUnclaimed": true, "minSelfStake": 50000000000000, "commission": 50000000, "unclaimedEraThreshold": 1, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedGeoArea": { + "skip": false, + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX"] + } }, "db": { "mongo": { From 23c728f8dbc08410603e821645b060d7710aca94 Mon Sep 17 00:00:00 2001 From: Alessio Onori Date: Tue, 16 Apr 2024 13:45:40 +0200 Subject: [PATCH 6/8] update setCandidateInvalidity function --- .../templates/kusama-otv-backend.yaml | 4 +- .../templates/polkadot-otv-backend.yaml | 4 +- .../templates/kusama-otv-backend.yaml | 4 +- .../templates/polkadot-otv-backend.yaml | 4 +- .../common/src/constraints/ValidityChecks.ts | 4 +- packages/common/src/db/queries/Candidate.ts | 34 ++++++++--------- .../common/src/db/queries/CandidateUtils.ts | 37 ++++++++++++------- 7 files changed, 50 insertions(+), 41 deletions(-) diff --git a/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml b/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml index 43f17a41f..48386f374 100644 --- a/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml +++ b/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml @@ -63,8 +63,8 @@ spec: "unclaimedEraThreshold": 4, "sanctionedGeoArea": { "skip": false, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX" ] } }, "cron": { diff --git a/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml b/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml index ffb636811..15d8cb2b0 100644 --- a/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml +++ b/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml @@ -62,8 +62,8 @@ spec: "unclaimedEraThreshold": 1, "sanctionedGeoArea": { "skip": false, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX" ] } }, "cron": { diff --git a/apps/1kv-backend/templates/kusama-otv-backend.yaml b/apps/1kv-backend/templates/kusama-otv-backend.yaml index ea7ae2da1..43465a11a 100644 --- a/apps/1kv-backend/templates/kusama-otv-backend.yaml +++ b/apps/1kv-backend/templates/kusama-otv-backend.yaml @@ -61,8 +61,8 @@ spec: "unclaimedEraThreshold": 4, "sanctionedGeoArea": { "skip": false, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX" ] } }, "cron": { diff --git a/apps/1kv-backend/templates/polkadot-otv-backend.yaml b/apps/1kv-backend/templates/polkadot-otv-backend.yaml index 409a13b0a..ce5c4e912 100644 --- a/apps/1kv-backend/templates/polkadot-otv-backend.yaml +++ b/apps/1kv-backend/templates/polkadot-otv-backend.yaml @@ -60,8 +60,8 @@ spec: "unclaimedEraThreshold": 1, "sanctionedGeoArea": { "skip": false, - "sanctionedCountries": ["RU", "IR", "CU", "KP", "SY"], - "sanctionedRegions": ["Crimea", "Autonomous Republic of Crimea", "Republic of Crimea", "Luhansk", "Luhanska Oblast", "Luhanska", "Luganskaya Oblast’", "Luganskaya", "Donetsk", "Donetska Oblast", "Donetskaya Oblast’", "Donetska", "Donetskaya", "Sevastopol City", "Sevastopol", "Gorod Sevastopol" ] + "sanctionedCountries": ["XXX"], + "sanctionedRegions": ["XXX" ] } }, "cron": { diff --git a/packages/common/src/constraints/ValidityChecks.ts b/packages/common/src/constraints/ValidityChecks.ts index eccb0da19..969266e2e 100644 --- a/packages/common/src/constraints/ValidityChecks.ts +++ b/packages/common/src/constraints/ValidityChecks.ts @@ -446,13 +446,13 @@ export const checkSanctionedGeoArea = async ( !config.constraints?.sanctionedGeoArea?.sanctionedCountries?.length && !config.constraints?.sanctionedGeoArea?.sanctionedRegions?.length ) { - setSanctionedGeoAreaValidity(candidate, true); + await setSanctionedGeoAreaValidity(candidate, true); return true; } const location = await queries.getCandidateLocation(candidate.slotId); if (!location?.region || !location?.country) { - setSanctionedGeoAreaValidity(candidate, true); + await setSanctionedGeoAreaValidity(candidate, true); return true; } diff --git a/packages/common/src/db/queries/Candidate.ts b/packages/common/src/db/queries/Candidate.ts index ca3282426..a389ab07d 100644 --- a/packages/common/src/db/queries/Candidate.ts +++ b/packages/common/src/db/queries/Candidate.ts @@ -339,7 +339,7 @@ export const getIdentityAddresses = async ( export const setCandidateOnlineValid = async ( candidate: Candidate, ): Promise => { - setCandidateInvalidity(candidate, InvalidityReasonType.ONLINE, true); + await setCandidateInvalidity(candidate, InvalidityReasonType.ONLINE, true); await CandidateModel.findOneAndUpdate( { @@ -355,7 +355,7 @@ export const setCandidateOnlineNotValid = async ( candidate: Candidate, ): Promise => { const invalidityMessage = `Candidate ${candidate.name} offline. Offline since ${Date.now()}.`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.ONLINE, false, @@ -827,7 +827,7 @@ export const setOnlineValidity = async ( ): Promise => { const candidate = await getCandidateBySlotId(slotId); const invalidityMessage = `${candidate.name} offline. Last seen online ${candidate.onlineSince}.`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.ONLINE, isValid, @@ -841,7 +841,7 @@ export const setValidateIntentionValidity = async ( isValid: boolean, ): Promise => { const invalidityMessage = `${candidate.name} does not have a validate intention.`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.VALIDATE_INTENTION, isValid, @@ -855,7 +855,7 @@ export const setLatestClientReleaseValidity = async ( isValid: boolean, ): Promise => { const invalidityMessage = `${candidate.name} is not on the latest client version`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.CLIENT_UPGRADE, isValid, @@ -870,7 +870,7 @@ export const setConnectionTimeInvalidity = async ( isValid: boolean, ): Promise => { const invalidityMessage = `${candidate.name} has not been connected for minimum length`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.CONNECTION_TIME, isValid, @@ -888,7 +888,7 @@ export const setIdentityInvalidity = async ( const invalidityMessage = message ? message : `${candidate.name} has not properly set their identity`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.IDENTITY, isValid, @@ -903,7 +903,7 @@ export const setOfflineAccumulatedInvalidity = async ( isValid: boolean, ): Promise => { const invalidityMessage = `${candidate.name} has been offline ${candidate.offlineAccumulated / 1000 / 60} minutes this week.`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.ACCUMULATED_OFFLINE_TIME, isValid, @@ -919,7 +919,7 @@ export const setRewardDestinationInvalidity = async ( isValid: boolean, ): Promise => { const invalidityMessage = `${candidate.name} does not have reward destination as Staked`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.REWARD_DESTINATION, isValid, @@ -937,7 +937,7 @@ export const setCommissionInvalidity = async ( const invalidityMessage = message ? message : `${candidate.name} has not properly set their commission`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.COMMISION, isValid, @@ -955,7 +955,7 @@ export const setSelfStakeInvalidity = async ( const invalidityMessage = message ? message : `${candidate.name} has not properly bonded enough self stake`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.SELF_STAKE, isValid, @@ -973,7 +973,7 @@ export const setUnclaimedInvalidity = async ( const invalidityMessage = message ? message : `${candidate.name} has not properly claimed era rewards`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.UNCLAIMED_REWARDS, isValid, @@ -991,7 +991,7 @@ export const setBlockedInvalidity = async ( const invalidityMessage = message ? message : `${candidate.name} blocks external nominations`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.BLOCKED, isValid, @@ -1009,7 +1009,7 @@ export const setProviderInvalidity = async ( const invalidityMessage = message ? message : `${candidate.name} has banned infrastructure provider`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.PROVIDER, isValid, @@ -1027,7 +1027,7 @@ export const setKusamaRankInvalidity = async ( const invalidityMessage = message ? message : `${candidate.name} has not properly claimed era rewards`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.KUSAMA_RANK, isValid, @@ -1044,7 +1044,7 @@ export const setBeefyKeysInvalidity = async ( const invalidityMessage = message ? message : `${candidate.name} does not have beefy keys`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.BEEFY, isValid, @@ -1059,7 +1059,7 @@ export const setSanctionedGeoAreaValidity = async ( isValid: boolean, ): Promise => { const invalidityMessage = `${candidate.name} in sanctioned area.`; - setCandidateInvalidity( + await setCandidateInvalidity( candidate, InvalidityReasonType.SANCTIONED_GEO_AREA, isValid, diff --git a/packages/common/src/db/queries/CandidateUtils.ts b/packages/common/src/db/queries/CandidateUtils.ts index 0abea84e2..24e7cea2c 100644 --- a/packages/common/src/db/queries/CandidateUtils.ts +++ b/packages/common/src/db/queries/CandidateUtils.ts @@ -35,25 +35,34 @@ export const setCandidateInvalidity = async ( ) => { if (skipIfNoData && !isCandidateInvaliditySet(candidate)) return; - const invalidityReasons = filterCandidateInvalidityFields( - candidate, - invalidityType, - ); + const invalidityReason: InvalidityReason = { + valid: isValid, + type: invalidityType, + updated: Date.now(), + details: isValid ? "" : `${invalidityMessage}`, + }; + + await CandidateModel.updateOne( + { + slotId: candidate.slotId, + "invalidity.type": invalidityType, + }, + { + $set: { + "invalidity.$": invalidityReason, + }, + }, + ).exec(); - await CandidateModel.findOneAndUpdate( + await CandidateModel.updateOne( { slotId: candidate.slotId, + "invalidity.type": { $ne: invalidityType }, }, { - invalidity: [ - ...invalidityReasons, - { - valid: isValid, - type: invalidityType, - updated: Date.now(), - details: isValid ? "" : `${invalidityMessage}`, - }, - ], + $push: { + invalidity: invalidityReason, + }, }, ).exec(); }; From b0e3689e2fdfbd3e64941f5f27752d8469f67b1f Mon Sep 17 00:00:00 2001 From: Alessio Onori Date: Tue, 16 Apr 2024 13:53:22 +0200 Subject: [PATCH 7/8] default config --- apps/1kv-backend-staging/templates/kusama-otv-backend.yaml | 2 +- apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml | 2 +- apps/1kv-backend/templates/kusama-otv-backend.yaml | 2 +- apps/1kv-backend/templates/polkadot-otv-backend.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml b/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml index 48386f374..ae5c6ff38 100644 --- a/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml +++ b/apps/1kv-backend-staging/templates/kusama-otv-backend.yaml @@ -62,7 +62,7 @@ spec: "commission": 150000000, "unclaimedEraThreshold": 4, "sanctionedGeoArea": { - "skip": false, + "skip": true, "sanctionedCountries": ["XXX"], "sanctionedRegions": ["XXX" ] } diff --git a/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml b/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml index 15d8cb2b0..317427d07 100644 --- a/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml +++ b/apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml @@ -61,7 +61,7 @@ spec: "commission": 50000000, "unclaimedEraThreshold": 1, "sanctionedGeoArea": { - "skip": false, + "skip": true, "sanctionedCountries": ["XXX"], "sanctionedRegions": ["XXX" ] } diff --git a/apps/1kv-backend/templates/kusama-otv-backend.yaml b/apps/1kv-backend/templates/kusama-otv-backend.yaml index 43465a11a..15e20c7bb 100644 --- a/apps/1kv-backend/templates/kusama-otv-backend.yaml +++ b/apps/1kv-backend/templates/kusama-otv-backend.yaml @@ -60,7 +60,7 @@ spec: "commission": 150000000, "unclaimedEraThreshold": 4, "sanctionedGeoArea": { - "skip": false, + "skip": true, "sanctionedCountries": ["XXX"], "sanctionedRegions": ["XXX" ] } diff --git a/apps/1kv-backend/templates/polkadot-otv-backend.yaml b/apps/1kv-backend/templates/polkadot-otv-backend.yaml index ce5c4e912..b4548e178 100644 --- a/apps/1kv-backend/templates/polkadot-otv-backend.yaml +++ b/apps/1kv-backend/templates/polkadot-otv-backend.yaml @@ -59,7 +59,7 @@ spec: "commission": 50000000, "unclaimedEraThreshold": 1, "sanctionedGeoArea": { - "skip": false, + "skip": true, "sanctionedCountries": ["XXX"], "sanctionedRegions": ["XXX" ] } From 814689419a992c95702fac16caaac5cdfed7cccf Mon Sep 17 00:00:00 2001 From: Alessio Onori Date: Tue, 16 Apr 2024 13:58:13 +0200 Subject: [PATCH 8/8] bump versions --- 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 27bea09f7..712c255ee 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.1.16 + targetRevision: v3.2.0 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 447340ea9..d07e974ac 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.1.16 + targetRevision: v3.2.0 plugin: env: - name: HELM_VALUES diff --git a/charts/otv-backend/Chart.yaml b/charts/otv-backend/Chart.yaml index af51c4177..7de1cb298 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.1.16 -appVersion: v3.1.16 +version: v3.2.0 +appVersion: v3.2.0 apiVersion: v2 diff --git a/packages/common/package.json b/packages/common/package.json index 3a16729db..7d7156b6d 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/common", - "version": "3.1.16", + "version": "3.2.0", "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 b45441b55..ac41fec11 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/core", - "version": "3.1.16", + "version": "3.2.0", "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 7a4821e90..5e5b2795e 100644 --- a/packages/gateway/package.json +++ b/packages/gateway/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/gateway", - "version": "3.1.16", + "version": "3.2.0", "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 aa44345e3..eac6502d3 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.1.16", + "version": "3.2.0", "type": "module", "scripts": { "dev": "vite", diff --git a/packages/telemetry/package.json b/packages/telemetry/package.json index ae4299cb3..42173a63b 100644 --- a/packages/telemetry/package.json +++ b/packages/telemetry/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/telemetry", - "version": "3.1.16", + "version": "3.2.0", "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 65c5e21c8..77ad78ac3 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -1,6 +1,6 @@ { "name": "@1kv/worker", - "version": "3.1.16", + "version": "3.2.0", "description": "Services for running the Thousand Validator Program.", "main": "build/index.js", "types": "build/index.d.ts",