mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Request missing blobs while processing pending queue (#13015)
* Request missing blobs while processing pending queue * Fix build * Lower complexity * Fix conflict * Clean up per James's comment --------- Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/libp2p/go-libp2p/core"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/v4/async"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/blockchain"
|
||||
@@ -184,6 +185,7 @@ func (s *Service) hasPeer() bool {
|
||||
}
|
||||
|
||||
// processAndBroadcastBlock validates, processes, and broadcasts a block.
|
||||
// part of the function is to request missing blobs from peers if the block contains kzg commitments.
|
||||
func (s *Service) processAndBroadcastBlock(ctx context.Context, b interfaces.ReadOnlySignedBeaconBlock, blkRoot [32]byte) error {
|
||||
if err := s.validateBeaconBlock(ctx, b, blkRoot); err != nil {
|
||||
if !errors.Is(ErrOptimisticParent, err) {
|
||||
@@ -192,6 +194,14 @@ func (s *Service) processAndBroadcastBlock(ctx context.Context, b interfaces.Rea
|
||||
}
|
||||
}
|
||||
|
||||
peers := s.getBestPeers()
|
||||
peerCount := len(peers)
|
||||
if peerCount > 0 {
|
||||
if err := s.requestPendingBlobs(ctx, b.Block(), blkRoot, peers[rand.NewGenerator().Int()%peerCount]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.cfg.chain.ReceiveBlock(ctx, b, blkRoot); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -219,6 +229,12 @@ func (s *Service) handleBlockProcessingError(ctx context.Context, err error, b i
|
||||
log.WithError(err).WithField("slot", b.Block().Slot()).Debug("Could not process block")
|
||||
}
|
||||
|
||||
// getBestPeers returns the list of best peers based on finalized checkpoint epoch.
|
||||
func (s *Service) getBestPeers() []core.PeerID {
|
||||
_, bestPeers := s.cfg.p2p.Peers().BestFinalized(maxPeerRequest, s.cfg.chain.FinalizedCheckpt().Epoch)
|
||||
return bestPeers
|
||||
}
|
||||
|
||||
func (s *Service) checkIfBlockIsBad(
|
||||
ctx context.Context,
|
||||
span *trace.Span,
|
||||
@@ -265,8 +281,7 @@ func (s *Service) sendBatchRootRequest(ctx context.Context, roots [][32]byte, ra
|
||||
if len(roots) == 0 {
|
||||
return nil
|
||||
}
|
||||
cp := s.cfg.chain.FinalizedCheckpt()
|
||||
_, bestPeers := s.cfg.p2p.Peers().BestFinalized(maxPeerRequest, cp.Epoch)
|
||||
bestPeers := s.getBestPeers()
|
||||
if len(bestPeers) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user