Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
domiwei committed Apr 22, 2024
1 parent faa3488 commit c0eca92
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 27 deletions.
1 change: 1 addition & 0 deletions cl/beacon/synced_data/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "github.com/ledgerwatch/erigon/cl/phase1/core/state"
type SyncedData interface {
OnHeadState(newState *state.CachingBeaconState) (err error)
HeadState() *state.CachingBeaconState
HeadStateReader() state.BeaconStateReader
Syncing() bool
HeadSlot() uint64
}
14 changes: 14 additions & 0 deletions cl/beacon/synced_data/mock_services/synced_data_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cl/beacon/synced_data/synced_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (s *SyncedDataManager) HeadState() *state.CachingBeaconState {
return nil
}

func (s *SyncedDataManager) HeadStateReader() state.BeaconStateReader {
return s.HeadState()
}

func (s *SyncedDataManager) Syncing() bool {
if !s.enabled {
return false
Expand Down
12 changes: 12 additions & 0 deletions cl/phase1/core/state/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package state

import libcommon "github.com/ledgerwatch/erigon-lib/common"

// BeaconStateReader is an interface for reading the beacon state.
//
//go:generate mockgen -destination=./mock_services/beacon_state_reader.go -package=mock_services . BeaconStateReader
type BeaconStateReader interface {
ValidatorPublicKey(index int) (libcommon.Bytes48, error)
GetDomain(domainType [4]byte, epoch uint64) ([]byte, error)
CommitteeCount(epoch uint64) uint64
}
84 changes: 84 additions & 0 deletions cl/phase1/core/state/mock_services/beacon_state_reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions cl/phase1/network/services/attestation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
var (
computeSubnetForAttestation = subnets.ComputeSubnetForAttestation
computeCommitteeCountPerSlot = subnets.ComputeCommitteeCountPerSlot
computeSigningRoot = fork.ComputeSigningRoot
blsVerify = bls.Verify
)

type attestationService struct {
Expand Down Expand Up @@ -60,7 +62,7 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64,
committeeIndex = att.AttestantionData().CommitteeIndex()
targetEpoch = att.AttestantionData().Target().Epoch()
)
headState := s.syncedDataManager.HeadState()
headState := s.syncedDataManager.HeadStateReader()
if headState == nil {
return ErrIgnore
}
Expand Down Expand Up @@ -148,11 +150,11 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64,
if err != nil {
return fmt.Errorf("unable to get the domain: %v", err)
}
signingRoot, err := fork.ComputeSigningRoot(att.AttestantionData(), domain)
signingRoot, err := computeSigningRoot(att.AttestantionData(), domain)
if err != nil {
return fmt.Errorf("unable to get signing root: %v", err)
}
if valid, err := bls.Verify(signature[:], signingRoot[:], pubKey[:]); err != nil {
if valid, err := blsVerify(signature[:], signingRoot[:], pubKey[:]); err != nil {
return err
} else if !valid {
return fmt.Errorf("invalid signature")
Expand Down
Loading

0 comments on commit c0eca92

Please sign in to comment.