Browse Source

Merge pull request #227 from binance-chain/cache_write_policy

[R4R]use more aggressive write cache policy
zjubfd 4 years ago
parent
commit
b67a129e5b
3 changed files with 13 additions and 4 deletions
  1. 1 1
      consensus/parlia/parlia.go
  2. 9 3
      consensus/parlia/snapshot.go
  3. 3 0
      eth/backend.go

+ 1 - 1
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

+ 9 - 3
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
 	}
 }
 

+ 3 - 0
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)