Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor tweaks to GetAttestationData #4533

Merged
merged 9 commits into from Jan 14, 2020
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