Skip to content

Commit

Permalink
small fixes for clients page
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 24, 2023
1 parent 53618bf commit 8da9eaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions indexer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func (client *IndexerClient) GetLastHead() (int64, []byte) {
}

func (client *IndexerClient) GetStatus() string {
if !client.isConnected {
return "disconnected"
} else if client.isSynchronizing {
if client.isSynchronizing {
return "synchronizing"
} else if !client.isConnected {
return "disconnected"
} else {
return "ready"
}
Expand Down Expand Up @@ -119,6 +119,19 @@ func (client *IndexerClient) runIndexerClient() error {
return fmt.Errorf("genesis fork version from RPC does not match the genesis fork version explorer configuration")
}

// get latest header
latestHeader, err := client.rpcClient.GetLatestBlockHead()
if err != nil {
return fmt.Errorf("could not get latest header: %v", err)
}
if latestHeader == nil {
return fmt.Errorf("could not find latest header")
}
client.setHeadBlock(latestHeader.Data.Root, uint64(latestHeader.Data.Header.Message.Slot))
if client.indexerCache.finalizedEpoch >= 0 && utils.EpochOfSlot(uint64(latestHeader.Data.Header.Message.Slot)) <= uint64(client.indexerCache.finalizedEpoch) {
return fmt.Errorf("client is far behind - head is before synchronized checkpoint")
}

// check syncronization state
syncStatus, err := client.rpcClient.GetNodeSyncing()
if err != nil {
Expand Down Expand Up @@ -147,19 +160,6 @@ func (client *IndexerClient) runIndexerClient() error {
client.cacheMutex.Unlock()
}

// get latest header
latestHeader, err := client.rpcClient.GetLatestBlockHead()
if err != nil {
return fmt.Errorf("could not get latest header: %v", err)
}
if latestHeader == nil {
return fmt.Errorf("could not find latest header")
}
client.setHeadBlock(latestHeader.Data.Root, uint64(latestHeader.Data.Header.Message.Slot))
if client.indexerCache.finalizedEpoch >= 0 && utils.EpochOfSlot(uint64(latestHeader.Data.Header.Message.Slot)) <= uint64(client.indexerCache.finalizedEpoch) {
return fmt.Errorf("client is far behind - head is before synchronized checkpoint")
}

logger.WithField("client", client.clientName).Debugf("endpoint %v ready: %v ", client.clientName, client.versionStr)
client.retryCounter = 0

Expand Down
4 changes: 2 additions & 2 deletions templates/clients/clients.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ <h1 class="h4 mb-1 mb-md-0"><i class="fas fa-server mx-2"></i>Clients</h1>
<tr>
<th>#</th>
<th>Name</th>
<th>Version</th>
<th>Head Slot</th>
<th>Head Root</th>
<th>Status</th>
<th>Version</th>
</tr>
</thead>
<tbody>
{{ range $i, $client := .Clients }}
<tr>
<td>{{ $client.Index }}</td>
<td>{{ $client.Name }}</td>
<td>{{ $client.Version }}</td>
<td><a href="/slot/{{ $client.HeadSlot }}">{{ formatAddCommas $client.HeadSlot }}</a></td>
<td><a href="/slot/0x{{ printf "%x" $client.HeadRoot }}">0x{{ printf "%x" $client.HeadRoot }}</a></td>
<td>
Expand All @@ -43,6 +42,7 @@ <h1 class="h4 mb-1 mb-md-0"><i class="fas fa-server mx-2"></i>Clients</h1>
<span class="badge rounded-pill text-bg-dark">Unknown</span>
{{ end }}
</td>
<td>{{ $client.Version }}</td>
</tr>
{{ end }}
</tbody>
Expand Down

0 comments on commit 8da9eaf

Please sign in to comment.