use weight as the sync target selector
This commit is contained in:
parent
af53b72eb8
commit
f26385d0c6
@ -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
|
// 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;
|
// start a new worker to sync it, if it is *heavier* than any active or pending set;
|
||||||
// if it is not, we ignore it.
|
// if it is not, we ignore it.
|
||||||
activeHeavier := false
|
|
||||||
for _, ws := range sm.state {
|
for _, ws := range sm.state {
|
||||||
if ws.ts.Height() > ts.Height() {
|
if isHeavier(ws.ts, ts) {
|
||||||
activeHeavier = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if activeHeavier {
|
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pendHeaviest := sm.pend.Heaviest()
|
pendHeaviest := sm.pend.Heaviest()
|
||||||
if pendHeaviest != nil && pendHeaviest.Height() > ts.Height() {
|
if pendHeaviest != nil && isHeavier(pendHeaviest, ts) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +345,7 @@ func (sm *syncManager) selectSyncTarget(done *types.TipSet) (*types.TipSet, bool
|
|||||||
|
|
||||||
heaviest := related.heaviestTipSet()
|
heaviest := related.heaviestTipSet()
|
||||||
for _, ws := range sm.state {
|
for _, ws := range sm.state {
|
||||||
if ws.ts.Height() > heaviest.Height() {
|
if isHeavier(ws.ts, heaviest) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,6 +353,10 @@ func (sm *syncManager) selectSyncTarget(done *types.TipSet) (*types.TipSet, bool
|
|||||||
return heaviest, true, nil
|
return heaviest, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isHeavier(a, b *types.TipSet) bool {
|
||||||
|
return a.ParentWeight().GreaterThan(b.ParentWeight())
|
||||||
|
}
|
||||||
|
|
||||||
// sync buckets and related utilities
|
// sync buckets and related utilities
|
||||||
type syncBucketSet struct {
|
type syncBucketSet struct {
|
||||||
buckets []*syncTargetBucket
|
buckets []*syncTargetBucket
|
||||||
|
Loading…
Reference in New Issue
Block a user