Skip to content

Commit

Permalink
Upon start up, don't insert head to proto array node DAG as index 0 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Feb 5, 2020
1 parent 68b6a7c commit 8ad174f
Showing 1 changed file with 2 additions and 30 deletions.
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
}

0 comments on commit 8ad174f

Please sign in to comment.