Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func main() {
// Start the attestation checker service in a goroutine
logger.Info("Starting attestation checker for %d validators", len(indices))
checker := &services.AttestationChecker{
BeaconAdapter: adapter,
ValidatorIndices: indices,
PollInterval: 1 * time.Minute,
CheckedEpochs: make(map[domain.ValidatorIndex]domain.Epoch),
BeaconAdapter: adapter,
Web3SignerAdapter: web3Signer,
PollInterval: 1 * time.Minute,
CheckedEpochs: make(map[domain.ValidatorIndex]domain.Epoch),
}
wg.Add(1)
go func() {
Expand Down
30 changes: 20 additions & 10 deletions internal/application/services/attestation_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

type AttestationChecker struct {
BeaconAdapter ports.BeaconChainAdapter
ValidatorIndices []domain.ValidatorIndex
PollInterval time.Duration
BeaconAdapter ports.BeaconChainAdapter
Web3SignerAdapter ports.Web3SignerAdapter
PollInterval time.Duration

lastFinalizedEpoch domain.Epoch
CheckedEpochs map[domain.ValidatorIndex]domain.Epoch // latest epoch checked for each validator index
Expand All @@ -39,16 +39,28 @@ func (a *AttestationChecker) checkLatestFinalizedEpoch(ctx context.Context) {
logger.Error("Error fetching finalized epoch: %v", err)
return
}

if finalizedEpoch == a.lastFinalizedEpoch {
logger.Debug("Finalized epoch %d unchanged, skipping check.", finalizedEpoch)
return
}

a.lastFinalizedEpoch = finalizedEpoch
logger.Info("New finalized epoch %d detected. Checking attestations for validators...", finalizedEpoch)
logger.Info("New finalized epoch %d detected.", finalizedEpoch)

pubkeys, err := a.Web3SignerAdapter.GetValidatorPubkeys()
if err != nil {
logger.Error("Error fetching pubkeys from web3signer: %v", err)
return
}

validatorIndices := a.getValidatorsToCheck(finalizedEpoch)
indices, err := a.BeaconAdapter.GetValidatorIndicesByPubkeys(ctx, pubkeys)
if err != nil {
logger.Error("Error fetching validator indices from beacon node: %v", err)
return
}
logger.Info("Found %d validator indices active", len(indices))

validatorIndices := a.getValidatorsToCheck(indices, finalizedEpoch)
if len(validatorIndices) == 0 {
return
}
Expand All @@ -58,8 +70,6 @@ func (a *AttestationChecker) checkLatestFinalizedEpoch(ctx context.Context) {
logger.Error("Error fetching validator duties: %v", err)
return
}

// This should never happen, we got here if we had no errors getting validator duties and there are validators to check.
if len(duties) == 0 {
logger.Warn("No duties found for finalized epoch %d. This should not happen!", finalizedEpoch)
return
Expand All @@ -80,9 +90,9 @@ func (a *AttestationChecker) checkLatestFinalizedEpoch(ctx context.Context) {
}
}

func (a *AttestationChecker) getValidatorsToCheck(epoch domain.Epoch) []domain.ValidatorIndex {
func (a *AttestationChecker) getValidatorsToCheck(indices []domain.ValidatorIndex, epoch domain.Epoch) []domain.ValidatorIndex {
var result []domain.ValidatorIndex
for _, index := range a.ValidatorIndices {
for _, index := range indices {
if a.wasCheckedThisEpoch(index, epoch) {
continue
}
Expand Down