Skip to content

Commit be2e651

Browse files
wen-codingclaude
andcommitted
feat: add AUTOBAHN option to local docker cluster (CON-247)
- NodeKey.SaveAs writes node_pubkey.txt alongside node_key.json - FilePVKey.Save writes validator_pubkey.txt alongside priv_validator_key.json - step1 copies pubkey files to shared volume for cross-node access - step4 generates autobahn JSON config from all nodes' pubkeys when AUTOBAHN=true - Wired through docker-compose.yml and Makefile Usage: AUTOBAHN=true make docker-cluster-start Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8d7e329 commit be2e651

6 files changed

Lines changed: 71 additions & 7 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ docker-cluster-start: docker-cluster-stop build-docker-node
293293
else \
294294
DETACH_FLAG=""; \
295295
fi; \
296-
DOCKER_PLATFORM=$(DOCKER_PLATFORM) USERID=$(shell id -u) GROUPID=$(shell id -g) GOCACHE=$(shell go env GOCACHE) NUM_ACCOUNTS=10 INVARIANT_CHECK_INTERVAL=${INVARIANT_CHECK_INTERVAL} UPGRADE_VERSION_LIST=${UPGRADE_VERSION_LIST} MOCK_BALANCES=${MOCK_BALANCES} GIGA_EXECUTOR=${GIGA_EXECUTOR} GIGA_OCC=${GIGA_OCC} RECEIPT_BACKEND=${RECEIPT_BACKEND} docker compose up $$DETACH_FLAG
296+
DOCKER_PLATFORM=$(DOCKER_PLATFORM) USERID=$(shell id -u) GROUPID=$(shell id -g) GOCACHE=$(shell go env GOCACHE) NUM_ACCOUNTS=10 INVARIANT_CHECK_INTERVAL=${INVARIANT_CHECK_INTERVAL} UPGRADE_VERSION_LIST=${UPGRADE_VERSION_LIST} MOCK_BALANCES=${MOCK_BALANCES} GIGA_EXECUTOR=${GIGA_EXECUTOR} GIGA_OCC=${GIGA_OCC} RECEIPT_BACKEND=${RECEIPT_BACKEND} AUTOBAHN=${AUTOBAHN} docker compose up $$DETACH_FLAG
297297

298298
.PHONY: localnet-start
299299

docker/docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ services:
1919
- GIGA_EXECUTOR
2020
- GIGA_OCC
2121
- RECEIPT_BACKEND
22+
- AUTOBAHN
2223
volumes:
2324
- "${PROJECT_HOME}:/sei-protocol/sei-chain:Z"
2425
- "${PROJECT_HOME}/../sei-tendermint:/sei-protocol/sei-tendermint:Z"
@@ -50,6 +51,7 @@ services:
5051
- GIGA_EXECUTOR
5152
- GIGA_OCC
5253
- RECEIPT_BACKEND
54+
- AUTOBAHN
5355
volumes:
5456
- "${PROJECT_HOME}:/sei-protocol/sei-chain:Z"
5557
- "${PROJECT_HOME}/../sei-tendermint:/sei-protocol/sei-tendermint:Z"
@@ -77,6 +79,7 @@ services:
7779
- GIGA_EXECUTOR
7880
- GIGA_OCC
7981
- RECEIPT_BACKEND
82+
- AUTOBAHN
8083
ports:
8184
- "26662-26664:26656-26658"
8285
- "9094-9095:9090-9091"
@@ -108,6 +111,7 @@ services:
108111
- GIGA_EXECUTOR
109112
- GIGA_OCC
110113
- RECEIPT_BACKEND
114+
- AUTOBAHN
111115
ports:
112116
- "26665-26667:26656-26658"
113117
- "9096-9097:9090-9091"

docker/localnode/scripts/step1_configure_init.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ echo "Configure and initialize environment"
88
cp build/seid "$GOBIN"/
99

1010
# Prepare shared folders
11+
NODE_DIR="build/generated/node_${NODE_ID}"
1112
mkdir -p build/generated/gentx/
1213
mkdir -p build/generated/exported_keys/
13-
mkdir -p build/generated/node_"$NODE_ID"
14+
mkdir -p "$NODE_DIR"
1415

1516
# Testing whether seid works or not
1617
seid version # Uncomment the below line if there are any dependency issues
@@ -22,16 +23,22 @@ MONIKER="sei-node-$NODE_ID"
2223
seid init "$MONIKER" --chain-id sei >/dev/null 2>&1
2324

2425
# Copy configs
25-
APP_CONFIG_FILE="build/generated/node_$NODE_ID/app.toml"
26-
TENDERMINT_CONFIG_FILE="build/generated/node_$NODE_ID/config.toml"
26+
APP_CONFIG_FILE="$NODE_DIR/app.toml"
27+
TENDERMINT_CONFIG_FILE="$NODE_DIR/config.toml"
2728
cp docker/localnode/config/app.toml "$APP_CONFIG_FILE"
2829
cp docker/localnode/config/config.toml "$TENDERMINT_CONFIG_FILE"
2930

3031

3132
# Set up persistent peers
3233
SEI_NODE_ID=$(seid tendermint show-node-id)
3334
NODE_IP=$(hostname -i | awk '{print $1}')
34-
echo "$SEI_NODE_ID@$NODE_IP:26656" >> build/generated/persistent_peers.txt
35+
P2P_PORT=26656 # Must match [p2p] laddr in config.toml
36+
echo "$SEI_NODE_ID@$NODE_IP:$P2P_PORT" >> build/generated/persistent_peers.txt
37+
38+
# Store autobahn-compatible pubkeys and address for config generation
39+
cp ~/.sei/config/validator_pubkey.txt "$NODE_DIR/" || { echo "ERROR: failed to copy validator_pubkey.txt"; exit 1; }
40+
cp ~/.sei/config/node_pubkey.txt "$NODE_DIR/" || { echo "ERROR: failed to copy node_pubkey.txt"; exit 1; }
41+
echo "$NODE_IP:$P2P_PORT" > "$NODE_DIR/autobahn_address.txt"
3542

3643
# Create a new account
3744
ACCOUNT_NAME="node_admin"

docker/localnode/scripts/step4_config_override.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
NODE_ID=${ID:-0}
44
GIGA_EXECUTOR=${GIGA_EXECUTOR:-false}
55
GIGA_OCC=${GIGA_OCC:-false}
6+
AUTOBAHN=${AUTOBAHN:-false}
67

78
APP_CONFIG_FILE="build/generated/node_$NODE_ID/app.toml"
89
TENDERMINT_CONFIG_FILE="build/generated/node_$NODE_ID/config.toml"
@@ -59,3 +60,40 @@ if [ -n "$RECEIPT_BACKEND" ]; then
5960
echo "rs-backend = \"$RECEIPT_BACKEND\"" >> ~/.sei/config/app.toml
6061
fi
6162
fi
63+
64+
# Generate Autobahn (GigaRouter) config if requested
65+
if [ "$AUTOBAHN" = "true" ]; then
66+
echo "Generating Autobahn config for node $NODE_ID..."
67+
AUTOBAHN_CONFIG="$HOME/.sei/config/autobahn.json"
68+
69+
# Build validators JSON array from all nodes' pubkeys
70+
VALIDATORS="["
71+
for i in $(seq 0 $((CLUSTER_SIZE - 1))); do
72+
VAL_KEY=$(cat "build/generated/node_${i}/validator_pubkey.txt") || { echo "ERROR: validator_pubkey.txt not found for node $i"; exit 1; }
73+
NODE_KEY=$(cat "build/generated/node_${i}/node_pubkey.txt") || { echo "ERROR: node_pubkey.txt not found for node $i"; exit 1; }
74+
ADDR=$(cat "build/generated/node_${i}/autobahn_address.txt") || { echo "ERROR: autobahn_address.txt not found for node $i"; exit 1; }
75+
if [ -z "$VAL_KEY" ] || [ -z "$NODE_KEY" ] || [ -z "$ADDR" ]; then
76+
echo "ERROR: empty pubkey or address for node $i"; exit 1
77+
fi
78+
if [ $i -gt 0 ]; then VALIDATORS="$VALIDATORS,"; fi
79+
VALIDATORS="$VALIDATORS{\"validator_key\":\"$VAL_KEY\",\"node_key\":\"$NODE_KEY\",\"address\":\"$ADDR\"}"
80+
done
81+
VALIDATORS="$VALIDATORS]"
82+
83+
cat > "$AUTOBAHN_CONFIG" << ENDOFCONFIG
84+
{
85+
"validators": $VALIDATORS,
86+
"max_gas_per_block": 50000000,
87+
"max_txs_per_block": 5000,
88+
"mempool_size": 5000,
89+
"block_interval": "400ms",
90+
"allow_empty_blocks": false,
91+
"view_timeout": "1.5s",
92+
"dial_interval": "10s"
93+
}
94+
ENDOFCONFIG
95+
96+
# Inject autobahn config file path into config.toml
97+
sed -i 's|autobahn-config-file = ""|autobahn-config-file = "'"$AUTOBAHN_CONFIG"'"|' ~/.sei/config/config.toml
98+
echo "Autobahn config written to $AUTOBAHN_CONFIG"
99+
fi

sei-tendermint/privval/file.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ func (pvKey FilePVKey) Save() error {
102102
if err != nil {
103103
return err
104104
}
105-
return tempfile.WriteFileAtomic(outFile, data, 0600)
105+
if err := tempfile.WriteFileAtomic(outFile, data, 0600); err != nil {
106+
return err
107+
}
108+
// Write pubkey in autobahn-compatible format alongside the key file.
109+
pubKeyStr := fmt.Sprintf("validator:%s", pvKey.PubKey.String())
110+
pubKeyPath := filepath.Clean(filepath.Join(filepath.Dir(outFile), "validator_pubkey.txt"))
111+
return os.WriteFile(pubKeyPath, []byte(pubKeyStr), 0600)
106112
}
107113

108114
//-------------------------------------------------------------------------------

sei-tendermint/types/node_key.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package types
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"os"
67
"path/filepath"
78

@@ -48,12 +49,20 @@ func (nk NodeKey) PubKey() crypto.PubKey {
4849
}
4950

5051
// SaveAs persists the NodeKey to filePath.
52+
// It also writes a node_pubkey.txt file in the same directory containing the
53+
// public key in "node:ed25519:public:<hex>" format for use in autobahn config generation.
5154
func (nk NodeKey) SaveAs(filePath string) error {
5255
jsonBytes, err := nk.MarshalJSON()
5356
if err != nil {
5457
return err
5558
}
56-
return os.WriteFile(filePath, jsonBytes, 0600)
59+
if err := os.WriteFile(filePath, jsonBytes, 0600); err != nil {
60+
return err
61+
}
62+
// Write pubkey in autobahn-compatible format alongside the key file.
63+
pubKeyStr := fmt.Sprintf("node:%s", nk.PubKey().String())
64+
pubKeyPath := filepath.Clean(filepath.Join(filepath.Dir(filePath), "node_pubkey.txt"))
65+
return os.WriteFile(pubKeyPath, []byte(pubKeyStr), 0600)
5766
}
5867

5968
// LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If

0 commit comments

Comments
 (0)