Revert initsync revert (#12431)

* Revert "Revert "BeaconBlocksByRange and BlobSidecarsByRange consistency (#123… (#12426)"

This reverts commit ddc1e48e05.

* fix metrics bug, add batch.next tests

---------

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
This commit is contained in:
kasey
2023-05-19 11:59:13 -05:00
committed by GitHub
parent b84dd40ba9
commit 385a317902
14 changed files with 771 additions and 449 deletions

View File

@@ -248,7 +248,7 @@ func (s *Service) sendBatchRootRequest(ctx context.Context, roots [][32]byte, ra
if len(bestPeers) == 0 {
return nil
}
roots = s.dedupRoots(roots)
roots = dedupRoots(roots)
// Randomly choose a peer to query from our best peers. If that peer cannot return
// all the requested blocks, we randomly select another peer.
pid := bestPeers[randGen.Int()%len(bestPeers)]
@@ -456,3 +456,16 @@ func slotToCacheKey(s primitives.Slot) string {
b := bytesutil.SlotToBytesBigEndian(s)
return string(b)
}
func dedupRoots(roots [][32]byte) [][32]byte {
newRoots := make([][32]byte, 0, len(roots))
rootMap := make(map[[32]byte]bool, len(roots))
for i, r := range roots {
if rootMap[r] {
continue
}
rootMap[r] = true
newRoots = append(newRoots, roots[i])
}
return newRoots
}