From 7525baeb2903f06d06e7d2c88ff696be7dec38e8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 13 Nov 2020 13:30:03 -0800 Subject: [PATCH 1/2] fix: remove unnecessary (and leaked) ticker --- internal/decision/scoreledger.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/decision/scoreledger.go b/internal/decision/scoreledger.go index 6f7c0f16..b9f1dfb9 100644 --- a/internal/decision/scoreledger.go +++ b/internal/decision/scoreledger.go @@ -102,8 +102,6 @@ func (l *scoreledger) Receipt() *Receipt { // DefaultScoreLedger is used by Engine as the default ScoreLedger. type DefaultScoreLedger struct { - // a sample counting ticker - ticker *time.Ticker // the score func scorePeer ScorePeerFunc // is closed on Close @@ -333,7 +331,6 @@ func (dsl *DefaultScoreLedger) PeerDisconnected(p peer.ID) { func NewDefaultScoreLedger() *DefaultScoreLedger { return &DefaultScoreLedger{ ledgerMap: make(map[peer.ID]*scoreledger), - ticker: time.NewTicker(time.Millisecond * 100), closing: make(chan struct{}), peerSampleInterval: shortTerm, } From ed0f4edf638e1b645c2f979ce62018be202f00f7 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 13 Nov 2020 13:30:39 -0800 Subject: [PATCH 2/2] fix: set the score ledger on start It's possible to start receiving and processing messages before we get around to starting. --- internal/decision/engine.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/decision/engine.go b/internal/decision/engine.go index 28584fb1..62957d61 100644 --- a/internal/decision/engine.go +++ b/internal/decision/engine.go @@ -178,6 +178,10 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore, peerTagger PeerTagger, func newEngine(ctx context.Context, bs bstore.Blockstore, peerTagger PeerTagger, self peer.ID, maxReplaceSize int, scoreLedger ScoreLedger) *Engine { + if scoreLedger == nil { + scoreLedger = NewDefaultScoreLedger() + } + e := &Engine{ ledgerMap: make(map[peer.ID]*ledger), scoreLedger: scoreLedger, @@ -221,9 +225,6 @@ func (e *Engine) UseScoreLedger(scoreLedger ScoreLedger) { // if it is unset, initializes the scoreLedger with the default // implementation. func (e *Engine) startScoreLedger(px process.Process) { - if e.scoreLedger == nil { - e.scoreLedger = NewDefaultScoreLedger() - } e.scoreLedger.Start(func(p peer.ID, score int) { if score == 0 { e.peerTagger.UntagPeer(p, e.tagUseful)