Skip to content

Commit

Permalink
Finish job without failure when balance is too low (#43)
Browse files Browse the repository at this point in the history
* Bump node version for vote-bot

* Catch errors for vote removal

* Apply update for payout bot as well

* Update messages

* Fix message for payout bot

* Update messages again
  • Loading branch information
puppetninja authored Dec 12, 2023
1 parent bb736a9 commit ca8855f
Show file tree
Hide file tree
Showing 9 changed files with 2,070 additions and 2,698 deletions.
2 changes: 1 addition & 1 deletion polkadot-payout-cron/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine
FROM node:20-alpine

RUN mkdir /home/node/app/ && chown -R node:node /home/node/app

Expand Down
1,911 changes: 755 additions & 1,156 deletions polkadot-payout-cron/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions polkadot-payout-cron/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"dependencies": {
"@polkadot/api": "^8.12.2",
"@polkadot/types": "^8.13.1",
"@slack/web-api": "^6.6.0",
"typescript": "^4.7.4"
"@polkadot/api": "^10.11.1",
"@polkadot/types": "^10.11.1",
"@slack/web-api": "^6.10.0",
"typescript": "^5.3.3"
},
"scripts": {
"build": "npx tsc -d"
Expand Down
16 changes: 10 additions & 6 deletions polkadot-payout-cron/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ import { WebClient } from '@slack/web-api';
import '@polkadot/api-augment/kusama';
import '@polkadot/types';

async function sendErrorToSlackAndExit(message: string) {
async function sendErrorToSlackAndExit(message: string, exitWithFailure: boolean = true) {
console.error(message);
if (process.env.SLACK_ALERT_TOKEN) {
const slackWeb = new WebClient(process.env.SLACK_ALERT_TOKEN!);
await slackWeb.chat.postMessage({ text: message, channel: process.env.SLACK_ALERT_CHANNEL! })
}
process.exit(1)
const exitCode = exitWithFailure ? 1 : 0;
process.exit(exitCode)
}
async function main() {
const provider = new WsProvider(`ws://${process.env.NODE_ENDPOINT!}:9944`);
Expand Down Expand Up @@ -95,7 +96,8 @@ async function main() {
console.log(`Number of past eras to pay out ${num_past_eras}`);
console.log(`Node RPC endpoint in use ${process.env.NODE_ENDPOINT}`);


// list of error codes that would allow the job to exit without failure
const exitWithoutFailureErrorCodes: number[] = [1010];

console.log(`Active Era is ${activeEra}`)
let controller_address = await api.query.staking.bonded(stash_account);
Expand Down Expand Up @@ -155,7 +157,7 @@ async function main() {
process.exit(0);
}
} else if (status.isInvalid || status.isDropped) {
let slackMessage = `Vote extrinsic failed for validator ${stash_alias}(${stash_account}) with error ${status}.`;
let slackMessage = `Payout extrinsic failed for validator ${stash_alias}(${stash_account}) with error ${status}.`;
sendErrorToSlackAndExit(slackMessage);
} else if (status.isRetracted) {
// fail the job but do not alert. It is likely the transaction will go through at next try.
Expand All @@ -164,8 +166,10 @@ async function main() {
}));
}
catch (e: any) {
let slackMessage = `Payout extrinsic failed on-chain submission for validator ${stash_alias} from payout address ${payout_alias} with error ${e.message}.`;
sendErrorToSlackAndExit(slackMessage);
const error_message: string = e.message
const exitWithFaiilure = exitWithoutFailureErrorCodes.indexOf(e.code) < 0 ? true : false
let slackMessage = `Payout extrinsic failed on-chain submission for validator ${stash_alias} from payout address ${payout_alias}(\`${payout_account}\`) with error ${error_message}.`;
sendErrorToSlackAndExit(slackMessage, exitWithFaiilure);
}
}

Expand Down
Loading

0 comments on commit ca8855f

Please sign in to comment.