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

Handle computation of stakes in parallel #144

Open
danil-lashin opened this issue Nov 13, 2018 · 0 comments
Open

Handle computation of stakes in parallel #144

danil-lashin opened this issue Nov 13, 2018 · 0 comments
Assignees
Milestone

Comments

@danil-lashin
Copy link
Contributor

danil-lashin commented Nov 13, 2018

Currently stake values re-computed each 12 blocks. In worst case node should calculate 256x3x1 000=768 000 values. This can and should be done in parallel.

func (s *StateDB) RecalculateTotalStakeValues() {
stateCandidates := s.getStateCandidates()
validators := s.getStateValidators()
for i := range stateCandidates.data {
candidate := &stateCandidates.data[i]
totalBipStake := big.NewInt(0)
for j := range candidate.Stakes {
stake := &candidate.Stakes[j]
stake.BipValue = stake.CalcBipValue(s)
totalBipStake.Add(totalBipStake, stake.BipValue)
}
candidate.TotalBipStake = totalBipStake
for j := range validators.data {
if bytes.Equal(validators.data[j].PubKey, candidate.PubKey) {
validators.data[j].TotalBipStake = totalBipStake
break
}
}
}
s.setStateValidators(validators)
s.MarkStateValidatorsDirty()
s.setStateCandidates(stateCandidates)
s.MarkStateCandidateDirty()
}

@danil-lashin danil-lashin added this to the Release milestone Nov 13, 2018
@danil-lashin danil-lashin self-assigned this Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant