From cc9811ec597e96dde71490cac7df107d25267bfb Mon Sep 17 00:00:00 2001 From: Hussam Date: Mon, 2 Oct 2023 17:45:26 -0500 Subject: [PATCH] Only print headers if they haven't been printed in the last minute --- core/worker.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/worker.go b/core/worker.go index 15f323675f..49e39d7d57 100644 --- a/core/worker.go +++ b/core/worker.go @@ -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 ( @@ -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. @@ -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) @@ -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() }