core: improve the network stability when double sign happens (#2596)

This commit is contained in:
buddho 2024-07-22 14:53:26 +08:00 committed by GitHub
parent 3cade73e40
commit b844958a96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -121,9 +121,12 @@ func (f *ForkChoice) ReorgNeeded(current *types.Header, extern *types.Header) (b
if f.preserve != nil {
currentPreserve, externPreserve = f.preserve(current), f.preserve(extern)
}
doubleSign := (extern.Coinbase == current.Coinbase)
reorg = !currentPreserve && (externPreserve ||
extern.Time < current.Time ||
extern.Time == current.Time && f.rand.Float64() < 0.5)
extern.Time == current.Time &&
((doubleSign && extern.Hash().Cmp(current.Hash()) < 0) ||
(!doubleSign && f.rand.Float64() < 0.5)))
}
return reorg, nil
}