Skip to content

Commit

Permalink
Better parent block request (#4572)
Browse files Browse the repository at this point in the history
* Use a good peer instead of a random one, if we know about it
* Exit init sync if there is an issue
* Merge refs/heads/master into better-parent-block-processing
* Merge refs/heads/master into better-parent-block-processing
* Merge refs/heads/master into better-parent-block-processing
* Merge refs/heads/master into better-parent-block-processing
* Update pending_blocks_queue.go
  • Loading branch information
prestonvanloon authored and prylabs-bulldozer[bot] committed Jan 17, 2020
1 parent 3d3dccb commit ccfc650
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion beacon-chain/sync/initial-sync/round_robin.go
Expand Up @@ -253,7 +253,8 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
for _, blk := range resp {
s.logSyncStatus(genesis, blk.Block, []peer.ID{best}, counter)
if err := s.chain.ReceiveBlockNoPubsubForkchoice(ctx, blk); err != nil {
return err
log.WithError(err).Error("Failed to process block, exiting init sync")
return nil
}
}
if len(resp) == 0 {
Expand Down
13 changes: 12 additions & 1 deletion beacon-chain/sync/pending_blocks_queue.go
Expand Up @@ -69,7 +69,18 @@ func (r *Service) processPendingBlocks(ctx context.Context) error {
"parentRoot": hex.EncodeToString(b.Block.ParentRoot),
}).Info("Requesting parent block")
req := [][32]byte{bytesutil.ToBytes32(b.Block.ParentRoot)}
if err := r.sendRecentBeaconBlocksRequest(ctx, req, pids[rand.Int()%len(pids)]); err != nil {

// Start with a random peer to query, but choose the first peer in our unsorted list that claims to
// have a head slot newer than the block slot we are requesting.
pid := pids[rand.Int()%len(pids)]
for _, p := range pids {
if cs, _ := r.p2p.Peers().ChainState(p); cs != nil && cs.HeadSlot >= uint64(s) {
pid = p
break
}
}

if err := r.sendRecentBeaconBlocksRequest(ctx, req, pid); err != nil {
traceutil.AnnotateError(span, err)
log.Errorf("Could not send recent block request: %v", err)
}
Expand Down

0 comments on commit ccfc650

Please sign in to comment.