Add a helper for max request block (#13173)

* Add a helper for max request block

* Add test

* Use deneb fork epoch from config

* Fix comment
This commit is contained in:
terence
2023-11-13 21:50:51 -08:00
committed by GitHub
parent 28aa11c976
commit ac06362baf
9 changed files with 59 additions and 7 deletions

View File

@@ -299,8 +299,10 @@ func (s *Service) sendBatchRootRequest(ctx context.Context, roots [][32]byte, ra
pid := bestPeers[randGen.Int()%len(bestPeers)]
for i := 0; i < numOfTries; i++ {
req := p2ptypes.BeaconBlockByRootsReq(roots)
if len(roots) > int(params.BeaconNetworkConfig().MaxRequestBlocks) {
req = roots[:params.BeaconNetworkConfig().MaxRequestBlocks]
currentEpoch := slots.ToEpoch(s.cfg.clock.CurrentSlot())
maxReqBlock := params.MaxRequestBlock(currentEpoch)
if uint64(len(roots)) > maxReqBlock {
req = roots[:maxReqBlock]
}
if err := s.sendRecentBeaconBlocksRequest(ctx, &req, pid); err != nil {
tracing.AnnotateError(span, err)