Skip to content

Commit

Permalink
Merge pull request #6 from w3f/application
Browse files Browse the repository at this point in the history
new app implementation, more efficient
  • Loading branch information
ironoa authored Oct 26, 2022
2 parents 7ab6380 + 63274e2 commit c17821e
Show file tree
Hide file tree
Showing 28 changed files with 4,163 additions and 31 deletions.
74 changes: 69 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
version: 2

jobs:
helmLint:
docker:
- image: web3f/ci-commons:v3
steps:
- checkout
- run:
command: |
helm lint ./charts/polkadot-k8s-payouts
yarnLint:
docker:
- image: web3f/node-dind:v1
steps:
- checkout
- run: yarn
- run: yarn lint

buildImage:
docker:
- image: web3f/ci-commons:v3
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
version: 20.10.7
- run:
command: |
/scripts/build-image.sh web3f/polkadot-payouts .
publishImage:
docker:
- image: web3f/ci-commons:v3
steps:
- checkout
- setup_remote_docker
- run:
command: |
/scripts/publish-image.sh web3f/polkadot-payouts
integrationTests:
docker:
- image: web3f/ci-commons:v2.4.16
- image: web3f/ci-commons:v3
steps:
- checkout
- setup_remote_docker
Expand All @@ -14,23 +53,48 @@ jobs:
publishChart:
docker:
- image: web3f/ci-commons:v2.4.16
- image: web3f/ci-commons:v3
steps:
- checkout
- run:
command: |
/scripts/publish-chart.sh
workflows:
version: 2
test_and_deploy:
jobs:
- helmLint:
filters:
tags:
only: /.*/
- yarnLint:
filters:
tags:
only: /.*/
- buildImage:
context: dockerhub-bot
filters:
tags:
only: /.*/
requires:
- yarnLint
- helmLint
- integrationTests:
filters:
tags:
only: /.*/

requires:
- buildImage
- publishImage:
context: dockerhub-bot
filters:
branches:
ignore: /.*/
tags:
only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
requires:
- integrationTests
- publishChart:
context: github-bot
filters:
Expand All @@ -39,4 +103,4 @@ workflows:
tags:
only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
requires:
- integrationTests
- integrationTests
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*
!package.json
!yarn.lock
!src
!tsconfig.json
!.eslintrc.js
!.eslintignore
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
test
18 changes: 18 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
"@typescript-eslint/no-empty-interface": "off"
},
env: {
node: true,
},
};
21 changes: 21 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
reviewers:
- "w3f/infrastructure"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-minor","version-update:semver-patch"]

- package-ecosystem: docker
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-minor","version-update:semver-patch"]
20 changes: 20 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v2
11 changes: 11 additions & 0 deletions .github/workflows/yarn_upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 'Yarn Upgrade'
on:
schedule:
- cron: '0 10 * * 1'
workflow_dispatch:

jobs:
yarn-upgrade:
uses: w3f/base-services-charts/.github/workflows/yarn_upgrade.yml@master
secrets:
PR_PAT: ${{ secrets.BOT_PAT }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules/
dist/
yarn-error.log
config/*
!config/*sample*
!config/*sample*
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:14-alpine

WORKDIR /app

COPY package.json yarn.lock ./
RUN yarn --ignore-scripts

COPY . .
RUN yarn && \
yarn build

ENTRYPOINT ["yarn", "start"]
56 changes: 54 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,58 @@

# Polkadot-K8s-Payouts

A tool to deploy an utility that automatically claims your Kusama/Polkadot validator rewards in a Kubernetes cluster.
This tool leverages on the official [polkadot-payout](https://github.com/w3f/polkadot-payouts) application from Web3 Foundation.
Tool that automatically claims your Kusama/Polkadot validator rewards.
Deployable in a Kubernetes cluster as a cronjob (helm chart).
Forked from https://github.com/ironoa/polkadot-k8s-payouts


# How it works - Local

You can start by cloning the repo and installiing the dependencies, NodeJS and Yarn are required:
```
$ git clone https://github.com/w3f/polkadot-k8s-payouts
$ cd polkadot-k8s-payouts
$ yarn
```
Then you should create a configuration file, you can start by copying a sample provided with the repo and customizing it:
```
$ cp config/main.sample.yaml config/main.yaml
```
Now you can customize `config/main.yaml`, see the following configurations about how to do it. Once you are done you
can run the tool with:
```
$ yarn start
```

# About - Keystore Password File

The password file should not contain any trailing new line charaters, therefore you could use this command to be sure to create a properly formatted password file: `echo -n "yourPassword" > yourFileName`

# About - Batch Size

The claims extrinsics are batched in utility.batch extrinsic calls. This parameter is the maximum number of calls to be packed into the batch extrinsic.

# Optional - Grace Period
This is an optional parameter you can add to configure a grace period limitation you wish to introduce: it will prevent a claim to be triggered if the validator rewards is not "old" enough eras from the current one.
For example, in Kusama this is equivalent to a grace period of 4 days:
```
# config/main.yaml
logLevel: info
wsEndpoint: "wss://kusama-rpc.polkadot.io/"
gracePeriod:
enabled: true
eras: 16
claims:
enabled: true
claimerKeystore:
filePath: /path/to/validator-000/keystore
passwordPath: /path/to/validator-000/keystore/password
targets:
- alias: validator-000
validatorAddress: "<validator-000-stash-address>"
- alias: validator-001
validatorAddress: "<validator-001-stash-address>"
```

# Optional - Deep Check
This is an optional parameter you can add to force a scan starting from the last 84 era, rather then relying on the onchain account ledger information. Keep it disabled for normal operations.
4 changes: 2 additions & 2 deletions charts/polkadot-k8s-payouts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: Polkadot K8s Payouts
name: polkadot-k8s-payouts
version: v0.1.19
appVersion: v0
version: v1.0.0
appVersion: v1
apiVersion: v2
8 changes: 4 additions & 4 deletions charts/polkadot-k8s-payouts/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ spec:
- name: config
mountPath: /app/config
- name: password
mountPath: {{ dir .Values.config.claimThirdParty.claimerKeystore.passwordPath }}
mountPath: {{ dir .Values.config.claim.claimerKeystore.passwordPath }}
- name: wallet
mountPath: {{ dir .Values.config.claimThirdParty.claimerKeystore.filePath }}
mountPath: {{ dir .Values.config.claim.claimerKeystore.filePath }}
volumes:
- name: config
configMap:
Expand All @@ -48,10 +48,10 @@ spec:
secretName: {{ .Release.Name }}-password
items:
- key: claimer_password
path: {{ base .Values.config.claimThirdParty.claimerKeystore.passwordPath }}
path: {{ base .Values.config.claim.claimerKeystore.passwordPath }}
- name: wallet
secret:
secretName: {{ .Release.Name }}-wallet
items:
- key: claimer_wallet_json
path: {{ base .Values.config.claimThirdParty.claimerKeystore.filePath }}
path: {{ base .Values.config.claim.claimerKeystore.filePath }}
23 changes: 10 additions & 13 deletions charts/polkadot-k8s-payouts/values.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
environment: production

image:
repo: web3f/accountant
repo: web3f/polkadot-payouts
# Tag is based on appVersion in chart.yaml

config:
logLevel: info
wsEndpoint: "wss://rpc.polkadot.io/"
isDeepHistoryCheckForced: false
retryPolicy:
delayMillis: 10000
maxAttempts: 5
gracePeriod:
targets:
- alias: ALESSIO
validatorAddress: "16cdSZUq7kxq6mtoVMWmYXo62FnNGT9jzWjVRUg87CpL9pxP"
deepCheck:
enabled: false
eras: 4
claimThirdParty:
parallelExecution:
claim:
enabled: false
batchSize: 9
gracePeriod:
enabled: false
degree: 4
eras: 4
claimerKeystore:
filePath: '/app/keystore/wallet/wallet.json'
passwordPath: '/app/keystore/password/password'
targets:
- alias: ALESSIO
validatorAddress: "16cdSZUq7kxq6mtoVMWmYXo62FnNGT9jzWjVRUg87CpL9pxP"

secret:
claimerPasswordValue: '}b#%q.~0QAWog'
Expand Down
18 changes: 18 additions & 0 deletions config/main.sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
logLevel: info
wsEndpoint: "wss://kusama-rpc.polkadot.io/"
targets:
- alias: validator-000
validatorAddress: "<validator-000-stash-address>"
- alias: validator-001
validatorAddress: "<validator-001-stash-address>"
deepCheck:
enabled: false
claim:
enabled: false
batchSize: 9
gracePeriod:
enabled: false
eras: 4
claimerKeystore:
filePath: /path/to/validator-000/keystore
passwordPath: /path/to/validator-000/keystore/password
8 changes: 6 additions & 2 deletions helmfile.d/config/claimer.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
environment: {{ .Environment.Name }}

{{ if eq .Environment.Name "ci" }}
image:
tag: {{ env "CIRCLE_SHA1" }}
{{ end }}

config:
logLevel: info
isDeepHistoryCheckForced: false
logLevel: info
2 changes: 1 addition & 1 deletion helmfile.d/config/kusama/claimer.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
config:
wsEndpoint: "wss://kusama-rpc.polkadot.io/"
claimThirdParty:
claim:
targets:
{{- range $index, $value := .Environment.Values.validatorsKusama }}
- alias: {{ $value.name }}
Expand Down
Loading

0 comments on commit c17821e

Please sign in to comment.