From 0491be6025e7e050cd998870f35f78b03a7abf9e Mon Sep 17 00:00:00 2001 From: Przemek Rzad Date: Fri, 22 Mar 2024 15:09:39 +0100 Subject: [PATCH] Introduce a CronJob to claim bridge relayer rewards (#335) --- charts/bridges-common-relay/Chart.yaml | 2 +- charts/bridges-common-relay/README.md | 3 +- .../templates/cronjob.yml | 87 +++++++++++++++++++ charts/bridges-common-relay/values.yaml | 16 ++++ 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 charts/bridges-common-relay/templates/cronjob.yml diff --git a/charts/bridges-common-relay/Chart.yaml b/charts/bridges-common-relay/Chart.yaml index 38072eba..502ffaee 100644 --- a/charts/bridges-common-relay/Chart.yaml +++ b/charts/bridges-common-relay/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: bridges-common-relay description: A Helm chart for bridges-common-relay type: application -version: 1.0.0 +version: 1.1.0 maintainers: - name: Parity url: https://github.com/paritytech/helm-charts diff --git a/charts/bridges-common-relay/README.md b/charts/bridges-common-relay/README.md index f1b78418..79d44216 100644 --- a/charts/bridges-common-relay/README.md +++ b/charts/bridges-common-relay/README.md @@ -18,7 +18,7 @@ This is intended behaviour. Make sure to run `git add -A` once again to stage ch # Parity Bridges Common helm chart -![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) +![Version: 1.1.0](https://img.shields.io/badge/Version-1.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) This helm chart installs [Parity Bridges Common](https://github.com/paritytech/parity-bridges-common) relayer. @@ -59,6 +59,7 @@ helm install bridges-common-relay parity/bridges-common-relay | prometheus.port | int | `9615` | The port for exposed Prometheus metrics | | replicaCount | int | `1` | | | resources | object | `{}` | Resource limits & requests | +| rewards | object | `{}` | CronJobs to automatically claim relayer rewards | | secrets | object | `{}` | Secrets will be mounted to pod /secrets/{key} | | securityContext | object | `{}` | SecurityContext holds pod-level security attributes and common container settings. | | service | object | `{"port":80,"type":"ClusterIP"}` | Service | diff --git a/charts/bridges-common-relay/templates/cronjob.yml b/charts/bridges-common-relay/templates/cronjob.yml new file mode 100644 index 00000000..305b207d --- /dev/null +++ b/charts/bridges-common-relay/templates/cronjob.yml @@ -0,0 +1,87 @@ +{{ range $val := .Values.rewards }} +{{ range $reward_owner := tuple "ThisChain" "BridgedChain" }} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: bridge-{{ $val.name | lower }}-{{ $reward_owner | lower }} + labels: + {{- include "bridges-common-relay.labels" $ | nindent 4 }} +spec: + schedule: {{ $val.schedule | quote }} + concurrencyPolicy: Forbid # Because of extrinsic nonces. + jobTemplate: + metadata: + annotations: + checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") $ | sha256sum }} + labels: + {{- include "bridges-common-relay.labels" $ | nindent 8 }} + spec: + backOffLimit: 0 + template: + metadata: + annotations: + {{- with $.Values.podAnnotations }} + {{- toYaml . | nindent 12 }} + {{- end }} + spec: + restartPolicy: Never + serviceAccountName: {{ include "bridges-common-relay.serviceAccountName" $ }} + {{- if or $.Values.secrets $.Values.existingSecretName }} + volumes: + - name: secrets + secret: + secretName: {{ include "bridges-common-relay.secretName" $ }} + optional: false + {{- end}} + containers: + - name: bridges-common-relay-{{ $val.name | lower }}-{{ $reward_owner | lower }} + image: paritytech/polkadotjs-cli:latest + imagePullPolicy: IfNotPresent + env: + - name: RPC_URL + value: {{ $val.rpc_url | quote }} + command: + - /bin/bash + - -c + - | + set -euo pipefail + + rewards_account_params=$( + jq --null-input \ + --arg lane_id {{ $val.lane_id | quote }} \ + --arg bridged_chain_id {{ $val.bridged_chain_id | quote }} \ + --arg owner {{ $reward_owner | quote }} \ + '{ + "laneId": $lane_id, + "bridgedChainId": $bridged_chain_id, + "owner": $owner + }' + ) + + reward=$( + polkadot-js-api --ws "$RPC_URL" query.bridgeRelayers.relayerRewards \ + {{ $val.address | quote }} \ + "$rewards_account_params" \ + | jq -r '.relayerRewards' + ) + if [[ "$reward" == "null" || "$reward" == "0" ]] + then + echo "No reward to claim, exiting." + exit 0 + fi + echo "{{ $val.name }} on {{ $reward_owner }} has a reward of ${reward}." + + polkadot-js-api --ws "$RPC_URL" \ + --seed "$(cat /secrets/{{ $val.seed_phrase_secret_name }})" \ + tx.bridgeRelayers.claimRewards "$rewards_account_params" + resources: + {{- toYaml $.Values.resources | nindent 16 }} + {{- if or $.Values.secrets $.Values.existingSecretName }} + volumeMounts: + - name: secrets + mountPath: "/secrets" + readOnly: true + {{- end}} +--- +{{- end }} +{{- end }} diff --git a/charts/bridges-common-relay/values.yaml b/charts/bridges-common-relay/values.yaml index 59e26fb5..82bff6d2 100644 --- a/charts/bridges-common-relay/values.yaml +++ b/charts/bridges-common-relay/values.yaml @@ -114,3 +114,19 @@ serviceMonitor: relabelings: [] # -- Metric relabelings config metricRelabelings: [] + +# -- CronJobs to automatically claim relayer rewards +rewards: {} + # - name: rococoToWestendRelayer + # # -- cron schedule + # schedule: "00 01 * * *" + # # -- Public address of the relayer + # address: "5Fxxx" + # # -- Bridge Hub RPC URL to use + # rpc_url: "wss://example.com" + # # -- Bridge line ID + # lane_id: "0x00000002" + # # -- Bridged Chain ID, for example [rococo](https://github.com/paritytech/polkadot-sdk/blob/7241a8db7b3496816503c6058dae67f66c666b00/bridges/testing/environments/rococo-westend/bridges_rococo_westend.sh#L349). + # bridged_chain_id: "0x62687764" + # # -- Secret name of the seed phrase of the relayer + # seed_phrase_secret_name: "bridge-hub-rococo-signer-file"