Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion infrastructure/charts/mev-commit-erigon/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ description: A Helm chart for deploying MEV Commit chain with Erigon blockchain
type: application
version: 0.1.0
appVersion: "v3.0.7"

47 changes: 47 additions & 0 deletions infrastructure/charts/mev-commit-erigon/scripts/create-genesis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

set -e

echo "Creating genesis.json with generated accounts..."

# Check if accounts were generated
ACCOUNTS_FILE="/shared/generated_accounts.txt"
if [ ! -f "$ACCOUNTS_FILE" ]; then
echo "Error: No generated accounts found at $ACCOUNTS_FILE"
exit 1
fi

# Read the genesis template
GENESIS_TEMPLATE="/genesis-template/genesis-template.json"
if [ ! -f "$GENESIS_TEMPLATE" ]; then
echo "Error: Genesis template not found at $GENESIS_TEMPLATE"
exit 1
fi

# Copy template to working location
cp "$GENESIS_TEMPLATE" /shared/genesis.json

echo "Adding generated accounts to genesis..."

# Install jq for JSON manipulation
apk add --no-cache jq

# Read accounts and add them to genesis
while IFS= read -r address; do
if [ -n "$address" ]; then
echo "Adding account $address with balance $ACCOUNT_BALANCE"

# Add account to alloc section
jq --arg addr "$address" --arg balance "$ACCOUNT_BALANCE" \
'.alloc[$addr] = {"balance": $balance}' \
/shared/genesis.json > /shared/genesis_temp.json && \
mv /shared/genesis_temp.json /shared/genesis.json
fi
done < "$ACCOUNTS_FILE"

echo "Genesis file created successfully!"
echo "Genesis file location: /shared/genesis.json"

# Show the final genesis file (optional, for debugging)
echo "Final genesis.json alloc section:"
cat /shared/genesis.json | jq '.alloc'
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

set -e

echo "Checking for existing genesis file..."

# Check if genesis file already exists
if [ -f "/shared/genesis.json" ]; then
echo "Genesis file already exists at /shared/genesis.json"

# Validate existing file
apk add --no-cache jq
if jq . /shared/genesis.json > /dev/null 2>&1; then
echo "Existing genesis file is valid JSON. Skipping download."
exit 0
else
echo "Warning: Existing genesis file is invalid JSON. Re-downloading..."
rm -f /shared/genesis.json
fi
fi

echo "Downloading genesis from URL..."

# Check if genesis URL is provided
if [ -z "$GENESIS_URL" ]; then
echo "Error: GENESIS_URL environment variable not set"
exit 1
fi

echo "Downloading genesis from: $GENESIS_URL"

# Install curl and jq
apk add --no-cache curl jq

# Download genesis file
curl -L -o /shared/genesis.json "$GENESIS_URL"

if [ ! -f "/shared/genesis.json" ]; then
echo "Error: Failed to download genesis file"
exit 1
fi

echo "Genesis file downloaded successfully!"
echo "Genesis file location: /shared/genesis.json"

# Validate JSON format
if ! jq . /shared/genesis.json > /dev/null 2>&1; then
echo "Error: Downloaded file is not valid JSON"
exit 1
fi

echo "Genesis file validation passed!"
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

set -e

echo "Starting account generation..."

# Create keystore directory if it doesn't exist
mkdir -p /keystore

# Create accounts file to store generated addresses
ACCOUNTS_FILE="/shared/generated_accounts.txt"
> "$ACCOUNTS_FILE" # Clear the file

echo "Generating $ACCOUNT_COUNT accounts..."

for i in $(seq 1 $ACCOUNT_COUNT); do
echo "Generating account $i of $ACCOUNT_COUNT..."

# Generate account using geth
ACCOUNT_OUTPUT=$(geth account new \
--keystore /keystore \
--password /password/password.txt 2>&1)

# Extract address from output
# Geth outputs: "Your new account is locked with a password. Please give a password. Do not forget this password.
# Your new key was generated
# Public address of the key: 0x..."
ADDRESS=$(echo "$ACCOUNT_OUTPUT" | grep -i "Public address of the key:" | awk '{print $NF}' | tr -d '\n\r')

if [ -z "$ADDRESS" ]; then
# Fallback: try to extract from different output format
ADDRESS=$(echo "$ACCOUNT_OUTPUT" | grep -o "0x[a-fA-F0-9]\{40\}" | head -1)
fi

if [ -z "$ADDRESS" ]; then
echo "Error: Could not extract address from geth output"
echo "Geth output was: $ACCOUNT_OUTPUT"
exit 1
fi

echo "Generated account: $ADDRESS"
echo "$ADDRESS" >> "$ACCOUNTS_FILE"
done

echo "Generated $ACCOUNT_COUNT accounts successfully!"
echo "Accounts stored in: $ACCOUNTS_FILE"

# List generated keystore files
echo "Keystore files:"
ls -la /keystore/

# Show generated accounts
echo "Generated account addresses:"
cat "$ACCOUNTS_FILE"
41 changes: 41 additions & 0 deletions infrastructure/charts/mev-commit-erigon/scripts/init-erigon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

set -e

echo "Initializing Erigon..."

# Check if genesis file exists
if [ ! -f "/shared/genesis.json" ]; then
echo "Error: Genesis file not found at /shared/genesis.json"
exit 1
fi

echo "Found genesis file at /shared/genesis.json"

# Check if Erigon data directory already exists and is initialized
if [ -d "${ERIGON_DATADIR}/chaindata" ]; then
echo "Erigon chaindata already exists at ${ERIGON_DATADIR}/chaindata"
echo "Skipping initialization to preserve existing data"
exit 0
fi

echo "Initializing Erigon with genesis file..."

# Create data directory if it doesn't exist
mkdir -p "${ERIGON_DATADIR}"

# Initialize Erigon with genesis
erigon init \
--datadir="${ERIGON_DATADIR}" \
/shared/genesis.json

if [ $? -eq 0 ]; then
echo "Erigon initialization completed successfully!"
else
echo "Error: Erigon initialization failed"
exit 1
fi

# List contents to verify
echo "Erigon data directory contents:"
ls -la "${ERIGON_DATADIR}/"
49 changes: 49 additions & 0 deletions infrastructure/charts/mev-commit-erigon/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,52 @@ Selector labels
app.kubernetes.io/name: {{ include "erigon-snode.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Validate genesis configuration - ensure mutual exclusivity
*/}}
{{- define "erigon-snode.validateGenesis" -}}
{{- $accountGenEnabled := .Values.genesis.accountGeneration.enabled | default false }}
{{- $genesisUrlSet := .Values.genesis.url | default "" }}
{{- if and $accountGenEnabled (ne $genesisUrlSet "") }}
{{- fail "ERROR: Cannot use both genesis.accountGeneration.enabled=true AND genesis.url. Choose one method only." }}
{{- end }}
{{- if and (not $accountGenEnabled) (eq $genesisUrlSet "") }}
{{- fail "ERROR: Must configure either genesis.accountGeneration.enabled=true OR set genesis.url. One genesis method is required." }}
{{- end }}
{{- end }}

{{/*
Validate account generation configuration
*/}}
{{- define "erigon-snode.validateAccountGeneration" -}}
{{- if .Values.genesis.accountGeneration.enabled }}
{{- if not .Values.genesis.accountGeneration.count }}
{{- fail "ERROR: genesis.accountGeneration.count is required when account generation is enabled" }}
{{- end }}
{{- if lt (.Values.genesis.accountGeneration.count | int) 1 }}
{{- fail "ERROR: genesis.accountGeneration.count must be at least 1" }}
{{- end }}
{{- if not .Values.genesis.accountGeneration.password }}
{{- fail "ERROR: genesis.accountGeneration.password is required when account generation is enabled" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Validate JWT configuration
*/}}
{{- define "erigon-snode.validateJWT" -}}
{{- if not .Values.jwt.token }}
{{- fail "ERROR: jwt.token is required" }}
{{- end }}
{{- end }}

{{/*
Run all validations
*/}}
{{- define "erigon-snode.validate" -}}
{{- include "erigon-snode.validateGenesis" . }}
{{- include "erigon-snode.validateAccountGeneration" . }}
{{- include "erigon-snode.validateJWT" . }}
{{- end }}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "erigon-snode.fullname" . }}-scripts
labels:
{{- include "erigon-snode.labels" . | nindent 4 }}
data:
{{- if .Values.genesis.accountGeneration.enabled }}
generate-account.sh: |-
{{- .Files.Get "scripts/generate-account.sh" | nindent 4 }}
create-genesis.sh: |-
{{- .Files.Get "scripts/create-genesis.sh" | nindent 4 }}
{{- else }}
download-genesis.sh: |-
{{- .Files.Get "scripts/download-genesis.sh" | nindent 4 }}
{{- end }}
init-erigon.sh: |-
{{- .Files.Get "scripts/init-erigon.sh" | nindent 4 }}
43 changes: 0 additions & 43 deletions infrastructure/charts/mev-commit-erigon/templates/configmap.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if .Values.genesis.accountGeneration.enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "erigon-snode.fullname" . }}-password
labels:
{{- include "erigon-snode.labels" . | nindent 4 }}
type: Opaque
data:
password.txt: {{ .Values.genesis.accountGeneration.password | b64enc }}
{{- end }}
Loading
Loading