Skip to content

Commit

Permalink
Remove Head Root from Beacon Block by Range Request (#5165)
Browse files Browse the repository at this point in the history
* make proto changes
* remove head root
  • Loading branch information
nisdas authored Mar 22, 2020
1 parent 4f83b45 commit ecd4b76
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 206 deletions.
21 changes: 9 additions & 12 deletions beacon-chain/sync/initial-sync-old/round_robin.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
highestFinalizedSlot := helpers.StartSlot(s.highestFinalizedEpoch() + 1)
// Step 1 - Sync to end of finalized epoch.
for s.chain.HeadSlot() < highestFinalizedSlot {
root, finalizedEpoch, peers := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, helpers.SlotToEpoch(s.chain.HeadSlot()))
_, finalizedEpoch, peers := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, helpers.SlotToEpoch(s.chain.HeadSlot()))
if len(peers) == 0 {
log.Warn("No peers; waiting for reconnect")
time.Sleep(refreshTime)
Expand Down Expand Up @@ -124,10 +124,9 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
count = 1
}
req := &p2ppb.BeaconBlocksByRangeRequest{
HeadBlockRoot: root,
StartSlot: start,
Count: count,
Step: step,
StartSlot: start,
Count: count,
Step: step,
}

go func(i int, pid peer.ID) {
Expand Down Expand Up @@ -248,20 +247,19 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
// mitigation. We are already convinced that we are on the correct finalized chain. Any blocks
// we receive there after must build on the finalized chain or be considered invalid during
// fork choice resolution / block processing.
root, _, pids := s.p2p.Peers().BestFinalized(1 /* maxPeers */, s.highestFinalizedEpoch())
_, _, pids := s.p2p.Peers().BestFinalized(1 /* maxPeers */, s.highestFinalizedEpoch())
for len(pids) == 0 {
log.Info("Waiting for a suitable peer before syncing to the head of the chain")
time.Sleep(refreshTime)
root, _, pids = s.p2p.Peers().BestFinalized(1 /* maxPeers */, s.highestFinalizedEpoch())
_, _, pids = s.p2p.Peers().BestFinalized(1 /* maxPeers */, s.highestFinalizedEpoch())
}
best := pids[0]

for head := helpers.SlotsSince(genesis); s.chain.HeadSlot() < head; {
req := &p2ppb.BeaconBlocksByRangeRequest{
HeadBlockRoot: root,
StartSlot: s.chain.HeadSlot() + 1,
Count: mathutil.Min(helpers.SlotsSince(genesis)-s.chain.HeadSlot()+1, 256),
Step: 1,
StartSlot: s.chain.HeadSlot() + 1,
Count: mathutil.Min(helpers.SlotsSince(genesis)-s.chain.HeadSlot()+1, 256),
Step: 1,
}

log.WithField("req", req).WithField("peer", best.Pretty()).Debug(
Expand Down Expand Up @@ -300,7 +298,6 @@ func (s *Service) requestBlocks(ctx context.Context, req *p2ppb.BeaconBlocksByRa
"start": req.StartSlot,
"count": req.Count,
"step": req.Step,
"head": fmt.Sprintf("%#x", req.HeadBlockRoot),
}).Debug("Requesting blocks")
stream, err := s.p2p.Send(ctx, req, pid)
if err != nil {
Expand Down
9 changes: 3 additions & 6 deletions beacon-chain/sync/initial-sync/blocks_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package initialsync
import (
"bytes"
"context"
"fmt"
"io"
"math/rand"
"sort"
Expand Down Expand Up @@ -317,10 +316,9 @@ func (f *blocksFetcher) requestBeaconBlocksByRange(
}

req := &p2ppb.BeaconBlocksByRangeRequest{
HeadBlockRoot: root,
StartSlot: start,
Count: count,
Step: step,
StartSlot: start,
Count: count,
Step: step,
}

resp, respErr := f.requestBlocks(ctx, req, pid)
Expand Down Expand Up @@ -364,7 +362,6 @@ func (f *blocksFetcher) requestBlocks(
"start": req.StartSlot,
"count": req.Count,
"step": req.Step,
"head": fmt.Sprintf("%#x", req.HeadBlockRoot),
}).Debug("Requesting blocks")
stream, err := f.p2p.Send(ctx, req, pid)
if err != nil {
Expand Down
12 changes: 5 additions & 7 deletions beacon-chain/sync/initial-sync/round_robin.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,19 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
// mitigation. We are already convinced that we are on the correct finalized chain. Any blocks
// we receive there after must build on the finalized chain or be considered invalid during
// fork choice resolution / block processing.
root, _, pids := s.p2p.Peers().BestFinalized(1 /* maxPeers */, s.highestFinalizedEpoch())
_, _, pids := s.p2p.Peers().BestFinalized(1 /* maxPeers */, s.highestFinalizedEpoch())
for len(pids) == 0 {
log.Info("Waiting for a suitable peer before syncing to the head of the chain")
time.Sleep(refreshTime)
root, _, pids = s.p2p.Peers().BestFinalized(1 /* maxPeers */, s.highestFinalizedEpoch())
_, _, pids = s.p2p.Peers().BestFinalized(1 /* maxPeers */, s.highestFinalizedEpoch())
}
best := pids[0]

for head := helpers.SlotsSince(genesis); s.chain.HeadSlot() < head; {
req := &p2ppb.BeaconBlocksByRangeRequest{
HeadBlockRoot: root,
StartSlot: s.chain.HeadSlot() + 1,
Count: mathutil.Min(helpers.SlotsSince(genesis)-s.chain.HeadSlot()+1, blockBatchSize),
Step: 1,
StartSlot: s.chain.HeadSlot() + 1,
Count: mathutil.Min(helpers.SlotsSince(genesis)-s.chain.HeadSlot()+1, blockBatchSize),
Step: 1,
}

log.WithField("req", req).WithField("peer", best.Pretty()).Debug(
Expand Down Expand Up @@ -139,7 +138,6 @@ func (s *Service) requestBlocks(ctx context.Context, req *p2ppb.BeaconBlocksByRa
"start": req.StartSlot,
"count": req.Count,
"step": req.Step,
"head": fmt.Sprintf("%#x", req.HeadBlockRoot),
}).Debug("Requesting blocks")
stream, err := s.p2p.Send(ctx, req, pid)
if err != nil {
Expand Down
116 changes: 31 additions & 85 deletions proto/beacon/p2p/v1/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions proto/beacon/p2p/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ message Status {
}

message BeaconBlocksByRangeRequest {
bytes head_block_root = 1 [(gogoproto.moretags) = "ssz-size:\"32\""];
uint64 start_slot = 2;
uint64 count = 3;
uint64 step = 4;
uint64 start_slot = 1;
uint64 count = 2;
uint64 step = 3;
}
Loading

0 comments on commit ecd4b76

Please sign in to comment.