Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove statsqueue length variable and fix trusted flag #26

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ var (
}
TrustedNodeFlag = cli.BoolFlag{
Name: "trustednode",
Usage: "Truted node boolean flag for use by team",
Usage: "Truted node boolean flag for trusted nodes",
}
FakePoWFlag = cli.BoolFlag{
Name: "fakepow",
Expand Down
30 changes: 11 additions & 19 deletions quaistats/quaistats.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ type Service struct {
// that the operations are atomic. As a result, it's safe to use across multiple goroutines
// without external synchronization.
type StatsQueue struct {
data []interface{}
length int
mutex sync.Mutex
data []interface{}
mutex sync.Mutex
}

func NewStatsQueue() *StatsQueue {
Expand All @@ -168,20 +167,18 @@ func (q *StatsQueue) Enqueue(item interface{}) {
defer q.mutex.Unlock()

q.data = append(q.data, item)
q.length++
}

func (q *StatsQueue) Dequeue() interface{} {
q.mutex.Lock()
defer q.mutex.Unlock()

if q.length == 0 {
if len(q.data) == 0 {
return nil
}

item := q.data[0]
q.data = q.data[1:]
q.length--
return item
}

Expand All @@ -190,14 +187,13 @@ func (q *StatsQueue) EnqueueFront(item interface{}) {
defer q.mutex.Unlock()

q.data = append([]interface{}{item}, q.data...)
q.length++
}

func (q *StatsQueue) Size() int {
q.mutex.Lock()
defer q.mutex.Unlock()

return q.length
return len(q.data)
}

// parseEthstatsURL parses the netstats connection url.
Expand Down Expand Up @@ -655,12 +651,12 @@ func (s *Service) reportNodeStats(url string, mod int, authJwt string) error {
}

func (s *Service) sendTransactionStats(url string, authJwt string) error {
if s.transactionStatsQueue.length == 0 {
if len(s.transactionStatsQueue.data) == 0 {
return nil
}
statsBatch := make([]*blockTransactionStats, 0, c_queueBatchSize)

for i := 0; i < int(c_queueBatchSize) && s.transactionStatsQueue.length > 0; i++ {
for i := 0; i < int(c_queueBatchSize) && len(s.transactionStatsQueue.data) > 0; i++ {
stat := s.transactionStatsQueue.Dequeue()
if stat == nil {
break
Expand Down Expand Up @@ -688,7 +684,7 @@ func (s *Service) sendTransactionStats(url string, authJwt string) error {
}

func (s *Service) sendDetailStats(url string, authJwt string) error {
if s.detailStatsQueue.length == 0 {
if len(s.transactionStatsQueue.data) == 0 {
return nil
}
statsBatch := make([]*blockDetailStats, 0, c_queueBatchSize)
Expand Down Expand Up @@ -721,7 +717,7 @@ func (s *Service) sendDetailStats(url string, authJwt string) error {
}

func (s *Service) sendAppendTimeStats(url string, authJwt string) error {
if s.appendTimeStatsQueue.length == 0 {
if len(s.transactionStatsQueue.data) == 0 {
return nil
}

Expand Down Expand Up @@ -1180,18 +1176,14 @@ func (s *Service) assembleBlockDetailStats(block *types.Block) *blockDetailStats
return nil
}
header := block.Header()
location := header.NumberArray()
primeHeight := location[0]
regionHeight := location[1]
zoneHeight := location[2]
difficulty := header.Difficulty().String()

// Assemble and return the block stats
return &blockDetailStats{
Timestamp: new(big.Int).SetUint64(header.Time()),
ZoneHeight: zoneHeight.Uint64(),
RegionHeight: regionHeight.Uint64(),
PrimeHeight: primeHeight.Uint64(),
ZoneHeight: header.NumberArray()[2].Uint64(),
RegionHeight: header.NumberArray()[1].Uint64(),
PrimeHeight: header.NumberArray()[0].Uint64(),
Chain: common.NodeLocation.Name(),
Entropy: common.BigBitsToBits(s.backend.TotalLogS(block.Header())).String(),
Difficulty: difficulty,
Expand Down
Loading