Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R]use more aggressive write cache policy #227

Merged
merged 2 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions consensus/parlia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down