Skip to content

Commit

Permalink
Minor tweaks to GetAttestationData (prysmaticlabs#4533)
Browse files Browse the repository at this point in the history
* Maybe bugfix

* Maybe bugfix

* make GetAttestationData cheaper

* clone head state getter return values

* Fix tests

* fix e2e and revert most changes 😩

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and cryptomental committed Feb 28, 2020
1 parent 4095605 commit 8fe107c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
6 changes: 3 additions & 3 deletions beacon-chain/blockchain/chain_info.go
Expand Up @@ -67,7 +67,7 @@ func (s *Service) FinalizedCheckpt() *ethpb.Checkpoint {
return &ethpb.Checkpoint{Root: s.genesisRoot[:]}
}

return s.headState.FinalizedCheckpoint
return proto.Clone(s.headState.FinalizedCheckpoint).(*ethpb.Checkpoint)
}

// CurrentJustifiedCheckpt returns the current justified checkpoint from head state.
Expand All @@ -82,7 +82,7 @@ func (s *Service) CurrentJustifiedCheckpt() *ethpb.Checkpoint {
return &ethpb.Checkpoint{Root: s.genesisRoot[:]}
}

return s.headState.CurrentJustifiedCheckpoint
return proto.Clone(s.headState.CurrentJustifiedCheckpoint).(*ethpb.Checkpoint)
}

// PreviousJustifiedCheckpt returns the previous justified checkpoint from head state.
Expand All @@ -97,7 +97,7 @@ func (s *Service) PreviousJustifiedCheckpt() *ethpb.Checkpoint {
return &ethpb.Checkpoint{Root: s.genesisRoot[:]}
}

return s.headState.PreviousJustifiedCheckpoint
return proto.Clone(s.headState.PreviousJustifiedCheckpoint).(*ethpb.Checkpoint)
}

// HeadSlot returns the slot of the head of the chain.
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/service.go
Expand Up @@ -200,6 +200,7 @@ func (s *Service) Start() {
AttPool: s.attestationsPool,
HeadFetcher: s.headFetcher,
ForkFetcher: s.forkFetcher,
FinalizationFetcher: s.finalizationFetcher,
CanonicalStateChan: s.canonicalStateChan,
BlockFetcher: s.powChainService,
DepositFetcher: s.depositFetcher,
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/validator/attester.go
Expand Up @@ -63,7 +63,7 @@ func (vs *Server) GetAttestationData(ctx context.Context, req *ethpb.Attestation
headRoot := vs.HeadFetcher.HeadRoot()

if helpers.CurrentEpoch(headState) < helpers.SlotToEpoch(req.Slot) {
headState, err = state.ProcessSlots(ctx, headState, req.Slot)
headState, err = state.ProcessSlots(ctx, headState, helpers.StartSlot(helpers.SlotToEpoch(req.Slot)))
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not process slots up to %d: %v", req.Slot, err)
}
Expand Down
22 changes: 12 additions & 10 deletions beacon-chain/rpc/validator/attester_test.go
Expand Up @@ -152,11 +152,12 @@ func TestGetAttestationData_OK(t *testing.T) {
beaconState.BlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = targetRoot[:]
beaconState.BlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedRoot[:]
attesterServer := &Server{
BeaconDB: db,
P2P: &mockp2p.MockBroadcaster{},
SyncChecker: &mockSync.Sync{IsSyncing: false},
AttestationCache: cache.NewAttestationCache(),
HeadFetcher: &mock.ChainService{State: beaconState, Root: blockRoot[:]},
BeaconDB: db,
P2P: &mockp2p.MockBroadcaster{},
SyncChecker: &mockSync.Sync{IsSyncing: false},
AttestationCache: cache.NewAttestationCache(),
HeadFetcher: &mock.ChainService{State: beaconState, Root: blockRoot[:]},
FinalizationFetcher: &mock.ChainService{CurrentJustifiedCheckPoint: beaconState.CurrentJustifiedCheckpoint},
}
if err := db.SaveState(ctx, beaconState, blockRoot); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -257,11 +258,12 @@ func TestAttestationDataAtSlot_handlesFarAwayJustifiedEpoch(t *testing.T) {
beaconState.BlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = epochBoundaryRoot[:]
beaconState.BlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedBlockRoot[:]
attesterServer := &Server{
BeaconDB: db,
P2P: &mockp2p.MockBroadcaster{},
AttestationCache: cache.NewAttestationCache(),
HeadFetcher: &mock.ChainService{State: beaconState, Root: blockRoot[:]},
SyncChecker: &mockSync.Sync{IsSyncing: false},
BeaconDB: db,
P2P: &mockp2p.MockBroadcaster{},
AttestationCache: cache.NewAttestationCache(),
HeadFetcher: &mock.ChainService{State: beaconState, Root: blockRoot[:]},
FinalizationFetcher: &mock.ChainService{CurrentJustifiedCheckPoint: beaconState.CurrentJustifiedCheckpoint},
SyncChecker: &mockSync.Sync{IsSyncing: false},
}
if err := db.SaveState(ctx, beaconState, blockRoot); err != nil {
t.Fatal(err)
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/validator/server.go
Expand Up @@ -41,6 +41,7 @@ type Server struct {
AttestationCache *cache.AttestationCache
HeadFetcher blockchain.HeadFetcher
ForkFetcher blockchain.ForkFetcher
FinalizationFetcher blockchain.FinalizationFetcher
CanonicalStateChan chan *pbp2p.BeaconState
BlockFetcher powchain.POWBlockFetcher
DepositFetcher depositcache.DepositFetcher
Expand Down

0 comments on commit 8fe107c

Please sign in to comment.