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

fix: set the score ledger on start #447

Merged
merged 2 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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