core: fix (*NEO).computeCommitteeMembers
In (*NEO).computeCommitteeMembers we return standbyCommittee in case if there's not enought candidates. But there can be standby committee members among candidates, so we need to fill in known votes.
This commit is contained in:
parent
be0609cc7a
commit
bc3f8a3b48
1 changed files with 19 additions and 11 deletions
|
@ -246,11 +246,9 @@ func (n *NEO) updateCommittee(ic *interop.Context) error {
|
||||||
return ic.DAO.PutStorageItem(n.ContractID, prefixCommittee, si)
|
return ic.DAO.PutStorageItem(n.ContractID, prefixCommittee, si)
|
||||||
}
|
}
|
||||||
|
|
||||||
committee, cvs, err := n.computeCommitteeMembers(ic.Chain, ic.DAO)
|
_, cvs, err := n.computeCommitteeMembers(ic.Chain, ic.DAO)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if cvs == nil {
|
|
||||||
cvs = toKeysWithVotes(committee)
|
|
||||||
}
|
}
|
||||||
if err := n.updateCache(cvs, ic.Chain); err != nil {
|
if err := n.updateCache(cvs, ic.Chain); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -852,18 +850,28 @@ func (n *NEO) computeCommitteeMembers(bc blockchainer.Blockchainer, d dao.DAO) (
|
||||||
// votersCount / totalSupply must be >= 0.2
|
// votersCount / totalSupply must be >= 0.2
|
||||||
votersCount.Mul(votersCount, big.NewInt(effectiveVoterTurnout))
|
votersCount.Mul(votersCount, big.NewInt(effectiveVoterTurnout))
|
||||||
voterTurnout := votersCount.Div(votersCount, n.getTotalSupply(d))
|
voterTurnout := votersCount.Div(votersCount, n.getTotalSupply(d))
|
||||||
if voterTurnout.Sign() != 1 {
|
|
||||||
pubs := bc.GetStandByCommittee()
|
sbVals := bc.GetStandByCommittee()
|
||||||
return pubs, nil, nil
|
count := len(sbVals)
|
||||||
}
|
|
||||||
cs, err := n.getCandidates(d, false)
|
cs, err := n.getCandidates(d, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
sbVals := bc.GetStandByCommittee()
|
if voterTurnout.Sign() != 1 || len(cs) < count {
|
||||||
count := len(sbVals)
|
kvs := make(keysWithVotes, count)
|
||||||
if len(cs) < count {
|
for i := range kvs {
|
||||||
return sbVals, nil, nil
|
kvs[i].UnmarshaledKey = sbVals[i]
|
||||||
|
kvs[i].Key = string(sbVals[i].Bytes())
|
||||||
|
votes := big.NewInt(0)
|
||||||
|
for j := range cs {
|
||||||
|
if cs[j].Key == kvs[i].Key {
|
||||||
|
votes = cs[j].Votes
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kvs[i].Votes = votes
|
||||||
|
}
|
||||||
|
return sbVals, kvs, nil
|
||||||
}
|
}
|
||||||
pubs := make(keys.PublicKeys, count)
|
pubs := make(keys.PublicKeys, count)
|
||||||
for i := range pubs {
|
for i := range pubs {
|
||||||
|
|
Loading…
Reference in a new issue