From b844958a96bfef0cf303a477da6924387ba78456 Mon Sep 17 00:00:00 2001 From: buddho Date: Mon, 22 Jul 2024 14:53:26 +0800 Subject: [PATCH] core: improve the network stability when double sign happens (#2596) --- core/forkchoice.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/forkchoice.go b/core/forkchoice.go index c70d5dd64..bea7652fa 100644 --- a/core/forkchoice.go +++ b/core/forkchoice.go @@ -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 }