Skip to content

Commit

Permalink
Add ability to set operations-pool per baker (#577)
Browse files Browse the repository at this point in the history
* Add ability to set operations-pool per baker

Operations-pool allows the baker to target a flashbake endpoint or other
external mempool provider by passing a URL. This was previously done by
passing BAKER_EXTRA_ARGS env variable, but it would be the same for
every baker in your pod. This allows setting an endpoint per baking
address.

* fix tests

* only deploy baker-config if there is a baker

* Update charts/tezos/values.yaml

Co-authored-by: Aryeh Harris <harryttd@users.noreply.github.com>

* improve values.yaml comments, per review

* do not mount the baker-config vol if it does not exist

* fix tests

* in values.yaml, make baker1 example accurate

* do not deploy baker config for non-bakers

---------

Co-authored-by: Aryeh Harris <harryttd@users.noreply.github.com>
  • Loading branch information
nicolasochem and harryttd authored Jun 2, 2023
1 parent f213d80 commit 7bf5c1c
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 79 deletions.
18 changes: 11 additions & 7 deletions charts/tezos/scripts/baker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ proto_command="{{ .command_in_tpl }}"

my_baker_account="$(sed -n "$(($BAKER_INDEX + 1))p" < /etc/tezos/baker-account )"

per_block_vote_file=/etc/tezos/per-block-votes/${my_baker_account}-${proto_command}-per-block-votes.json
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
fi

per_block_vote_file=/etc/tezos/baker-config/${my_baker_account}-${proto_command}-per-block-votes.json

if [ $(cat $per_block_vote_file) == "null" ]; then
cat << EOF
Expand All @@ -25,12 +33,8 @@ EOF
fi
extra_args="--votefile ${per_block_vote_file}"

if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
if [ -f /etc/tezos/baker-config/${my_baker_account}_operations_pool ]; then
extra_args="${extra_args} --operations-pool $(cat /etc/tezos/baker-config/${my_baker_account}_operations_pool)"
fi

CLIENT="$TEZ_BIN/octez-client -d $CLIENT_DIR"
Expand Down
4 changes: 2 additions & 2 deletions charts/tezos/templates/_containers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@
name: tezos-accounts
{{- end }}
{{- if eq .type "baker" }}
- mountPath: /etc/tezos/per-block-votes
name: per-block-votes
- mountPath: /etc/tezos/baker-config
name: baker-config
{{- end }}
{{- if (eq .type "octez-node") }}
ports:
Expand Down
8 changes: 4 additions & 4 deletions charts/tezos/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ metadata:
{{- end }}

{{/*
Has per-block votes defined?
Is there a baker?
*/}}
{{- define "tezos.hasPerBlockVotes" }}
{{- range .Values.protocols }}
{{- if .vote }}
{{- define "tezos.shouldDeployBakerConfig" }}
{{- range .Values.nodes }}
{{- if (has "baker" .runs) }}
{{- "true" }}
{{- end }}
{{- end }}
Expand Down
7 changes: 5 additions & 2 deletions charts/tezos/templates/configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,20 @@ metadata:
name: tezos-secret
namespace: {{ .Release.Namespace }}
---
{{- if (include "tezos.hasPerBlockVotes" .) }}
{{- if (include "tezos.shouldDeployBakerConfig" .) }}
apiVersion: v1
data:
{{- range $k, $v := .Values.accounts }}
{{- range ( $v.protocols | default $.Values.protocols ) }}
{{ $k }}-{{ .command }}-per-block-votes.json: {{ .vote | toJson | quote }}
{{- end }}
{{- if $v.operations_pool }}
{{ $k }}_operations_pool: {{ $v.operations_pool | quote }}
{{- end }}
{{- end }}
kind: ConfigMap
metadata:
name: per-block-votes
name: baker-config
namespace: {{ .Release.Namespace }}
---
{{- end }}
6 changes: 3 additions & 3 deletions charts/tezos/templates/nodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ spec:
- name: tezos-accounts
secret:
secretName: tezos-secret
{{- if (include "tezos.hasPerBlockVotes" $) }}
- name: per-block-votes
{{- if has "baker" $.node_vals.runs }}
- name: baker-config
configMap:
name: per-block-votes
name: baker-config
{{- end }}
{{- if $.node_vals.local_storage | default false }}
- emptyDir: {}
Expand Down
19 changes: 11 additions & 8 deletions charts/tezos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ accounts: {}
#
# `accounts` is a map where keys are account aliases and values are maps of
# fields `key`, `is_bootstrap_baker_account`, `bootstrap_balance`, `signer_url`
# and `protocols`.
# `protocols` and `operations_pool`.
#
# The `key` field can be set to a public or private key. For a bootstrap baker,
# it must be set to a private key. The key type will be recognized automatically,
# and the pod will fail if the key type is unexpected.
#
# The `protocols` fields overrides the top-level `protocols` field described
# below and has the same syntax. This allows to set specific per-block votes per
# baker.
#
# The `operations_pool` field instructs the baker to target a url for external
# mempool queries when baking a block. This is useful to run a Flashbake-capable baker.
# The entry is passed to baker binaries using the `--operations-pool` flag.
#
# - Public chains: Accounts do not get `is_bootstrap_baker_account` and
# `bootstrap_balance` fields.
# - Non-public chains: If you don't specify accounts needed by nodes, they can
Expand All @@ -55,10 +63,6 @@ accounts: {}
# node but they will not be bootstrap accounts. If you don't set a bootstrap
# balance, it will default to the `bootstrap_mutez` field above.
#
# The `protocols` fields overrides the top-level `protocols` field described
# below and has the same syntax. This allows to set specific per-block votes per
# baker.
#
# Example:
#
# ```
Expand All @@ -69,9 +73,8 @@ accounts: {}
# bootstrap_balance: "50000000000000"
#
# baker1:
# key: edpk...
# is_bootstrap_baker_account: false
# bootstrap_balance: "4000000000000"
# key: edsk...
# operations_pool: http://flashbake-endpoint-baker-listener:12732
# protocols:
# - command: PtMumbai
# vote:
Expand Down
123 changes: 70 additions & 53 deletions test/charts/private-chain.expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ data:
tacoinfraSigner-013-PtJakart-per-block-votes.json: "{\"liquidity_baking_toggle_vote\":\"pass\"}"
kind: ConfigMap
metadata:
name: per-block-votes
name: baker-config
namespace: testing
---
# Source: tezos-chain/templates/tacoinfra-remote-signer/main.yaml
Expand Down Expand Up @@ -690,9 +690,6 @@ spec:
- name: tezos-accounts
secret:
secretName: tezos-secret
- name: per-block-votes
configMap:
name: per-block-votes
volumeClaimTemplates:
- metadata:
name: var-volume
Expand Down Expand Up @@ -799,7 +796,15 @@ spec:
my_baker_account="$(sed -n "$(($BAKER_INDEX + 1))p" < /etc/tezos/baker-account )"
per_block_vote_file=/etc/tezos/per-block-votes/${my_baker_account}-${proto_command}-per-block-votes.json
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
fi
per_block_vote_file=/etc/tezos/baker-config/${my_baker_account}-${proto_command}-per-block-votes.json
if [ $(cat $per_block_vote_file) == "null" ]; then
cat << EOF
Expand All @@ -813,12 +818,8 @@ spec:
fi
extra_args="--votefile ${per_block_vote_file}"
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
if [ -f /etc/tezos/baker-config/${my_baker_account}_operations_pool ]; then
extra_args="${extra_args} --operations-pool $(cat /etc/tezos/baker-config/${my_baker_account}_operations_pool)"
fi
CLIENT="$TEZ_BIN/octez-client -d $CLIENT_DIR"
Expand All @@ -844,8 +845,8 @@ spec:
name: config-volume
- mountPath: /var/tezos
name: var-volume
- mountPath: /etc/tezos/per-block-votes
name: per-block-votes
- mountPath: /etc/tezos/baker-config
name: baker-config
- name: baker-1-013-ptjakart
image: "tezos/tezos:v15-release"
imagePullPolicy: IfNotPresent
Expand All @@ -867,7 +868,15 @@ spec:
my_baker_account="$(sed -n "$(($BAKER_INDEX + 1))p" < /etc/tezos/baker-account )"
per_block_vote_file=/etc/tezos/per-block-votes/${my_baker_account}-${proto_command}-per-block-votes.json
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
fi
per_block_vote_file=/etc/tezos/baker-config/${my_baker_account}-${proto_command}-per-block-votes.json
if [ $(cat $per_block_vote_file) == "null" ]; then
cat << EOF
Expand All @@ -881,12 +890,8 @@ spec:
fi
extra_args="--votefile ${per_block_vote_file}"
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
if [ -f /etc/tezos/baker-config/${my_baker_account}_operations_pool ]; then
extra_args="${extra_args} --operations-pool $(cat /etc/tezos/baker-config/${my_baker_account}_operations_pool)"
fi
CLIENT="$TEZ_BIN/octez-client -d $CLIENT_DIR"
Expand All @@ -912,8 +917,8 @@ spec:
name: config-volume
- mountPath: /var/tezos
name: var-volume
- mountPath: /etc/tezos/per-block-votes
name: per-block-votes
- mountPath: /etc/tezos/baker-config
name: baker-config
- name: baker-2-013-ptjakart
image: "tezos/tezos:v15-release"
imagePullPolicy: IfNotPresent
Expand All @@ -935,7 +940,15 @@ spec:
my_baker_account="$(sed -n "$(($BAKER_INDEX + 1))p" < /etc/tezos/baker-account )"
per_block_vote_file=/etc/tezos/per-block-votes/${my_baker_account}-${proto_command}-per-block-votes.json
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
fi
per_block_vote_file=/etc/tezos/baker-config/${my_baker_account}-${proto_command}-per-block-votes.json
if [ $(cat $per_block_vote_file) == "null" ]; then
cat << EOF
Expand All @@ -949,12 +962,8 @@ spec:
fi
extra_args="--votefile ${per_block_vote_file}"
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
if [ -f /etc/tezos/baker-config/${my_baker_account}_operations_pool ]; then
extra_args="${extra_args} --operations-pool $(cat /etc/tezos/baker-config/${my_baker_account}_operations_pool)"
fi
CLIENT="$TEZ_BIN/octez-client -d $CLIENT_DIR"
Expand All @@ -980,8 +989,8 @@ spec:
name: config-volume
- mountPath: /var/tezos
name: var-volume
- mountPath: /etc/tezos/per-block-votes
name: per-block-votes
- mountPath: /etc/tezos/baker-config
name: baker-config
- name: baker-3-013-ptjakart
image: "tezos/tezos:v15-release"
imagePullPolicy: IfNotPresent
Expand All @@ -1003,7 +1012,15 @@ spec:
my_baker_account="$(sed -n "$(($BAKER_INDEX + 1))p" < /etc/tezos/baker-account )"
per_block_vote_file=/etc/tezos/per-block-votes/${my_baker_account}-${proto_command}-per-block-votes.json
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
fi
per_block_vote_file=/etc/tezos/baker-config/${my_baker_account}-${proto_command}-per-block-votes.json
if [ $(cat $per_block_vote_file) == "null" ]; then
cat << EOF
Expand All @@ -1017,12 +1034,8 @@ spec:
fi
extra_args="--votefile ${per_block_vote_file}"
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
if [ -f /etc/tezos/baker-config/${my_baker_account}_operations_pool ]; then
extra_args="${extra_args} --operations-pool $(cat /etc/tezos/baker-config/${my_baker_account}_operations_pool)"
fi
CLIENT="$TEZ_BIN/octez-client -d $CLIENT_DIR"
Expand All @@ -1048,8 +1061,8 @@ spec:
name: config-volume
- mountPath: /var/tezos
name: var-volume
- mountPath: /etc/tezos/per-block-votes
name: per-block-votes
- mountPath: /etc/tezos/baker-config
name: baker-config
- name: baker-4-013-ptjakart
image: "tezos/tezos:v15-release"
imagePullPolicy: IfNotPresent
Expand All @@ -1071,7 +1084,15 @@ spec:
my_baker_account="$(sed -n "$(($BAKER_INDEX + 1))p" < /etc/tezos/baker-account )"
per_block_vote_file=/etc/tezos/per-block-votes/${my_baker_account}-${proto_command}-per-block-votes.json
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
fi
per_block_vote_file=/etc/tezos/baker-config/${my_baker_account}-${proto_command}-per-block-votes.json
if [ $(cat $per_block_vote_file) == "null" ]; then
cat << EOF
Expand All @@ -1085,12 +1106,8 @@ spec:
fi
extra_args="--votefile ${per_block_vote_file}"
if [ "${my_baker_account}" == "" ]; then
while true; do
printf "This container is not baking, but exists "
printf "due to uneven numer of bakers within the statefulset\n"
sleep 300
done
if [ -f /etc/tezos/baker-config/${my_baker_account}_operations_pool ]; then
extra_args="${extra_args} --operations-pool $(cat /etc/tezos/baker-config/${my_baker_account}_operations_pool)"
fi
CLIENT="$TEZ_BIN/octez-client -d $CLIENT_DIR"
Expand All @@ -1116,8 +1133,8 @@ spec:
name: config-volume
- mountPath: /var/tezos
name: var-volume
- mountPath: /etc/tezos/per-block-votes
name: per-block-votes
- mountPath: /etc/tezos/baker-config
name: baker-config
- name: logger
image: "ghcr.io/oxheadalpha/tezos-k8s-utils:master"
imagePullPolicy: IfNotPresent
Expand Down Expand Up @@ -1263,9 +1280,9 @@ spec:
- name: tezos-accounts
secret:
secretName: tezos-secret
- name: per-block-votes
- name: baker-config
configMap:
name: per-block-votes
name: baker-config
volumeClaimTemplates:
- metadata:
name: var-volume
Expand Down Expand Up @@ -1467,9 +1484,9 @@ spec:
- name: tezos-accounts
secret:
secretName: tezos-secret
- name: per-block-votes
- name: baker-config
configMap:
name: per-block-votes
name: baker-config
volumeClaimTemplates:
- metadata:
name: var-volume
Expand Down

0 comments on commit 7bf5c1c

Please sign in to comment.