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

Don't insert head to proto array DAG as index 0 #4749

Merged
merged 2 commits into from Feb 5, 2020
Merged
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
32 changes: 2 additions & 30 deletions beacon-chain/blockchain/service.go
Expand Up @@ -163,9 +163,7 @@ func (s *Service) Start() {
s.finalizedCheckpt = proto.Clone(finalizedCheckpoint).(*ethpb.Checkpoint)
s.prevFinalizedCheckpt = proto.Clone(finalizedCheckpoint).(*ethpb.Checkpoint)

if err := s.resumeForkChoice(ctx, justifiedCheckpoint, finalizedCheckpoint); err != nil {
log.Fatalf("Could not resume fork choice: %v", err)
}
s.resumeForkChoice(justifiedCheckpoint, finalizedCheckpoint)
}

if finalizedCheckpoint.Epoch > 1 {
Expand Down Expand Up @@ -476,33 +474,7 @@ func (s *Service) pruneGarbageState(ctx context.Context, slot uint64) error {

// This is called when a client starts from non-genesis slot. This passes last justified and finalized
// information to fork choice service to initializes fork choice store.
func (s *Service) resumeForkChoice(
ctx context.Context,
justifiedCheckpoint *ethpb.Checkpoint,
finalizedCheckpoint *ethpb.Checkpoint) error {
func (s *Service) resumeForkChoice(justifiedCheckpoint *ethpb.Checkpoint, finalizedCheckpoint *ethpb.Checkpoint) {
store := protoarray.New(justifiedCheckpoint.Epoch, finalizedCheckpoint.Epoch, bytesutil.ToBytes32(finalizedCheckpoint.Root))
s.forkChoiceStore = store

headBlock, err := s.beaconDB.HeadBlock(ctx)
if err != nil {
return err
}
if headBlock == nil || headBlock.Block == nil {
return errors.New("head block is nil")
}
headBlockRoot, err := ssz.HashTreeRoot(headBlock.Block)
if err != nil {
return err
}
if err := s.forkChoiceStore.ProcessBlock(
ctx,
headBlock.Block.Slot,
headBlockRoot,
bytesutil.ToBytes32(headBlock.Block.ParentRoot),
finalizedCheckpoint.Epoch,
justifiedCheckpoint.Epoch); err != nil {
return err
}

return nil
}