From 6f52db8d5e64ba944911dddc73d379584e3552c2 Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Thu, 31 Oct 2024 07:23:45 +0000 Subject: [PATCH] fix(notifications): properly initialize efficiency map in all cases --- backend/cmd/misc/main.go | 2 +- backend/pkg/notification/collection.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/cmd/misc/main.go b/backend/cmd/misc/main.go index 5134cc5e9..2851ff268 100644 --- a/backend/cmd/misc/main.go +++ b/backend/cmd/misc/main.go @@ -569,7 +569,7 @@ func collectNotifications(startEpoch uint64) error { if err != nil { return err } - defer tx.Rollback() + defer utils.Rollback(tx) err = notification.QueueWebhookNotifications(notifications, tx) if err != nil { diff --git a/backend/pkg/notification/collection.go b/backend/pkg/notification/collection.go index 2c703e583..04089dec9 100644 --- a/backend/pkg/notification/collection.go +++ b/backend/pkg/notification/collection.go @@ -519,6 +519,13 @@ func collectGroupEfficiencyNotifications(notificationsByUserID types.Notificatio return fmt.Errorf("error getting proposal assignments: %w", err) } for _, assignment := range proposalAssignments.Data { + if _, ok := efficiencyMap[types.ValidatorIndex(assignment.ValidatorIndex)]; !ok { + efficiencyMap[types.ValidatorIndex(assignment.ValidatorIndex)] = &dbResult{ + ValidatorIndex: assignment.ValidatorIndex, + AttestationReward: decimal.Decimal{}, + AttestationIdealReward: decimal.Decimal{}, + } + } efficiencyMap[types.ValidatorIndex(assignment.ValidatorIndex)].BlocksScheduled++ } @@ -538,6 +545,13 @@ func collectGroupEfficiencyNotifications(notificationsByUserID types.Notificatio efficiencyMap[types.ValidatorIndex(s.Data.Message.ProposerIndex)].BlocksProposed++ for i, validatorIndex := range syncAssignments.Data.Validators { + if _, ok := efficiencyMap[types.ValidatorIndex(validatorIndex)]; !ok { + efficiencyMap[types.ValidatorIndex(validatorIndex)] = &dbResult{ + ValidatorIndex: uint64(validatorIndex), + AttestationReward: decimal.Decimal{}, + AttestationIdealReward: decimal.Decimal{}, + } + } efficiencyMap[types.ValidatorIndex(validatorIndex)].SyncScheduled++ if utils.BitAtVector(s.Data.Message.Body.SyncAggregate.SyncCommitteeBits, i) {