github.com/sunriselayer/sunrise-da@v0.13.1-sr3/das/stats.go (about) 1 package das 2 3 // SamplingStats collects information about the DASer process. 4 type SamplingStats struct { 5 // all headers before SampledChainHead were successfully sampled 6 SampledChainHead uint64 `json:"head_of_sampled_chain"` 7 // all headers before CatchupHead were submitted to sampling workers. They could be either already 8 // sampled, failed or still in progress. For in progress items check Workers stat. 9 CatchupHead uint64 `json:"head_of_catchup"` 10 // NetworkHead is the height of the most recent header in the network 11 NetworkHead uint64 `json:"network_head_height"` 12 // Failed contains all skipped headers heights with corresponding try count 13 Failed map[uint64]int `json:"failed,omitempty"` 14 // Workers has information about each currently running worker stats 15 Workers []WorkerStats `json:"workers,omitempty"` 16 // Concurrency amount of currently running parallel workers 17 Concurrency int `json:"concurrency"` 18 // CatchUpDone indicates whether all known headers are sampled 19 CatchUpDone bool `json:"catch_up_done"` 20 // IsRunning tracks whether the DASer service is running 21 IsRunning bool `json:"is_running"` 22 } 23 24 type WorkerStats struct { 25 JobType jobType `json:"job_type"` 26 Curr uint64 `json:"current"` 27 From uint64 `json:"from"` 28 To uint64 `json:"to"` 29 30 ErrMsg string `json:"error,omitempty"` 31 } 32 33 // totalSampled returns the total amount of sampled headers 34 func (s SamplingStats) totalSampled() uint64 { 35 var inProgress uint64 36 for _, w := range s.Workers { 37 // don't count recent jobs, since heights they are working on are after catchup head 38 if w.JobType != recentJob { 39 inProgress += w.To - w.Curr + 1 40 } 41 } 42 return s.CatchupHead - inProgress - uint64(len(s.Failed)) 43 } 44 45 // workersByJobType returns a map of job types to the number of workers assigned to those types. 46 func (s SamplingStats) workersByJobType() map[jobType]int64 { 47 workers := make(map[jobType]int64) 48 for _, w := range s.Workers { 49 workers[w.JobType]++ 50 } 51 return workers 52 }