Skip to content

Commit 8d1c165

Browse files
domiweiGiulio2002
andauthored
Caplin: Simplified peer refreshing (#18123) (#18152)
We actually never use metadata, so let's do one less network call Co-authored-by: Giulio rebuffo <[email protected]>
1 parent 4b6f962 commit 8d1c165

File tree

3 files changed

+27
-45
lines changed

3 files changed

+27
-45
lines changed

cl/beacon/handler/node.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ func (a *ApiHandler) GetEthV1NodePeersInfos(w http.ResponseWriter, r *http.Reque
103103
}
104104
peers := make([]peer, 0, len(ret.Peers))
105105
for i := range ret.Peers {
106+
if ret.Peers[i].Enr == "" {
107+
continue
108+
}
106109
peers = append(peers, peer{
107110
PeerID: ret.Peers[i].Pid,
108111
State: ret.Peers[i].State,
@@ -128,6 +131,9 @@ func (a *ApiHandler) GetEthV1NodePeerInfos(w http.ResponseWriter, r *http.Reques
128131
// find the peer with matching enr
129132
for _, p := range ret.Peers {
130133
if p.Pid == pid {
134+
if p.Enr == "" {
135+
continue
136+
}
131137
return newBeaconResponse(peer{
132138
PeerID: p.Pid,
133139
State: p.State,

cl/rpc/peer_selection.go

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ type peerDataKey struct {
6767
}
6868

6969
type peerData struct {
70-
pid string
71-
mask map[uint64]bool
72-
earliestAvailableSlot uint64
70+
pid string
71+
mask map[uint64]bool
7372
}
7473

7574
func (c *columnDataPeers) refreshPeers(ctx context.Context) {
@@ -106,46 +105,26 @@ func (c *columnDataPeers) refreshPeers(ctx context.Context) {
106105
log.Debug("[peerSelector] empty cgc", "peer", pid)
107106
continue
108107
}
109-
// request status
110-
buf := new(bytes.Buffer)
111-
forkDigest, err := c.ethClock.CurrentForkDigest()
112-
if err != nil {
113-
log.Debug("[peerSelector] failed to get fork digest", "peer", pid, "err", err)
114-
continue
115-
}
116-
myStatus := &cltypes.Status{
117-
ForkDigest: forkDigest,
118-
FinalizedRoot: c.beaconState.FinalizedCheckpoint().Root,
119-
FinalizedEpoch: c.beaconState.FinalizedCheckpoint().Epoch,
120-
HeadRoot: c.beaconState.FinalizedCheckpoint().Root,
121-
HeadSlot: c.beaconState.FinalizedCheckpoint().Epoch * c.beaconConfig.SlotsPerEpoch,
122-
EarliestAvailableSlot: new(uint64),
123-
}
124-
if err := ssz_snappy.EncodeAndWrite(buf, myStatus); err != nil {
125-
log.Debug("[peerSelector] failed to encode my status", "peer", pid, "err", err)
126-
continue
127-
}
128-
status := &cltypes.Status{}
129-
if err := c.simpleReuqest(ctx, pid, communication.StatusProtocolV2, status, buf.Bytes()); err != nil {
130-
log.Debug("[peerSelector] failed to request peer status", "peer", pid, "err", err)
131-
continue
132-
}
133-
if status.EarliestAvailableSlot == nil {
134-
log.Debug("[peerSelector] empty earliest available slot", "peer", pid)
135-
continue
108+
custodyIndices := map[cltypes.CustodyIndex]bool{}
109+
if peer.EnodeId == "" {
110+
// fill all custody indices
111+
for i := cltypes.CustodyIndex(0); i < c.beaconConfig.NumberOfCustodyGroups; i++ {
112+
custodyIndices[i] = true
113+
}
114+
} else {
115+
// get custody indices
116+
enodeId := enode.HexID(peer.EnodeId)
117+
custodyIndices, err = peerdasutils.GetCustodyColumns(enodeId, *metadata.CustodyGroupCount)
118+
if err != nil {
119+
log.Debug("[peerSelector] failed to get custody indices", "peer", pid, "err", err)
120+
continue
121+
}
136122
}
137123

138-
// get custody indices
139-
enodeId := enode.HexID(peer.EnodeId)
140-
custodyIndices, err := peerdasutils.GetCustodyColumns(enodeId, *metadata.CustodyGroupCount)
141-
if err != nil {
142-
log.Debug("[peerSelector] failed to get custody indices", "peer", pid, "err", err)
143-
continue
144-
}
145-
data := &peerData{pid: pid, mask: custodyIndices, earliestAvailableSlot: *status.EarliestAvailableSlot}
124+
data := &peerData{pid: pid, mask: custodyIndices}
146125
c.peerMetaCache.Add(peerKey, data)
147126
newPeers = append(newPeers, *data)
148-
log.Debug("[peerSelector] added peer", "peer", pid, "custodies", len(custodyIndices), "earliestAvailableSlot", *status.EarliestAvailableSlot)
127+
log.Debug("[peerSelector] added peer", "peer", pid, "custodies", len(custodyIndices))
149128
}
150129
c.peersMutex.Lock()
151130
c.peersQueue = newPeers

cl/sentinel/sentinel.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,23 +521,20 @@ func (s *Sentinel) GetPeersInfos() *sentinelproto.PeersInfoResponse {
521521
entry.State = "disconnected"
522522
}
523523
conns := s.host.Network().ConnsToPeer(p)
524-
if len(conns) == 0 {
525-
continue
526-
}
527-
if conns[0].Stat().Direction == network.DirOutbound {
524+
if len(conns) == 0 || conns[0].Stat().Direction == network.DirOutbound {
528525
entry.Direction = "outbound"
529526
} else {
530527
entry.Direction = "inbound"
531528
}
532529
if enr, ok := s.pidToEnr.Load(p); ok {
533530
entry.Enr = enr.(string)
534531
} else {
535-
continue
532+
entry.Enr = ""
536533
}
537534
if enodeId, ok := s.pidToEnodeId.Load(p); ok {
538535
entry.EnodeId = enodeId.(enode.ID).String()
539536
} else {
540-
continue
537+
entry.EnodeId = ""
541538
}
542539
agent, err := s.host.Peerstore().Get(p, "AgentVersion")
543540
if err == nil {

0 commit comments

Comments
 (0)