core: improve readability of the fork choice logic (#2658)
This commit is contained in:
parent
5d19f2182b
commit
3bd9a2395c
@ -121,12 +121,19 @@ func (f *ForkChoice) ReorgNeeded(current *types.Header, extern *types.Header) (b
|
|||||||
if f.preserve != nil {
|
if f.preserve != nil {
|
||||||
currentPreserve, externPreserve = f.preserve(current), f.preserve(extern)
|
currentPreserve, externPreserve = f.preserve(current), f.preserve(extern)
|
||||||
}
|
}
|
||||||
|
choiceRules := func() bool {
|
||||||
|
if extern.Time == current.Time {
|
||||||
doubleSign := (extern.Coinbase == current.Coinbase)
|
doubleSign := (extern.Coinbase == current.Coinbase)
|
||||||
reorg = !currentPreserve && (externPreserve ||
|
if doubleSign {
|
||||||
extern.Time < current.Time ||
|
return extern.Hash().Cmp(current.Hash()) < 0
|
||||||
extern.Time == current.Time &&
|
} else {
|
||||||
((doubleSign && extern.Hash().Cmp(current.Hash()) < 0) ||
|
return f.rand.Float64() < 0.5
|
||||||
(!doubleSign && f.rand.Float64() < 0.5)))
|
}
|
||||||
|
} else {
|
||||||
|
return extern.Time < current.Time
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reorg = !currentPreserve && (externPreserve || choiceRules())
|
||||||
}
|
}
|
||||||
return reorg, nil
|
return reorg, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user