use weight as the sync target selector

This commit is contained in:
vyzo 2020-10-26 14:51:26 +02:00
parent af53b72eb8
commit f26385d0c6

View File

@ -318,20 +318,14 @@ func (sm *syncManager) addSyncTarget(ts *types.TipSet) (*types.TipSet, bool, err
// it's not related to any active or pending sync; this could be a fork in which case we
// start a new worker to sync it, if it is *heavier* than any active or pending set;
// if it is not, we ignore it.
activeHeavier := false
for _, ws := range sm.state {
if ws.ts.Height() > ts.Height() {
activeHeavier = true
break
if isHeavier(ws.ts, ts) {
return nil, false, nil
}
}
if activeHeavier {
return nil, false, nil
}
pendHeaviest := sm.pend.Heaviest()
if pendHeaviest != nil && pendHeaviest.Height() > ts.Height() {
if pendHeaviest != nil && isHeavier(pendHeaviest, ts) {
return nil, false, nil
}
@ -351,7 +345,7 @@ func (sm *syncManager) selectSyncTarget(done *types.TipSet) (*types.TipSet, bool
heaviest := related.heaviestTipSet()
for _, ws := range sm.state {
if ws.ts.Height() > heaviest.Height() {
if isHeavier(ws.ts, heaviest) {
return nil, false, nil
}
}
@ -359,6 +353,10 @@ func (sm *syncManager) selectSyncTarget(done *types.TipSet) (*types.TipSet, bool
return heaviest, true, nil
}
func isHeavier(a, b *types.TipSet) bool {
return a.ParentWeight().GreaterThan(b.ParentWeight())
}
// sync buckets and related utilities
type syncBucketSet struct {
buckets []*syncTargetBucket