Skip to content

Commit

Permalink
Start a stats print on 1m timer. Print len of appendQueue on Info, co…
Browse files Browse the repository at this point in the history
…ntents on Debug
  • Loading branch information
Djadih committed Sep 21, 2023
1 parent fea9ce1 commit 22cebe4
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"math/big"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -39,6 +40,8 @@ const (
c_appendQueueRetryPriorityThreshold = 5 // If retry counter for a block is less than this number, then its put in the special list that is tried first to be appended
c_appendQueueRemoveThreshold = 10 // Number of blocks behind the block should be from the current header to be eligble for removal from the append queue
c_normalListProcCounter = 5 // Ratio of Number of times the PriorityList is serviced over the NormalList
c_statsPrintPeriod = 60 // Time between stats prints
c_appendQueuePrintSize = 10
)

type blockNumberAndRetryCounter struct {
Expand Down Expand Up @@ -80,6 +83,7 @@ func NewCore(db ethdb.Database, config *Config, isLocalBlock func(block *types.H
c.processingCache = proccesingCache

go c.updateAppendQueue()
go c.startStatsTimer()
return c, nil
}

Expand All @@ -102,7 +106,7 @@ func (c *Core) InsertChain(blocks types.Blocks) (int, error) {
if !c.processingCache.Contains(block.Hash()) {
c.processingCache.Add(block.Hash(), 1)
} else {
log.Info("Already proccessing block:", "Number:", block.Header().NumberArray(), "Hash:", block.Hash())
log.Info("Already processing block:", "Number:", block.Header().NumberArray(), "Hash:", block.Hash())
return idx, errors.New("Already in process of appending this block")
}
newPendingEtxs, _, err := c.sl.Append(block.Header(), types.EmptyHeader(), common.Hash{}, false, nil)
Expand Down Expand Up @@ -139,7 +143,7 @@ func (c *Core) InsertChain(blocks types.Blocks) (int, error) {
log.Info("Append failed.", "hash", block.Hash(), "err", err)
}
if err != nil && strings.Contains(err.Error(), "connection refused") {
log.Error("Append failed because of conenction refused error")
log.Error("Append failed because of connection refused error")
} else {
c.removeFromAppendQueue(block)
}
Expand Down Expand Up @@ -296,6 +300,38 @@ func (c *Core) updateAppendQueue() {
}
}

func (c *Core) startStatsTimer() {
futureTimer := time.NewTicker(c_statsPrintPeriod * time.Second)
defer futureTimer.Stop()
for {
select {
case <-futureTimer.C:
c.printStats()
case <-c.quit:
return
}
}
}

// printStats displays stats on syncing, latestHeight, etc.
func (c *Core) printStats() {
log.Info("Blocks waiting to be appended", "len(appendQueue)", len(c.appendQueue.Keys()))

// Print hashes & heights of all queue entries.
for counter, hash := range c.appendQueue.Keys() {
if counter == c_appendQueuePrintSize {
break
}
if value, exist := c.appendQueue.Peek(hash); exist {
hashNumber := types.HashAndNumber{Hash: hash.(common.Hash), Number: value.(blockNumberAndRetryCounter).number}
log.Lazy(func() string {
return "AppendQueue entry. Number: " + strconv.FormatUint(hashNumber.Number, 10) + ". Hash: " + hashNumber.Hash.String()
}, "debug")
}
}

}

func (c *Core) BadHashExistsInChain() bool {
nodeCtx := common.NodeLocation.Context()
// Lookup the bad hashes list to see if we have it in the database
Expand Down

0 comments on commit 22cebe4

Please sign in to comment.