-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathparse-vc.sh
More file actions
142 lines (120 loc) · 5.66 KB
/
parse-vc.sh
File metadata and controls
142 lines (120 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# parse validator-config to load values related to the $item
# needed for ream and qlean (or any other client), zeam picks directly from validator-config
# 1. load quic port and export it in $quicPort
# 2. private key and dump it into a file $client.key and export it in $privKeyPath
# 3. devnet and export it in $devnet
# $item, $configDir (genesis dir) is available here
# Check if yq is installed
if ! command -v yq &> /dev/null; then
echo "Error: yq is required but not installed. Please install yq first."
echo "On macOS: brew install yq"
echo "On Linux: https://github.com/mikefarah/yq#install"
exit 1
fi
# Validate that validator config file exists
validator_config_file="$configDir/validator-config.yaml"
if [ ! -f "$validator_config_file" ]; then
echo "Error: Validator config file not found at $validator_config_file"
exit 1
fi
# Automatically extract QUIC port using yq
quicPort=$(yq eval ".validators[] | select(.name == \"$item\") | .enrFields.quic" "$validator_config_file")
# Validate that we found a QUIC port for this node
if [ -z "$quicPort" ] || [ "$quicPort" == "null" ]; then
echo "Error: No QUIC port found for node '$item' in $validator_config_file"
echo "Available nodes:"
yq eval '.validators[].name' "$validator_config_file"
exit 1
fi
# Automatically extract metrics port using yq
metricsPort=$(yq eval ".validators[] | select(.name == \"$item\") | .metricsPort" "$validator_config_file")
# Validate that we found a metrics port for this node
if [ -z "$metricsPort" ] || [ "$metricsPort" == "null" ]; then
echo "Error: No metrics port found for node '$item' in $validator_config_file"
echo "Available nodes:"
yq eval '.validators[].name' "$validator_config_file"
exit 1
fi
# Automatically extract HTTP port using yq (optional - only some clients use it)
httpPort=$(yq eval ".validators[] | select(.name == \"$item\") | .httpPort" "$validator_config_file")
if [ -z "$httpPort" ] || [ "$httpPort" == "null" ]; then
httpPort=""
fi
# Automatically extract API port using yq (optional - only some clients use it)
apiPort=$(yq eval ".validators[] | select(.name == \"$item\") | .apiPort" "$validator_config_file")
if [ -z "$apiPort" ] || [ "$apiPort" == "null" ]; then
apiPort=""
fi
# Automatically extract devnet using yq (optional - only ream uses it)
devnet=$(yq eval ".validators[] | select(.name == \"$item\") | .devnet" "$validator_config_file")
if [ -z "$devnet" ] || [ "$devnet" == "null" ]; then
devnet=""
fi
# Automatically extract isAggregator flag using yq (defaults to false if not set)
isAggregator=$(yq eval ".validators[] | select(.name == \"$item\") | .isAggregator // false" "$validator_config_file")
if [ -z "$isAggregator" ] || [ "$isAggregator" == "null" ]; then
isAggregator="false"
fi
# Extract attestation_committee_count from config section (optional - only if explicitly set)
attestationCommitteeCount=$(yq eval ".config.attestation_committee_count" "$validator_config_file")
if [ -z "$attestationCommitteeCount" ] || [ "$attestationCommitteeCount" == "null" ]; then
attestationCommitteeCount=""
fi
# Automatically extract private key using yq
privKey=$(yq eval ".validators[] | select(.name == \"$item\") | .privkey" "$validator_config_file")
# Validate that we found a private key for this node
if [ -z "$privKey" ] || [ "$privKey" == "null" ]; then
echo "Error: No private key found for node '$item' in $validator_config_file"
exit 1
fi
# Create the private key file
privKeyPath="$item.key"
echo "$privKey" > "$configDir/$privKeyPath"
# Extract hash-sig key configuration from top-level config
keyType=$(yq eval ".config.keyType" "$validator_config_file")
hashSigKeyIndex=$(yq eval ".validators | to_entries | .[] | select(.value.name == \"$item\") | .key" "$validator_config_file")
# Load hash-sig keys if configured
if [ "$keyType" == "hash-sig" ] && [ "$hashSigKeyIndex" != "null" ] && [ -n "$hashSigKeyIndex" ]; then
# Set hash-sig key paths
hashSigPkPath="$configDir/hash-sig-keys/validator_${hashSigKeyIndex}_pk.json"
hashSigSkPath="$configDir/hash-sig-keys/validator_${hashSigKeyIndex}_sk.json"
# Validate that hash-sig keys exist
if [ ! -f "$hashSigPkPath" ]; then
echo "Warning: Hash-sig public key not found at $hashSigPkPath"
echo "Run genesis generator to create hash-sig keys: ./generate-genesis.sh $configDir"
fi
if [ ! -f "$hashSigSkPath" ]; then
echo "Warning: Hash-sig secret key not found at $hashSigSkPath"
echo "Run genesis generator to create hash-sig keys: ./generate-genesis.sh $configDir"
fi
# Export hash-sig key paths for client use
export HASH_SIG_PK_PATH="$hashSigPkPath"
export HASH_SIG_SK_PATH="$hashSigSkPath"
export HASH_SIG_KEY_INDEX="$hashSigKeyIndex"
echo "Node: $item"
echo "QUIC Port: $quicPort"
echo "Metrics Port: $metricsPort"
echo "API Port: ${apiPort:-<not set>}"
echo "Devnet: ${devnet:-<not set>}"
echo "Private Key File: $privKeyPath"
echo "Key Type: $keyType"
echo "Hash-Sig Key Index: $hashSigKeyIndex"
echo "Hash-Sig Public Key: $hashSigPkPath"
echo "Hash-Sig Secret Key: $hashSigSkPath"
echo "Is Aggregator: $isAggregator"
if [ -n "$attestationCommitteeCount" ]; then
echo "Attestation Committee Count: $attestationCommitteeCount"
fi
else
echo "Node: $item"
echo "QUIC Port: $quicPort"
echo "Metrics Port: $metricsPort"
echo "API Port: ${apiPort:-<not set>}"
echo "Devnet: ${devnet:-<not set>}"
echo "Private Key File: $privKeyPath"
echo "Is Aggregator: $isAggregator"
if [ -n "$attestationCommitteeCount" ]; then
echo "Attestation Committee Count: $attestationCommitteeCount"
fi
fi