Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #447 from ipfs/fix/panic-and-leak
Browse files Browse the repository at this point in the history
fix: set the score ledger on start
  • Loading branch information
Stebalien authored Nov 13, 2020
2 parents b4720fa + ed0f4ed commit 95cb1a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 4 additions & 3 deletions internal/decision/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions internal/decision/scoreledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 95cb1a0

Please sign in to comment.