Skip to content

Commit

Permalink
fix outdated ENRs, due to outdated peer infos
Browse files Browse the repository at this point in the history
  • Loading branch information
skylenet committed Sep 25, 2024
1 parent 2cadefe commit 09d28bf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 29 deletions.
57 changes: 36 additions & 21 deletions handlers/clients_cl.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ func buildCLClientsPageData() (*models.ClientsCLPageData, time.Duration) {
for _, client := range services.GlobalBeaconService.GetConsensusClients() {
lastHeadSlot, lastHeadRoot := client.GetLastHead()

id := client.GetNodeIdentity()
if id == nil {
continue
}

// Add client to global nodes map
if _, ok := pageData.Nodes[id.PeerID]; !ok {
pageData.Nodes[id.PeerID] = &models.ClientCLNode{
PeerID: id.PeerID,
Alias: client.GetName(),
Type: "internal",
ENR: id.Enr,
}
}

peers := client.GetNodePeers()
resPeers := []*models.ClientCLPageDataClientPeers{}

Expand Down Expand Up @@ -208,7 +223,21 @@ func buildCLClientsPageData() (*models.ClientsCLPageData, time.Duration) {
} else {
if node.ENR == "" && peer.Enr != "" {
node.ENR = peer.Enr
} else if node.ENR != "" && peer.Enr != "" {
// Need to compare `seq` field from ENRs and only store highest
nodeENR, errA := utils.DecodeENR(node.ENR)
if errA != nil {
logrus.WithFields(logrus.Fields{"node": node.Alias, "enr": node.ENR}).Error("failed to decode enr of a node ", errA)
}
peerENR, errB := utils.DecodeENR(peer.Enr)
if errB != nil {
logrus.WithFields(logrus.Fields{"node": node.Alias, "peer": peer.PeerID, "enr": peer.Enr}).Error("failed to decode enr of a peer ", errB)
}
if errA != nil && errB != nil && peerENR.Seq() > nodeENR.Seq() {
node.ENR = peer.Enr // Store the peer's ENR
}
}

}

// Increase peer direction counter
Expand All @@ -227,11 +256,6 @@ func buildCLClientsPageData() (*models.ClientsCLPageData, time.Duration) {
return resPeers[i].Type > resPeers[j].Type
})

id := client.GetNodeIdentity()
if id == nil {
continue
}

resClient := &models.ClientsCLPageDataClient{
Index: int(client.GetIndex()) + 1,
Name: client.GetName(),
Expand All @@ -250,21 +274,6 @@ func buildCLClientsPageData() (*models.ClientsCLPageData, time.Duration) {
LastRefresh: client.GetLastEventTime(),
}

// Add client to global nodes map
node, ok := pageData.Nodes[id.PeerID]
if !ok {
pageData.Nodes[id.PeerID] = &models.ClientCLNode{
PeerID: id.PeerID,
Alias: client.GetName(),
Type: "internal",
ENR: id.Enr,
}
} else {
if node.ENR == "" && id.Enr != "" {
node.ENR = id.Enr
}
}

lastError := client.GetLastClientError()
if lastError != nil {
resClient.LastError = lastError.Error()
Expand Down Expand Up @@ -330,8 +339,14 @@ func buildCLClientsPageData() (*models.ClientsCLPageData, time.Duration) {
custodySubnetCount := pageData.PeerDASInfos.CustodyRequirement

// TODO: This is a temporary hack to simulate different custody subnet counts
//if rand.IntN(20-1)+1 == 5 {
//if rand.IntN(30-1)+1 == 1 {
// custodySubnetCount = 128
//} else if rand.IntN(5-1)+1 == 4 {
// custodySubnetCount = 64
//} else if rand.IntN(5-1)+1 == 3 {
// custodySubnetCount = 32
//} else if rand.IntN(5-1)+1 == 2 {
// custodySubnetCount = 8
//}

if cscHex, ok := v.ENRKeyValues["csc"]; ok {
Expand Down
24 changes: 16 additions & 8 deletions templates/clients/clients_cl.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,19 @@ <h5 class="modal-title" id="peerDasWarningsModal">👀 PeerDAS: Some problems we
<tr>
<td>Custody columns</td>
<td>
<code>{{ (index $root.Nodes $client.PeerID).PeerDAS.CustodyColumns }}</code>
<i class="fa fa-copy text-muted p-1" role="button" data-bs-placement="right" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ $client.PeerDAS.CustodyColumns }}" ></i>
<div style="word-break: break-all; text-wrap: pretty;">
<code>{{ (index $root.Nodes $client.PeerID).PeerDAS.CustodyColumns }}</code>
<i class="fa fa-copy text-muted p-1" role="button" data-bs-placement="right" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ $client.PeerDAS.CustodyColumns }}" ></i>
</div>
</td>
</tr>
<tr>
<td>Custody subnets</td>
<td>
<code>{{ (index $root.Nodes $client.PeerID).PeerDAS.CustodyColumnSubnets }}</code>
<i class="fa fa-copy text-muted p-1" role="button" data-bs-placement="right" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ $client.PeerDAS.CustodyColumnSubnets }}" ></i>
<div style="word-break: break-all; text-wrap: pretty;">
<code>{{ (index $root.Nodes $client.PeerID).PeerDAS.CustodyColumnSubnets }}</code>
<i class="fa fa-copy text-muted p-1" role="button" data-bs-placement="right" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ $client.PeerDAS.CustodyColumnSubnets }}" ></i>
</div>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -453,15 +457,19 @@ <h5 class="modal-title" id="peerDasWarningsModal">👀 PeerDAS: Some problems we
<tr>
<td>Custody columns</td>
<td>
<code>{{ (index $root.Nodes $peer.ID).PeerDAS.CustodyColumns }}</code>
<i class="fa fa-copy text-muted p-1" role="button" data-bs-placement="right" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ $client.PeerDAS.CustodyColumns }}" ></i>
<div style="word-break: break-all; text-wrap: pretty;">
<code>{{ (index $root.Nodes $peer.ID).PeerDAS.CustodyColumns }}</code>
<i class="fa fa-copy text-muted p-1" role="button" data-bs-placement="right" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ $client.PeerDAS.CustodyColumns }}" ></i>
</div>
</td>
</tr>
<tr>
<td>Custody subnets</td>
<td>
<code>{{ (index $root.Nodes $peer.ID).PeerDAS.CustodyColumnSubnets }}</code>
<i class="fa fa-copy text-muted p-1" role="button" data-bs-placement="right" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ $client.PeerDAS.CustodyColumnSubnets }}" ></i>
<div style="word-break: break-all; text-wrap: pretty;">
<code>{{ (index $root.Nodes $peer.ID).PeerDAS.CustodyColumnSubnets }}</code>
<i class="fa fa-copy text-muted p-1" role="button" data-bs-placement="right" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ $client.PeerDAS.CustodyColumnSubnets }}" ></i>
</div>
</td>
</tr>
</tbody>
Expand Down

0 comments on commit 09d28bf

Please sign in to comment.