Skip to content

Commit

Permalink
🐛 fix validator balances and summaries when no retain array is set
Browse files Browse the repository at this point in the history
  • Loading branch information
aBMania committed Mar 4, 2024
1 parent 6c4633e commit a8633bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 39 deletions.
32 changes: 12 additions & 20 deletions services/chaindb/postgresql/validatorepochsummaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,36 +530,28 @@ func (s *Service) PruneValidatorEpochSummaries(ctx context.Context, to phase0.Ep
// Build the query.
queryBuilder := strings.Builder{}
queryVals := make([]any, 0)

queryBuilder.WriteString(`
DELETE FROM t_validator_epoch_summaries
`)
if len(retain) > 0 {
queryBuilder.WriteString(`
USING t_validators
`)
}
queryBuilder.WriteString(`
WHERE t_validator_epoch_summaries.f_validator_index = t_validators.f_index
AND f_epoch <= $1
`)
queryVals = append(queryVals, to)

if len(retain) > 0 {
queryBuilder.WriteString(`
AND NOT (t_validators.f_public_key = ANY($2))
`)
DELETE FROM t_validator_epoch_summaries
USING t_validators
WHERE f_epoch <= $1
AND t_validator_epoch_summaries.f_validator_index = t_validators.f_index
AND NOT (t_validators.f_public_key = ANY($2))`)

pubkeysBytes := make([][]byte, 0, len(retain))

for _, pubkey := range retain {
pubkeyBytes := make([]byte, len(pubkey))
copy(pubkeyBytes, pubkey[:])

pubkeysBytes = append(pubkeysBytes, pubkeyBytes)
for i := range retain {
pubkeysBytes = append(pubkeysBytes, retain[i][:])
}

queryVals = append(queryVals, pubkeysBytes)

} else {

Check failure on line 551 in services/chaindb/postgresql/validatorepochsummaries.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
queryBuilder.WriteString(`
DELETE FROM t_validator_epoch_summaries
WHERE f_epoch <= $1`)
}

if e := log.Trace(); e.Enabled() {
Expand Down
31 changes: 12 additions & 19 deletions services/chaindb/postgresql/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,35 +729,28 @@ func (s *Service) PruneValidatorBalances(ctx context.Context, to phase0.Epoch, r
queryBuilder := strings.Builder{}
queryVals := make([]any, 0)

queryBuilder.WriteString(`
DELETE FROM t_validator_balances
`)
if len(retain) > 0 {
queryBuilder.WriteString(`
USING t_validators
`)
}
queryBuilder.WriteString(`
WHERE t_validator_balances.f_validator_index = t_validators.f_index
AND f_epoch <= $1
`)
queryVals = append(queryVals, to)

if len(retain) > 0 {
queryBuilder.WriteString(`
AND NOT (t_validators.f_public_key = ANY($2))
`)
DELETE FROM t_validator_balances
USING t_validators
WHERE f_epoch <= $1
AND t_validator_balances.f_validator_index = t_validators.f_index
AND NOT (t_validators.f_public_key = ANY($2))`)

pubkeysBytes := make([][]byte, 0, len(retain))

for _, pubkey := range retain {
pubkeyBytes := make([]byte, len(pubkey))
copy(pubkeyBytes, pubkey[:])

pubkeysBytes = append(pubkeysBytes, pubkeyBytes)
for i := range retain {
pubkeysBytes = append(pubkeysBytes, retain[i][:])
}

queryVals = append(queryVals, pubkeysBytes)

} else {

Check failure on line 750 in services/chaindb/postgresql/validators.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
queryBuilder.WriteString(`
DELETE FROM t_validator_balances
WHERE f_epoch <= $1`)
}

if e := log.Trace(); e.Enabled() {
Expand Down

0 comments on commit a8633bf

Please sign in to comment.