native: refactor argument of NEO's getCommitteeMembers function

No funcional changes, just refactoring. It doesn't need the whole cache,
only the set of committee keys with votes.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-09-01 16:00:53 +03:00
parent 794658b54c
commit 27dddb4d50

View file

@ -363,7 +363,7 @@ func (n *NEO) initConfigCache(cfg config.ProtocolConfiguration) error {
func (n *NEO) updateCache(cache *NeoCache, cvs keysWithVotes, blockHeight uint32) error { func (n *NEO) updateCache(cache *NeoCache, cvs keysWithVotes, blockHeight uint32) error {
cache.committee = cvs cache.committee = cvs
var committee = getCommitteeMembers(cache) var committee = getCommitteeMembers(cache.committee)
script, err := smartcontract.CreateMajorityMultiSigRedeemScript(committee.Copy()) script, err := smartcontract.CreateMajorityMultiSigRedeemScript(committee.Copy())
if err != nil { if err != nil {
return err return err
@ -431,7 +431,7 @@ func (n *NEO) OnPersist(ic *interop.Context) error {
func (n *NEO) PostPersist(ic *interop.Context) error { func (n *NEO) PostPersist(ic *interop.Context) error {
gas := n.GetGASPerBlock(ic.DAO, ic.Block.Index) gas := n.GetGASPerBlock(ic.DAO, ic.Block.Index)
cache := ic.DAO.GetROCache(n.ID).(*NeoCache) cache := ic.DAO.GetROCache(n.ID).(*NeoCache)
pubs := getCommitteeMembers(cache) pubs := getCommitteeMembers(cache.committee)
committeeSize := n.cfg.GetCommitteeSize(ic.Block.Index) committeeSize := n.cfg.GetCommitteeSize(ic.Block.Index)
index := int(ic.Block.Index) % committeeSize index := int(ic.Block.Index) % committeeSize
committeeReward := new(big.Int).Mul(gas, bigCommitteeRewardRatio) committeeReward := new(big.Int).Mul(gas, bigCommitteeRewardRatio)
@ -1137,11 +1137,10 @@ func (n *NEO) modifyVoterTurnout(d *dao.Simple, amount *big.Int) error {
// GetCommitteeMembers returns public keys of nodes in committee using cached value. // GetCommitteeMembers returns public keys of nodes in committee using cached value.
func (n *NEO) GetCommitteeMembers(d *dao.Simple) keys.PublicKeys { func (n *NEO) GetCommitteeMembers(d *dao.Simple) keys.PublicKeys {
cache := d.GetROCache(n.ID).(*NeoCache) cache := d.GetROCache(n.ID).(*NeoCache)
return getCommitteeMembers(cache) return getCommitteeMembers(cache.committee)
} }
func getCommitteeMembers(cache *NeoCache) keys.PublicKeys { func getCommitteeMembers(cvs keysWithVotes) keys.PublicKeys {
var cvs = cache.committee
var committee = make(keys.PublicKeys, len(cvs)) var committee = make(keys.PublicKeys, len(cvs))
var err error var err error
for i := range committee { for i := range committee {