v1.27.0-a #10
@ -92,54 +92,43 @@ func (d *debug) chainStateSSE(w http.ResponseWriter, r *http.Request) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(rpcInfos))
|
wg.Add(len(rpcInfos))
|
||||||
for addr, token := range apiInfos {
|
for addr, token := range apiInfos {
|
||||||
|
addr := addr
|
||||||
ai := cliutil.APIInfo{
|
ai := cliutil.APIInfo{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Token: token,
|
Token: token,
|
||||||
}
|
}
|
||||||
|
|
||||||
var clayers []string
|
|
||||||
for layer, a := range confNameToAddr {
|
|
||||||
if a == addr {
|
|
||||||
clayers = append(clayers, layer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
da, err := ai.DialArgs("v1")
|
|
||||||
if err != nil {
|
|
||||||
log.Warnw("DialArgs", "error", err)
|
|
||||||
|
|
||||||
infosLk.Lock()
|
|
||||||
infos[addr] = rpcInfo{
|
|
||||||
Address: ai.Addr,
|
|
||||||
Reachable: false,
|
|
||||||
CLayers: clayers,
|
|
||||||
}
|
|
||||||
infosLk.Unlock()
|
|
||||||
|
|
||||||
wg.Done()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
ah := ai.AuthHeader()
|
|
||||||
|
|
||||||
v1api, closer, err := client.NewFullNodeRPCV1(ctx, da, ah)
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("Not able to establish connection to node with addr: %s", addr)
|
|
||||||
|
|
||||||
infosLk.Lock()
|
|
||||||
infos[addr] = rpcInfo{
|
|
||||||
Address: ai.Addr,
|
|
||||||
Reachable: false,
|
|
||||||
CLayers: clayers,
|
|
||||||
}
|
|
||||||
infosLk.Unlock()
|
|
||||||
|
|
||||||
wg.Done()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
go func(info string) {
|
go func(info string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
var clayers []string
|
||||||
|
for layer, a := range confNameToAddr {
|
||||||
|
if a == addr {
|
||||||
|
clayers = append(clayers, layer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
myinfo := rpcInfo{
|
||||||
|
Address: ai.Addr,
|
||||||
|
Reachable: false,
|
||||||
|
CLayers: clayers,
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
infosLk.Lock()
|
||||||
|
infos[ai.Addr] = myinfo
|
||||||
|
infosLk.Unlock()
|
||||||
|
}()
|
||||||
|
da, err := ai.DialArgs("v1")
|
||||||
|
if err != nil {
|
||||||
|
log.Warnw("DialArgs", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ah := ai.AuthHeader()
|
||||||
|
|
||||||
|
v1api, closer, err := client.NewFullNodeRPCV1(ctx, da, ah)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("Not able to establish connection to node with addr: %s", addr)
|
||||||
|
return
|
||||||
|
}
|
||||||
defer closer()
|
defer closer()
|
||||||
|
|
||||||
ver, err := v1api.Version(ctx)
|
ver, err := v1api.Version(ctx)
|
||||||
@ -164,26 +153,21 @@ func (d *debug) chainStateSSE(w http.ResponseWriter, r *http.Request) {
|
|||||||
syncState = fmt.Sprintf("behind (%s behind)", time.Since(time.Unix(int64(head.MinTimestamp()), 0)).Truncate(time.Second))
|
syncState = fmt.Sprintf("behind (%s behind)", time.Since(time.Unix(int64(head.MinTimestamp()), 0)).Truncate(time.Second))
|
||||||
}
|
}
|
||||||
|
|
||||||
var out rpcInfo
|
myinfo = rpcInfo{
|
||||||
out.Address = ai.Addr
|
Address: ai.Addr,
|
||||||
out.CLayers = clayers
|
CLayers: clayers,
|
||||||
out.Reachable = true
|
Reachable: true,
|
||||||
out.Version = ver.Version
|
Version: ver.Version,
|
||||||
out.SyncState = syncState
|
SyncState: syncState,
|
||||||
|
}
|
||||||
infosLk.Lock()
|
|
||||||
infos[info] = out
|
|
||||||
infosLk.Unlock()
|
|
||||||
|
|
||||||
}(addr)
|
}(addr)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
infoList := make([]rpcInfo, 0, len(infos))
|
var infoList []rpcInfo
|
||||||
for _, info := range infos {
|
for _, i := range infos {
|
||||||
infoList = append(infoList, info)
|
infoList = append(infoList, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(infoList, func(i, j int) bool {
|
sort.Slice(infoList, func(i, j int) bool {
|
||||||
return infoList[i].Address < infoList[j].Address
|
return infoList[i].Address < infoList[j].Address
|
||||||
})
|
})
|
||||||
@ -200,6 +184,12 @@ func (d *debug) chainStateSSE(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Duration(build.BlockDelaySecs) * time.Second)
|
time.Sleep(time.Duration(build.BlockDelaySecs) * time.Second)
|
||||||
|
|
||||||
|
select { // stop running if there is reader.
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user