Skip to content

Commit

Permalink
Merge branch 'main' into alert
Browse files Browse the repository at this point in the history
  • Loading branch information
ping-ke authored Nov 1, 2024
2 parents 7d703de + a46032a commit 810f276
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/priv-dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -85,6 +86,11 @@ func (d *dashboard) ReportStateHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fmt.Sprintf(`{"status":"error", "err message":"%s"}`, err.Error())))
return
}
if err = d.checkState(&state); err != nil {
log.Warn("check node state failed", "error", err.Error())
w.Write([]byte(fmt.Sprintf(`{"status":"error", "err message":"%s"}`, err.Error())))
return
}

log.Info("Get state from peer", "peer id", state.Id, "state", string(body))
d.lock.Lock()
Expand All @@ -99,9 +105,26 @@ func (d *dashboard) ReportStateHandler(w http.ResponseWriter, r *http.Request) {
d.m.SetSubmissionState(state.Id, state.Version, state.Address, shard.ShardId, shard.Miner, submission.Succeeded,
submission.Failed, submission.Dropped, submission.LastSucceededTime)
}

w.Write([]byte(`{"status":"ok"}`))
}

func (d *dashboard) checkState(state *node.NodeState) error {
if state == nil {
return errors.New("state is nil")
}
if len(state.Shards) == 0 {
return fmt.Errorf("no shard exist in the node state %s", state.Id)
}
for _, shard := range state.Shards {
if shard.SyncState == nil || shard.MiningState == nil || shard.SubmissionState == nil {
return fmt.Errorf("invalid shard state in the node state %s", state.Id)
}
}

return nil
}

func (d *dashboard) Report() {
var (
minerOfShards = make(map[uint64]map[common.Address]struct{})
Expand Down

0 comments on commit 810f276

Please sign in to comment.