Skip to content

Commit

Permalink
Introduce a CronJob to claim bridge relayer rewards (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzadp authored Mar 22, 2024
1 parent bd1ade8 commit 0491be6
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/bridges-common-relay/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion charts/bridges-common-relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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 |
Expand Down
87 changes: 87 additions & 0 deletions charts/bridges-common-relay/templates/cronjob.yml
Original file line number Diff line number Diff line change
@@ -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 }}
16 changes: 16 additions & 0 deletions charts/bridges-common-relay/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 0491be6

Please sign in to comment.