1+ id : analyze-cgc
2+ name : " CGC Analysis - Validate CGC vs Validator Balances"
3+ timeout : 30m
4+
5+ config :
6+ validatorPairNames : []
7+
8+ tasks :
9+ - name : check_clients_are_healthy
10+ title : " Check if at least one client is ready"
11+ timeout : 5m
12+ config :
13+ minClientCount : 1
14+
15+ # Matrix task to analyze each client pattern
16+ - name : run_task_matrix
17+ title : " Analyze CGC for all client patterns"
18+ id : cgc_analysis
19+ timeout : 25m
20+ configVars :
21+ matrixValues : " validatorPairNames"
22+ config :
23+ runConcurrent : true
24+ matrixVar : " validatorPairName"
25+ task :
26+ name : run_tasks
27+ title : " Analyze CGC for ${validatorPairName}"
28+ config :
29+ tasks :
30+ # Step 1: Get consensus client identity (CGC)
31+ - name : check_consensus_identity
32+ title : " Get CGC for clients matching ${validatorPairName}"
33+ id : client_identity
34+ timeout : 30s
35+ config :
36+ minClientCount : 1
37+ failOnCheckMiss : false
38+ pollInterval : 5s
39+ configVars :
40+ clientPattern : " validatorPairName"
41+
42+ # Step 2: Get validators for these clients
43+ - name : get_consensus_validators
44+ title : " Get validators for clients matching ${validatorPairName}"
45+ id : client_validators
46+ timeout : 60s
47+ config :
48+ validatorStatus : ["active_ongoing", "active_exiting", "active_slashed"]
49+ maxResults : 10000 # Get all validators
50+ outputFormat : " full"
51+ configVars :
52+ clientPattern : " validatorPairName"
53+
54+ # Step 3: Calculate and analyze results
55+ - name : run_shell
56+ title : " Calculate CGC analysis for ${validatorPairName}"
57+ id : cgc_calculation
58+ timeout : 30s
59+ config :
60+ envVars :
61+ client_identity : " tasks.client_identity.outputs.matchingClients"
62+ validators : " tasks.client_validators.outputs.validators"
63+ client_pattern : " validatorPairName"
64+ command : |
65+ echo "=== CGC Analysis for ${client_pattern} ==="
66+
67+ # Extract client info
68+ client_count=$(echo "$client_identity" | jq -r 'length')
69+ if [ "$client_count" -eq 0 ]; then
70+ echo "⚠️ No clients found matching pattern: ${client_pattern}"
71+ echo "::set-out-json status \"no_clients\""
72+ echo "::set-out-json client_name \"${client_pattern}\""
73+ exit 0
74+ fi
75+
76+ # Get first client's data
77+ client_name=$(echo "$client_identity" | jq -r '.[0].clientName')
78+ current_cgc=$(echo "$client_identity" | jq -r '.[0].cgc')
79+
80+ echo "Client: $client_name"
81+ echo "Current CGC: $current_cgc"
82+
83+ # Calculate validator stats
84+ validator_count=$(echo "$validators" | jq -r 'length')
85+ echo "Validators found: $validator_count"
86+
87+ if [ "$validator_count" -eq 0 ]; then
88+ echo "⚠️ No validators found for client: $client_name"
89+ echo "::set-out-json status \"no_validators\""
90+ echo "::set-out-json client_name \"$client_name\""
91+ echo "::set-out-json current_cgc $current_cgc"
92+ echo "::set-out-json validator_count 0"
93+ echo "::set-out-json total_effective_balance_eth 0"
94+ echo "::set-out-json required_cgc 0"
95+ echo "::set-out-json cgc_sufficient true"
96+ exit 0
97+ fi
98+
99+ # Sum effective balances (in gwei)
100+ total_balance_gwei=$(echo "$validators" | jq -r '[.[].effectiveBalance] | add')
101+
102+ # Convert to ETH (1 ETH = 1e9 gwei)
103+ total_balance_eth=$(echo "scale=6; $total_balance_gwei / 1000000000" | bc -l)
104+
105+ echo "Total effective balance: ${total_balance_eth} ETH"
106+
107+ # Calculate required CGC: ceil(total_balance_eth / 32)
108+ # Using bc for floating point math
109+ required_cgc=$(echo "scale=0; ($total_balance_gwei + 31999999999) / 32000000000" | bc -l)
110+
111+ echo "Required CGC (minimum): $required_cgc"
112+ echo "Current CGC: $current_cgc"
113+
114+ # Check if CGC is sufficient
115+ if [ "$current_cgc" -ge "$required_cgc" ]; then
116+ cgc_sufficient=true
117+ status="✅ CGC sufficient"
118+ echo "$status"
119+ else
120+ cgc_sufficient=false
121+ status="❌ CGC insufficient"
122+ echo "$status"
123+ deficit=$((required_cgc - current_cgc))
124+ echo "CGC deficit: $deficit"
125+ fi
126+
127+ # Set outputs
128+ echo "::set-out-json status \"analyzed\""
129+ echo "::set-out-json client_name \"$client_name\""
130+ echo "::set-out-json current_cgc $current_cgc"
131+ echo "::set-out-json validator_count $validator_count"
132+ echo "::set-out-json total_effective_balance_eth $total_balance_eth"
133+ echo "::set-out-json total_effective_balance_gwei $total_balance_gwei"
134+ echo "::set-out-json required_cgc $required_cgc"
135+ echo "::set-out-json cgc_sufficient $cgc_sufficient"
136+
137+ if [ "$cgc_sufficient" = "false" ]; then
138+ echo "::set-out-json cgc_deficit $((required_cgc - current_cgc))"
139+ else
140+ echo "::set-out-json cgc_deficit 0"
141+ fi
142+
143+ # Final summary
144+ - name : run_shell
145+ title : " CGC Analysis Summary"
146+ timeout : 1m
147+ config :
148+ envVars :
149+ analysis_results : " | [.tasks.cgc_analysis.outputs.childScopes[]?.tasks.cgc_calculation.outputs]"
150+ command : |
151+ echo "======================================="
152+ echo " CGC ANALYSIS SUMMARY"
153+ echo "======================================="
154+ echo ""
155+
156+ # Count results
157+ total_clients=$(echo "$analysis_results" | jq -r 'length')
158+ analyzed_count=0
159+ no_clients_count=0
160+ no_validators_count=0
161+ sufficient_count=0
162+ insufficient_count=0
163+ total_balance_sum=0
164+ total_validator_count=0
165+
166+ echo "Analyzed $total_clients client patterns:"
167+ echo ""
168+
169+ for i in $(seq 0 $((total_clients - 1))); do
170+ result=$(echo "$analysis_results" | jq -r ".[$i]")
171+
172+ if [ "$result" != "null" ]; then
173+ status=$(echo "$result" | jq -r '.status // "unknown"')
174+ client_name=$(echo "$result" | jq -r '.client_name // "unknown"')
175+
176+ case "$status" in
177+ "analyzed")
178+ analyzed_count=$((analyzed_count + 1))
179+ current_cgc=$(echo "$result" | jq -r '.current_cgc')
180+ validator_count=$(echo "$result" | jq -r '.validator_count')
181+ balance_eth=$(echo "$result" | jq -r '.total_effective_balance_eth')
182+ balance_gwei=$(echo "$result" | jq -r '.total_effective_balance_gwei')
183+ required_cgc=$(echo "$result" | jq -r '.required_cgc')
184+ cgc_sufficient=$(echo "$result" | jq -r '.cgc_sufficient')
185+
186+ echo "📊 Client: $client_name"
187+ echo " Validators: $validator_count"
188+ echo " Total Balance: ${balance_eth} ETH"
189+ echo " Current CGC: $current_cgc"
190+ echo " Required CGC: $required_cgc"
191+
192+ if [ "$cgc_sufficient" = "true" ]; then
193+ echo " Status: ✅ CGC Sufficient"
194+ sufficient_count=$((sufficient_count + 1))
195+ else
196+ deficit=$(echo "$result" | jq -r '.cgc_deficit')
197+ echo " Status: ❌ CGC Insufficient (deficit: $deficit)"
198+ insufficient_count=$((insufficient_count + 1))
199+ fi
200+
201+ # Add to totals (using integer math for gwei)
202+ total_balance_sum=$((total_balance_sum + balance_gwei))
203+ total_validator_count=$((total_validator_count + validator_count))
204+ ;;
205+ "no_clients")
206+ no_clients_count=$((no_clients_count + 1))
207+ echo "⚠️ Pattern: $client_name - No clients found"
208+ ;;
209+ "no_validators")
210+ no_validators_count=$((no_validators_count + 1))
211+ current_cgc=$(echo "$result" | jq -r '.current_cgc')
212+ echo "⚠️ Client: $client_name - No validators (CGC: $current_cgc)"
213+ ;;
214+ esac
215+ echo ""
216+ fi
217+ done
218+
219+ echo "======================================="
220+ echo " SUMMARY STATISTICS"
221+ echo "======================================="
222+ echo "Total patterns analyzed: $total_clients"
223+ echo "Clients analyzed: $analyzed_count"
224+ echo "Patterns with no clients: $no_clients_count"
225+ echo "Clients with no validators: $no_validators_count"
226+ echo ""
227+ echo "CGC Status:"
228+ echo " ✅ Sufficient: $sufficient_count"
229+ echo " ❌ Insufficient: $insufficient_count"
230+ echo ""
231+
232+ if [ "$total_validator_count" -gt 0 ]; then
233+ # Convert total balance back to ETH for display
234+ total_balance_eth=$(echo "scale=6; $total_balance_sum / 1000000000" | bc -l)
235+ echo "Network totals:"
236+ echo " Total validators: $total_validator_count"
237+ echo " Total effective balance: ${total_balance_eth} ETH"
238+
239+ # Calculate network-wide required CGC
240+ network_required_cgc=$(echo "scale=0; ($total_balance_sum + 31999999999) / 32000000000" | bc -l)
241+ echo " Network required CGC: $network_required_cgc"
242+ fi
243+
244+ echo ""
245+ if [ "$insufficient_count" -eq 0 ]; then
246+ echo "🎉 All clients have sufficient CGC!"
247+ else
248+ echo "⚠️ $insufficient_count clients have insufficient CGC"
249+ fi
250+ echo "======================================="
0 commit comments