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 fixes #4716

Merged
merged 3 commits into from Feb 2, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions beacon-chain/blockchain/forkchoice/process_attestation.go
Expand Up @@ -166,10 +166,9 @@ func (s *Store) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (*state
return nil, fmt.Errorf("pre state of target block %d does not exist", helpers.StartSlot(c.Epoch))
}

stateCopy := baseState.Copy()

if helpers.StartSlot(c.Epoch) > stateCopy.Slot() {
stateCopy, err = state.ProcessSlots(ctx, stateCopy, helpers.StartSlot(c.Epoch))
if helpers.StartSlot(c.Epoch) > baseState.Slot() {
baseState, err = state.ProcessSlots(ctx, baseState, helpers.StartSlot(c.Epoch))
if err != nil {
return nil, errors.Wrapf(err, "could not process slots up to %d", helpers.StartSlot(c.Epoch))
}
Expand All @@ -178,12 +177,12 @@ func (s *Store) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (*state

if err := s.checkpointState.AddCheckpointState(&cache.CheckpointState{
Checkpoint: c,
State: stateCopy,
State: baseState.Copy(),
}); err != nil {
return nil, errors.Wrap(err, "could not saved checkpoint state to cache")
}

return stateCopy, nil
return baseState, nil
}

// verifyAttTargetEpoch validates attestation is from the current or previous epoch.
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/forkchoice/service.go
Expand Up @@ -106,7 +106,7 @@ func (s *Store) GenesisStore(

if err := s.checkpointState.AddCheckpointState(&cache.CheckpointState{
Checkpoint: s.justifiedCheckpt,
State: justifiedState,
State: justifiedState.Copy(),
}); err != nil {
return errors.Wrap(err, "could not save genesis state in check point cache")
}
Expand Down
9 changes: 4 additions & 5 deletions beacon-chain/blockchain/process_attestation_helpers.go
Expand Up @@ -36,23 +36,22 @@ func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (*sta
return nil, fmt.Errorf("pre state of target block %d does not exist", helpers.StartSlot(c.Epoch))
}

stateCopy := baseState.Copy()

if helpers.StartSlot(c.Epoch) > stateCopy.Slot() {
stateCopy, err = state.ProcessSlots(ctx, stateCopy, helpers.StartSlot(c.Epoch))
if helpers.StartSlot(c.Epoch) > baseState.Slot() {
baseState, err = state.ProcessSlots(ctx, baseState, helpers.StartSlot(c.Epoch))
if err != nil {
return nil, errors.Wrapf(err, "could not process slots up to %d", helpers.StartSlot(c.Epoch))
}
}

if err := s.checkpointState.AddCheckpointState(&cache.CheckpointState{
Checkpoint: c,
State: stateCopy,
State: baseState.Copy(),
}); err != nil {
return nil, errors.Wrap(err, "could not saved checkpoint state to cache")
}

return stateCopy, nil
return baseState, nil
}

// verifyAttTargetEpoch validates attestation is from the current or previous epoch.
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/receive_attestation.go
Expand Up @@ -96,7 +96,7 @@ func (s *Service) processAttestation() {
ctx := context.Background()
atts := s.attPool.ForkchoiceAttestations()
for _, a := range atts {
hasState := s.beaconDB.HasState(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot))
hasState := s.beaconDB.HasState(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot)) && s.beaconDB.HasState(ctx, bytesutil.ToBytes32(a.Data.Target.Root))
hasBlock := s.beaconDB.HasBlock(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot))
if !(hasState && hasBlock) {
continue
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/cache/checkpoint_state.go
Expand Up @@ -91,7 +91,7 @@ func (c *CheckpointStateCache) StateByCheckpoint(cp *ethpb.Checkpoint) (*stateTr
return nil, ErrNotCheckpointState
}

return info.State, nil
return info.State.Copy(), nil
}

// AddCheckpointState adds CheckpointState object to the cache. This method also trims the least
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/cache/checkpoint_state_test.go
Expand Up @@ -71,7 +71,7 @@ func TestCheckpointStateCache_StateByCheckpoint(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(state, info1.State) {
if !reflect.DeepEqual(state.InnerStateUnsafe(), info1.State.InnerStateUnsafe()) {
t.Error("incorrectly cached state")
}

Expand All @@ -93,15 +93,15 @@ func TestCheckpointStateCache_StateByCheckpoint(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(state, info2.State) {
if !reflect.DeepEqual(state.InnerStateUnsafe(), info2.State.InnerStateUnsafe()) {
t.Error("incorrectly cached state")
}

state, err = cache.StateByCheckpoint(cp1)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(state, info1.State) {
if !reflect.DeepEqual(state.InnerStateUnsafe(), info1.State.InnerStateUnsafe()) {
t.Error("incorrectly cached state")
}
}
Expand Down