Skip to content

Commit 1455cc0

Browse files
committed
fix linter issues
1 parent 177019f commit 1455cc0

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

pkg/coordinator/tasks/check_consensus_identity/config.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ type Config struct {
1515
FailOnCheckMiss bool `yaml:"failOnCheckMiss" json:"failOnCheckMiss"`
1616

1717
// CGC (Custody Group Count) checks
18-
ExpectCGC *int `yaml:"expectCgc" json:"expectCgc"`
19-
MinCGC *int `yaml:"minCgc" json:"minCgc"`
20-
MaxCGC *int `yaml:"maxCgc" json:"maxCgc"`
18+
ExpectCGC *uint64 `yaml:"expectCgc" json:"expectCgc"`
19+
MinCGC *uint64 `yaml:"minCgc" json:"minCgc"`
20+
MaxCGC *uint64 `yaml:"maxCgc" json:"maxCgc"`
2121

2222
// ENR checks
2323
ExpectENRField map[string]interface{} `yaml:"expectEnrField" json:"expectEnrField"`
@@ -47,18 +47,6 @@ func (c *Config) Validate() error {
4747
return fmt.Errorf("clientPattern is required")
4848
}
4949

50-
if c.ExpectCGC != nil && *c.ExpectCGC < 0 {
51-
return fmt.Errorf("expectCgc must be >= 0")
52-
}
53-
54-
if c.MinCGC != nil && *c.MinCGC < 0 {
55-
return fmt.Errorf("minCgc must be >= 0")
56-
}
57-
58-
if c.MaxCGC != nil && *c.MaxCGC < 0 {
59-
return fmt.Errorf("maxCgc must be >= 0")
60-
}
61-
6250
if c.MinCGC != nil && c.MaxCGC != nil && *c.MinCGC > *c.MaxCGC {
6351
return fmt.Errorf("minCgc must be <= maxCgc")
6452
}

pkg/coordinator/tasks/check_consensus_identity/task.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type IdentityCheckResult struct {
4444
SeqNumber uint64 `json:"seqNumber"`
4545
Attnets string `json:"attnets"`
4646
Syncnets string `json:"syncnets"`
47-
CGC int `json:"cgc"`
47+
CGC uint64 `json:"cgc"`
4848
ENRFields map[string]interface{} `json:"enrFields"`
4949
ChecksPassed bool `json:"checksPassed"`
5050
FailureReasons []string `json:"failureReasons"`
@@ -118,6 +118,7 @@ func (t *Task) processCheck() {
118118
}
119119

120120
totalClientCount++
121+
121122
t.logger.Infof("Checking identity for client: %s", client.Config.Name)
122123

123124
result := t.checkClientIdentity(client)
@@ -131,12 +132,14 @@ func (t *Task) processCheck() {
131132
t.logger.Infof(" Discovery Addresses: %v", result.DiscoveryAddresses)
132133
t.logger.Infof(" Sequence Number: %d", result.SeqNumber)
133134
t.logger.Infof(" Checks Passed: %v", result.ChecksPassed)
135+
134136
if len(result.FailureReasons) > 0 {
135137
t.logger.Infof(" Failure Reasons: %v", result.FailureReasons)
136138
}
137139

138140
if result.ChecksPassed {
139141
passResultCount++
142+
140143
matchingClients = append(matchingClients, result)
141144
t.logger.Infof("✅ Client %s passed all checks", result.ClientName)
142145
} else {
@@ -221,8 +224,10 @@ func (t *Task) checkClientIdentity(client *clients.PoolClient) *IdentityCheckRes
221224
identity, err := client.ConsensusClient.GetRPCClient().GetNodeIdentity(ctx)
222225
if err != nil {
223226
t.logger.Errorf("Failed to get node identity for client %s: %v", client.Config.Name, err)
227+
224228
result.ChecksPassed = false
225229
result.FailureReasons = append(result.FailureReasons, fmt.Sprintf("Failed to get node identity: %v", err))
230+
226231
return result
227232
}
228233

@@ -239,11 +244,14 @@ func (t *Task) checkClientIdentity(client *clients.PoolClient) *IdentityCheckRes
239244

240245
// Extract CGC from ENR
241246
t.logger.Debugf("Extracting CGC from ENR for client %s", client.Config.Name)
247+
242248
cgc, enrFields, err := t.extractCGCFromENR(identity.ENR)
243249
if err != nil {
244250
t.logger.Errorf("Failed to parse ENR for client %s: %v", client.Config.Name, err)
251+
245252
result.ChecksPassed = false
246253
result.FailureReasons = append(result.FailureReasons, fmt.Sprintf("Failed to parse ENR: %v", err))
254+
247255
return result
248256
}
249257

@@ -303,12 +311,14 @@ func (t *Task) performChecks(result *IdentityCheckResult) {
303311
// Check P2P address match
304312
if t.config.ExpectP2PAddressMatch != "" {
305313
found := false
314+
306315
for _, addr := range result.P2PAddresses {
307316
if matched, _ := regexp.MatchString(t.config.ExpectP2PAddressMatch, addr); matched {
308317
found = true
309318
break
310319
}
311320
}
321+
312322
if !found {
313323
result.ChecksPassed = false
314324
result.FailureReasons = append(result.FailureReasons,
@@ -344,7 +354,7 @@ func (t *Task) performChecks(result *IdentityCheckResult) {
344354
}
345355

346356
// extractCGCFromENR extracts the Custody Group Count from ENR using proper ENR parsing
347-
func (t *Task) extractCGCFromENR(enrStr string) (int, map[string]interface{}, error) {
357+
func (t *Task) extractCGCFromENR(enrStr string) (cgc uint64, enrFields map[string]interface{}, err error) {
348358
if enrStr == "" {
349359
t.logger.Debugf("Empty ENR provided")
350360
return 0, nil, fmt.Errorf("empty ENR")
@@ -360,10 +370,8 @@ func (t *Task) extractCGCFromENR(enrStr string) (int, map[string]interface{}, er
360370
}
361371

362372
// Get all key-value pairs from ENR
363-
enrFields := t.getKeyValuesFromENR(record)
373+
enrFields = t.getKeyValuesFromENR(record)
364374

365-
// Extract CGC from the fields
366-
cgc := 0
367375
if cgcHex, ok := enrFields["cgc"]; ok {
368376
// CGC is stored as hex string, parse it
369377
cgcStr, ok := cgcHex.(string)
@@ -372,11 +380,12 @@ func (t *Task) extractCGCFromENR(enrStr string) (int, map[string]interface{}, er
372380
} else {
373381
// Remove "0x" prefix if present
374382
cgcStr = strings.TrimPrefix(cgcStr, "0x")
383+
375384
val, err := strconv.ParseUint(cgcStr, 16, 64)
376385
if err != nil {
377386
t.logger.Errorf("Failed to parse CGC value %s: %v", cgcStr, err)
378387
} else {
379-
cgc = int(val)
388+
cgc = val
380389
t.logger.Debugf("Found CGC in ENR: %d", cgc)
381390
}
382391
}
@@ -397,13 +406,15 @@ func (t *Task) decodeENR(raw string) (*enr.Record, error) {
397406
}
398407

399408
dec := make([]byte, base64.RawURLEncoding.DecodedLen(len(b)))
409+
400410
n, err := base64.RawURLEncoding.Decode(dec, b)
401411
if err != nil {
402412
return nil, err
403413
}
404414

405415
var r enr.Record
406416
err = rlp.DecodeBytes(dec[:n], &r)
417+
407418
return &r, err
408419
}
409420

@@ -417,8 +428,17 @@ func (t *Task) getKeyValuesFromENR(r *enr.Record) map[string]interface{} {
417428
// Get all key-value pairs from the record
418429
kv := r.AppendElements(nil)[1:] // Skip the sequence number
419430
for i := 0; i < len(kv); i += 2 {
420-
key := kv[i].(string)
421-
val := kv[i+1].(rlp.RawValue)
431+
key, ok := kv[i].(string)
432+
if !ok {
433+
t.logger.Warnf("Invalid ENR key type: %T", kv[i])
434+
continue
435+
}
436+
437+
val, ok := kv[i+1].(rlp.RawValue)
438+
if !ok {
439+
t.logger.Warnf("Invalid ENR value type for key %s: %T", key, kv[i+1])
440+
continue
441+
}
422442

423443
// Format the value based on the key
424444
fmtval := t.formatENRValue(key, val)

pkg/coordinator/tasks/get_consensus_validators/task.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Task struct {
3030
}
3131

3232
type ValidatorInfo struct {
33-
Index int `json:"index"`
33+
Index uint64 `json:"index"`
3434
Pubkey string `json:"pubkey"`
3535
Balance uint64 `json:"balance"`
3636
Status string `json:"status"`
@@ -81,7 +81,8 @@ func (t *Task) LoadConfig() error {
8181
return nil
8282
}
8383

84-
func (t *Task) Execute(ctx context.Context) error {
84+
//nolint:gocyclo // ignore
85+
func (t *Task) Execute(_ context.Context) error {
8586
// Get client pool and validator names
8687
clientPool := t.ctx.Scheduler.GetServices().ClientPool()
8788
consensusPool := clientPool.GetConsensusPool()
@@ -97,18 +98,22 @@ func (t *Task) Execute(ctx context.Context) error {
9798

9899
// Compile validator name pattern regex if provided
99100
var validatorNameRegex *regexp.Regexp
101+
100102
if t.config.ValidatorNamePattern != "" {
101103
var err error
102104
validatorNameRegex, err = regexp.Compile(t.config.ValidatorNamePattern)
105+
103106
if err != nil {
104107
return fmt.Errorf("invalid validator name pattern: %v", err)
105108
}
106109
}
107110

108111
// Compile client pattern regex if provided
109112
var clientNameRegex *regexp.Regexp
113+
110114
if t.config.ClientPattern != "" {
111115
var err error
116+
112117
clientNameRegex, err = regexp.Compile(t.config.ClientPattern)
113118
if err != nil {
114119
return fmt.Errorf("invalid client pattern: %v", err)
@@ -125,6 +130,7 @@ func (t *Task) Execute(ctx context.Context) error {
125130
if t.config.MinValidatorIndex != nil && uint64(validatorIndex) < *t.config.MinValidatorIndex {
126131
continue
127132
}
133+
128134
if t.config.MaxValidatorIndex != nil && uint64(validatorIndex) > *t.config.MaxValidatorIndex {
129135
continue
130136
}
@@ -133,6 +139,7 @@ func (t *Task) Execute(ctx context.Context) error {
133139
if t.config.MinValidatorBalance != nil && uint64(validator.Balance) < *t.config.MinValidatorBalance {
134140
continue
135141
}
142+
136143
if t.config.MaxValidatorBalance != nil && uint64(validator.Balance) > *t.config.MaxValidatorBalance {
137144
continue
138145
}
@@ -149,12 +156,14 @@ func (t *Task) Execute(ctx context.Context) error {
149156
if len(t.config.ValidatorStatus) > 0 {
150157
statusMatch := false
151158
validatorStatus := validator.Status.String()
159+
152160
for _, allowedStatus := range t.config.ValidatorStatus {
153161
if validatorStatus == allowedStatus {
154162
statusMatch = true
155163
break
156164
}
157165
}
166+
158167
if !statusMatch {
159168
continue
160169
}
@@ -182,7 +191,7 @@ func (t *Task) Execute(ctx context.Context) error {
182191

183192
// Create validator info
184193
validatorInfo := ValidatorInfo{
185-
Index: int(validatorIndex),
194+
Index: uint64(validatorIndex),
186195
Pubkey: fmt.Sprintf("0x%x", validator.Validator.PublicKey),
187196
Balance: uint64(validator.Balance),
188197
Status: validator.Status.String(),
@@ -210,16 +219,18 @@ func (t *Task) Execute(ctx context.Context) error {
210219
for i, validator := range matchingValidators {
211220
pubkeys[i] = validator.Pubkey
212221
}
222+
213223
if pubkeysData, err := vars.GeneralizeData(pubkeys); err == nil {
214224
t.ctx.Outputs.SetVar("pubkeys", pubkeysData)
215225
} else {
216226
return fmt.Errorf("failed to generalize pubkeys data: %v", err)
217227
}
218228
case "indices":
219-
indices := make([]int, len(matchingValidators))
229+
indices := make([]uint64, len(matchingValidators))
220230
for i, validator := range matchingValidators {
221231
indices[i] = validator.Index
222232
}
233+
223234
if indicesData, err := vars.GeneralizeData(indices); err == nil {
224235
t.ctx.Outputs.SetVar("indices", indicesData)
225236
} else {

0 commit comments

Comments
 (0)