Skip to content

Commit

Permalink
Merge branch 'bake_remotely' into midlbaker
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasochem committed Dec 16, 2023
2 parents dbb58de + caf1c5b commit 2b63a9b
Show file tree
Hide file tree
Showing 15 changed files with 584 additions and 167 deletions.
4 changes: 2 additions & 2 deletions charts/tezos/scripts/baker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ 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

if [ -f /etc/tezos/baker-config/${my_baker_account}_dal_node ]; then
extra_args="${extra_args} --dal-node $(cat /etc/tezos/baker-config/${my_baker_account}_dal_node)"
if [ -f /etc/tezos/baker-config/${my_baker_account}_dal_node_rpc_url ]; then
extra_args="${extra_args} --dal-node $(cat /etc/tezos/baker-config/${my_baker_account}_dal_node_rpc_url)"
fi

CLIENT="$TEZ_BIN/octez-client -d $CLIENT_DIR"
Expand Down
8 changes: 5 additions & 3 deletions charts/tezos/scripts/dal-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ extra_args=""
if [ "${BOOTSTRAP_PROFILE}" == "true" ]; then
extra_args="--bootstrap-profile"
fi
if [ "${ATTESTER_PROFILES}" != "" ]; then
extra_args="${extra_args} --attester-profiles ${ATTESTER_PROFILES}"
if [ -s "${TEZ_VAR}/dal_attester_config" ]; then
attester_config=$(cat "/var/tezos/dal_attester_config")
extra_args="${extra_args} --attester-profiles ${attester_config}"
fi
if [ "${PEER}" != "" ]; then
extra_args="${extra_args} --peer ${PEER}"
Expand All @@ -28,7 +29,8 @@ fi
#

CMD="$TEZ_BIN/octez-dal-node run ${extra_args} --data-dir ${DAL_DATA_DIR} \
--endpoint http://tezos-node-rpc:8732 \
--expected-pow 0 \
--endpoint ${NODE_RPC_URL} \
--net-addr 0.0.0.0:11732 \
--rpc-addr 0.0.0.0:10732"

Expand Down
33 changes: 33 additions & 0 deletions charts/tezos/scripts/rpc-baker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set -ex

TEZ_VAR=/var/tezos
TEZ_BIN=/usr/local/bin
CLIENT_DIR="$TEZ_VAR/client"
NODE_DIR="$TEZ_VAR/node"
BAKER_EXTRA_ARGS_FROM_ENV=${BAKER_EXTRA_ARGS}
mkdir -p $CLIENT_DIR

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

if [ ! -f "$per_block_vote_file" ]; then
echo "Error: $per_block_vote_file not found" >&2
exit 1
fi

extra_args="--votefile ${per_block_vote_file}"

if [ "${OPERATIONS_POOL}" != "" ]; then
extra_args="${extra_args} --operations-pool ${OPERATIONS_POOL}"
fi

if [ "${DAL_NODE_RPC_URL}" != "" ]; then
extra_args="${extra_args} --dal-node ${DAL_NODE_RPC_URL}"
fi

CLIENT="$TEZ_BIN/octez-client -d $CLIENT_DIR"
CMD="$TEZ_BIN/octez-baker-${PROTO_COMMAND} -d $CLIENT_DIR"

# ensure we can run octez-client commands without specifying client dir
ln -s /var/tezos/client /home/tezos/.tezos-client

exec $CMD --endpoint ${NODE_RPC_URL} run remotely ${extra_args} ${BAKER_EXTRA_ARGS_FROM_ENV} ${BAKE_USING_ACCOUNTS}
32 changes: 21 additions & 11 deletions charts/tezos/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,44 @@ metadata:
{{- end }}
{{- end }}

{{/*
Is there a baker?
{{/*
Is there a baker in nodes or is the bakers object not empty?
*/}}
{{- define "tezos.shouldDeployBakerConfig" }}
{{- $hasBakerInNodes := false }}
{{- range .Values.nodes }}
{{- if (has "baker" .runs) }}
{{- "true" }}
{{- $hasBakerInNodes = true }}
{{- end }}
{{- end }}
{{- $hasBakersObject := ne (len .Values.bakers) 0 }}
{{- if or $hasBakerInNodes $hasBakersObject }}
{{- "true" }}
{{- else }}
{{- "false" }}
{{- end }}
{{- end }}

{{/*
Get list of accounts that are being used to bake. Returned as a json
serialized dict because of how Helm renders everything returned from
a template as string. Function callers need to parse the returned
value like so: `fromJson | values | first`. A dict and not list is
returned because of the way `fromJson` works which expects a type of
map[string]interface {}.
{{/*
Get list of accounts that are being used to bake, including bake_using_accounts lists from bakers
object if it is non-empty. Returned as a json serialized dict.
*/}}
{{- define "tezos.getAccountsBaking" }}
{{- $allAccounts := list }}
{{- range $node := .Values.nodes }}
{{- range $instance := $node.instances }}
{{- if and .bake_using_accounts (kindIs "slice" .bake_using_accounts) }}
{{- if and .bake_using_accounts (kindIs "slice" .bake_using_accounts) }}
{{- $allAccounts = concat $allAccounts .bake_using_accounts }}
{{- end }}
{{- end }}
{{- end }}
{{- if ne (len .Values.bakers) 0 }}
{{- range $baker := .Values.bakers }}
{{- if and $baker.bake_using_accounts (kindIs "slice" $baker.bake_using_accounts) }}
{{- $allAccounts = concat $allAccounts $baker.bake_using_accounts }}
{{- end }}
{{- end }}
{{- end }}
{{- dict "data" (uniq $allAccounts) | toJson }}
{{- end }}

Expand Down
6 changes: 4 additions & 2 deletions charts/tezos/templates/configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ data:
{{ $tacoinfraSigners | default dict | mustToPrettyJson | indent 4 }}
OCTEZ_ROLLUP_NODES: |
{{ $.Values.smartRollupNodes | default dict | mustToPrettyJson | indent 4 }}
OCTEZ_BAKERS: |
{{ $.Values.bakers | default dict | mustToPrettyJson | indent 4 }}

---

Expand Down Expand Up @@ -94,8 +96,8 @@ data:
{{- if $account.operations_pool }}
{{ $accountName }}_operations_pool: {{ $account.operations_pool | quote }}
{{- end }}
{{- if $account.dal_node }}
{{ $accountName }}_dal_node: {{ $account.dal_node | quote }}
{{- if $account.dal_node_rpc_url }}
{{ $accountName }}_dal_node_rpc_url: {{ $account.dal_node_rpc_url | quote }}
{{- end }}
{{- end }}
kind: ConfigMap
Expand Down
93 changes: 93 additions & 0 deletions charts/tezos/templates/octez-baker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{{- range $k, $v := .Values.bakers }}

apiVersion: apps/v1
kind: StatefulSet
metadata:
name: baker-{{ $k }}
spec:
podManagementPolicy: Parallel
replicas: 1
serviceName: baker-{{ $k }}
selector:
matchLabels:
app: baker-{{ $k }}
template:
metadata:
labels:
app: baker-{{ $k }}
spec:
initContainers:
- image: {{ $.Values.tezos_k8s_images.utils }}
imagePullPolicy: Always
name: config-generator
args:
- config-generator
envFrom:
- configMapRef:
name: tezos-config
env:
- name: MY_POD_NAME
value: {{ $k }}
- name: MY_POD_TYPE
value: baker
volumeMounts:
- mountPath: /var/tezos
name: baker-volume
- mountPath: /etc/secret-volume
name: tezos-accounts
containers:
{{- $baker_name := index $v.bake_using_accounts 0 }}
{{- $account := get $.Values.accounts $baker_name | default dict }}
{{- range ( $account.protocols | default $.Values.protocols ) }}
- name: octez-baker-{{ lower .command }}
image: "{{ $.Values.images.octez }}"
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /var/tezos
name: baker-volume
- mountPath: /etc/tezos/baker-config
name: baker-config
command:
- /bin/sh
args:
- "-c"
- |
{{ tpl ($.Files.Get "scripts/rpc-baker.sh") $ | indent 12 }}
env:
- name: NODE_RPC_URL
value: "{{ $v.node_rpc_url }}"
- name: PROTO_COMMAND
value: "{{ .command }}"
- name: BAKER_NAME
value: {{ $baker_name }}
- name: BAKE_USING_ACCOUNTS
value: {{ join " " $v.bake_using_accounts }}
{{- if $v.operations_pool | default false }}
- name: OPERATIONS_POOL
value: "{{ $v.oprations_pool }}"
{{- end }}
{{- if $v.dal_node_rpc_url | default false }}
- name: DAL_NODE_RPC_URL
value: "{{ $v.dal_node_rpc_url }}"
{{- end }}
{{- end }}
securityContext:
fsGroup: 1000
volumes:
- name: baker-config
configMap:
name: baker-config
- name: tezos-accounts
secret:
secretName: tezos-secret
volumeClaimTemplates:
- metadata:
name: baker-volume
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "1Gi"
---
{{- end }}
62 changes: 53 additions & 9 deletions charts/tezos/templates/octez-dal-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
apiVersion: v1
kind: Service
metadata:
name: dal-{{ $k }}
name: {{ $k }}
namespace: {{ $.Release.Namespace }}
labels:
appType: octez-dal-node
spec:
type: NodePort
ports:
Expand All @@ -18,12 +20,12 @@ spec:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: dal-{{ $k }}
name: {{ $k }}
namespace: {{ $.Release.Namespace }}
spec:
podManagementPolicy: Parallel
replicas: 1
serviceName: dal-{{ $k }}
serviceName: {{ $k }}
selector:
matchLabels:
app: dal-{{ $k }}
Expand All @@ -32,6 +34,29 @@ spec:
labels:
app: dal-{{ $k }}
spec:
initContainers:
- image: {{ $.Values.tezos_k8s_images.utils }}
imagePullPolicy: Always
name: config-generator
args:
- config-generator
envFrom:
- configMapRef:
name: tezos-config
env:
- name: MY_POD_NAME
value: {{ $k }}
- name: MY_POD_TYPE
value: dal
{{- if $v.attest_using_accounts | default false }}
- name: ATTEST_USING_ACCOUNTS
value: {{ toJson $v.attest_using_accounts | quote }}
{{- end }}
volumeMounts:
- mountPath: /var/tezos
name: var-volume
- mountPath: /etc/secret-volume
name: tezos-accounts
containers:
- name: octez-dal-node
image: "{{ $.Values.images.octez }}"
Expand All @@ -52,14 +77,12 @@ spec:
{{ tpl ($.Files.Get "scripts/dal-node.sh") $ | indent 12 }}
{{- if $v | default false }}
env:
- name: NODE_RPC_URL
value: "{{ $v.node_rpc_url }}"
{{- if $v.bootstrapProfile | default false }}
- name: BOOTSTRAP_PROFILE
value: "true"
{{- end }}
{{- if $v.attesterProfiles | default false }}
- name: ATTESTER_PROFILES
value: "{{ $v.attesterProfiles }}"
{{- end }}
{{- if $v.peer | default false }}
- name: PEER
value: "{{ $v.peer }}"
Expand All @@ -75,6 +98,10 @@ spec:
{{- end }}
securityContext:
fsGroup: 1000
volumes:
- name: tezos-accounts
secret:
secretName: tezos-secret
volumeClaimTemplates:
- metadata:
name: var-volume
Expand All @@ -95,7 +122,7 @@ spec:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: dal-{{ $k }}
name: {{ $k }}
namespace: {{ $.Release.Namespace }}
{{- with $v.ingress.labels }}
labels:
Expand Down Expand Up @@ -125,11 +152,28 @@ spec:
path: /
backend:
service:
name: dal-{{ $k }}
name: {{ $k }}
port:
name: rpc
---
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
{{- toYaml .Values.serviceMonitor.labels | nindent 4 }}
name: tezos-service-monitor
namespace: {{ .Release.Namespace }}
spec:
endpoints:
- interval: 15s
port: metrics
path: /metrics
selector:
matchLabels:
appType: octez-dal-node
{{- end }}
Loading

0 comments on commit 2b63a9b

Please sign in to comment.