Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/config #296

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
- checkout
- setup_remote_docker:
docker_layer_caching: true
version: 20.10.7
- run:
command: |
/scripts/build-image.sh web3f/polkadot-watcher .
Expand Down
4 changes: 2 additions & 2 deletions charts/polkadot-watcher/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: Polkadot Watcher
name: polkadot-watcher
version: v4.4.4
appVersion: v4.4.4
version: v4.4.5
appVersion: v4.4.5
apiVersion: v2
3 changes: 2 additions & 1 deletion config/main.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ endpoint: "wss://kusama-rpc.polkadot.io/"
port: 3000
logLevel: info
environment: production
commissionLogic: eq #optional | lt | eq
validatorsFromGit: #optional
enabled: false
platform: gitLab
Expand All @@ -15,4 +16,4 @@ validators: #optional
address: Gt6HqWBhdu4Sy1u8ASTbS1qf2Ac5gwdegwr8tWN8saMxPt5
expected: #optional
commission: 0.17 #optional
payee: Gt6HqWBhdu4Sy1u8ASTbS1qf2Ac5gwdegwr8tWN8saMxPt5 #optional
payee: Gt6HqWBhdu4Sy1u8ASTbS1qf2Ac5gwdegwr8tWN8saMxPt5 #optional | Staked | Stash | Controller | None
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkadot-watcher",
"version": "4.4.4",
"version": "4.4.5",
"description": "Monitor events on Polkadot networks",
"repository": "[email protected]:w3f/polkadot-watcher.git",
"author": "W3F Infrastructure Team <[email protected]>",
Expand All @@ -20,7 +20,7 @@
"start": "node ./dist/index.js start"
},
"dependencies": {
"@polkadot/api": "^13.1.1",
"@polkadot/api": "^14.3.1",
"@w3f/config": "^0.1.1",
"@w3f/logger": "^0.4.2",
"commander": "^4.0.0",
Expand Down
45 changes: 38 additions & 7 deletions src/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Subscriber {
private readonly logger = LoggerSingleton.getInstance()

constructor(
cfg: InputConfig,
private readonly cfg: InputConfig,
private readonly api: ApiPromise,
private readonly promClient: PromClient) {

Expand Down Expand Up @@ -70,22 +70,53 @@ export class Subscriber {
const tmp = await this.api.derive.staking.queryMulti(this.validators.map(v=>v.address),{withDestination:true,withPrefs:true})
const stakingMap = new Map<string,DeriveStakingQuery>()
tmp.forEach(t=>stakingMap.set(t.accountId.toString(),t))

this.validators.forEach(v => {
let isOkCommission = true
const actualCommission = stakingMap.get(v.address).validatorPrefs.commission.toNumber() //expressed in ppb
if(!v.expected?.commission || v.expected.commission*10000000 == actualCommission){ //percentage to ppb conversion
if(v.expected?.commission){
isOkCommission = false
switch (this.cfg.commissionLogic) {
case "lt":
isOkCommission = actualCommission <= v.expected.commission*10000000
break;
default:
isOkCommission = actualCommission == v.expected.commission*10000000
}
}
if(isOkCommission)
this.promClient.resetStatusValidatorCommissionUnexpected(v.name,v.address)
} else {
else {
this.logger.info(`Detected Unexpected commission for validator ${v.name}: expected percentage ${v.expected.commission}, actual in ppb ${actualCommission}`)
this.promClient.setStatusValidatorCommissionUnexpected(v.name,v.address)
}

let isOkPayee = true
const actualRewardDestination = stakingMap.get(v.address).rewardDestination
if(v.expected?.payee && (!actualRewardDestination.isAccount || v.expected.payee != actualRewardDestination.asAccount.toString())){
if(v.expected?.payee){
isOkPayee = false
switch (v.expected.payee) {
case "Staked":
isOkPayee = actualRewardDestination.isStaked
break;
case "Stash":
isOkPayee = actualRewardDestination.isStash
break;
case "Controller":
isOkPayee = actualRewardDestination.isController
break;
case "None":
isOkPayee = actualRewardDestination.isNone
break;
default:
isOkPayee = actualRewardDestination.isAccount && v.expected.payee == actualRewardDestination.asAccount.toString()
break;
}
}
if(isOkPayee){
this.promClient.resetStatusValidatorPayeeUnexpected(v.name,v.address)
} else {
this.logger.info(`Detected Unexpected payee for validator ${v.name}: expected ${v.expected.payee}, actual ${JSON.stringify(actualRewardDestination)}`)
this.promClient.setStatusValidatorPayeeUnexpected(v.name,v.address)
} else {
this.promClient.resetStatusValidatorPayeeUnexpected(v.name,v.address)
}
})
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface InputConfig {
port: number;
endpoint: string;
validators?: Array<Subscribable>;
commissionLogic?: string;
validatorsFromGit?: {
enabled: boolean;
platform: string;
Expand Down
Loading
Loading