From 1f3e0606ee42f5cec594b2c34b17d2aafcb47faf Mon Sep 17 00:00:00 2001 From: fudongbai <296179868@qq.com> Date: Mon, 17 May 2021 19:32:39 +0800 Subject: [PATCH 1/2] use more aggressive write cache policy --- consensus/parlia/parlia.go | 2 +- consensus/parlia/snapshot.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index 438042aff2..a8976fd4ad 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -868,7 +868,7 @@ func (p *Parlia) EnoughDistance(chain consensus.ChainReader, header *types.Heade if err != nil { return true } - return snap.enoughDistance(p.val) + return snap.enoughDistance(p.val, header) } // CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty diff --git a/consensus/parlia/snapshot.go b/consensus/parlia/snapshot.go index 05aa8de64f..dc83d92c8d 100644 --- a/consensus/parlia/snapshot.go +++ b/consensus/parlia/snapshot.go @@ -244,17 +244,23 @@ func (s *Snapshot) inturn(validator common.Address) bool { return validators[offset] == validator } -func (s *Snapshot) enoughDistance(validator common.Address) bool { +func (s *Snapshot) enoughDistance(validator common.Address, header *types.Header) bool { idx := s.indexOfVal(validator) if idx < 0 { return true } validatorNum := int64(len(s.validators())) + if validatorNum == 1 { + return true + } + if validator == header.Coinbase { + return false + } offset := (int64(s.Number) + 1) % int64(validatorNum) if int64(idx) >= offset { - return int64(idx)-offset >= validatorNum/2 + return int64(idx)-offset >= validatorNum-2 } else { - return validatorNum+int64(idx)-offset >= validatorNum/2 + return validatorNum+int64(idx)-offset >= validatorNum-2 } } From 571a3170923bccf899d3ac9fb9f74d3605b5b8b8 Mon Sep 17 00:00:00 2001 From: fudongbai <296179868@qq.com> Date: Wed, 19 May 2021 11:46:46 +0800 Subject: [PATCH 2/2] fix ungraceful shutdown issue --- eth/backend.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eth/backend.go b/eth/backend.go index 224253d4e1..2247b94b5d 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -574,6 +574,9 @@ func (s *Ethereum) Stop() error { close(s.closeBloomHandler) s.txPool.Stop() s.miner.Stop() + s.miner.Close() + // TODO this is a hotfix for https://github.com/ethereum/go-ethereum/issues/22892, need a better solution + time.Sleep(5 * time.Second) s.blockchain.Stop() s.engine.Close() rawdb.PopUncleanShutdownMarker(s.chainDb)