Skip to content

Commit

Permalink
Only print headers if they haven't been printed in the last minute
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih authored and gameofpointers committed Oct 3, 2023
1 parent 41b837f commit 2b508cf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/dominant-strategies/go-quai/params"
"github.com/dominant-strategies/go-quai/trie"
lru "github.com/hashicorp/golang-lru"
expireLru "github.com/hnlq715/golang-lru"
)

const (
Expand Down Expand Up @@ -209,6 +210,8 @@ type worker struct {
snapshotMu sync.RWMutex // The lock used to protect the snapshots below
snapshotBlock *types.Block

headerPrints *expireLru.Cache

// atomic status counters
running int32 // The indicator whether the consensus engine is running or not.
newTxs int32 // New arrival transaction count since last sealing work submitting.
Expand Down Expand Up @@ -284,6 +287,9 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, db ethdb.Databas
recommit = minRecommitInterval
}

headerPrints, _ := expireLru.NewWithExpire(1, 60*time.Second)
worker.headerPrints = headerPrints

nodeCtx := common.NodeLocation.Context()
if headerchain.ProcessingState() && nodeCtx == common.ZONE_CTX {
worker.chainHeadSub = worker.hc.SubscribeChainHeadEvent(worker.chainHeadCh)
Expand Down Expand Up @@ -1029,5 +1035,10 @@ func totalFees(block *types.Block, receipts []*types.Receipt) *big.Float {
}

func (w *worker) CurrentInfo(header *types.Header) bool {
if w.headerPrints.Contains(header) {
return false
}

w.headerPrints.Add(header, nil)
return header.NumberU64()+c_startingPrintLimit > w.hc.CurrentHeader().NumberU64()
}

0 comments on commit 2b508cf

Please sign in to comment.