MCPcopy
hub / github.com/canopy-network/canopy / SetValidators

Method SetValidators

fsm/validator.go:131–179  ·  view source on GitHub ↗

SetValidators() upserts multiple Validators into the state and updates the supply tracker

(validators []*Validator, supply *Supply)

Source from the content-addressed store, hash-verified

129
130// SetValidators() upserts multiple Validators into the state and updates the supply tracker
131func (s *StateMachine) SetValidators(validators []*Validator, supply *Supply) lib.ErrorI {
132 // for each validator in the list
133 for _, val := range validators {
134 // if the unstaking height or the max paused height is set
135 if val.UnstakingHeight != 0 {
136 // if the validator is unstaking - update it accordingly in state
137 if err := s.SetValidatorUnstaking(crypto.NewAddress(val.Address), val, val.UnstakingHeight); err != nil {
138 return err
139 }
140 } else if val.MaxPausedHeight != 0 {
141 // if validator is paused - update it accordingly
142 if err := s.SetValidatorPaused(crypto.NewAddress(val.Address), val, val.MaxPausedHeight); err != nil {
143 return err
144 }
145 }
146 // add to 'total supply' in the supply tracker
147 supply.Total += val.StakedAmount
148 // add to 'staked supply' in the supply tracker
149 supply.Staked += val.StakedAmount
150 // set the validator structure in state
151 if err := s.SetValidator(val); err != nil {
152 return err
153 }
154 // if the validator is a 'delegate'
155 if val.Delegate {
156 // add to the delegation supply
157 supply.DelegatedOnly += val.StakedAmount
158 // set the delegations in state
159 if err := s.SetDelegations(crypto.NewAddressFromBytes(val.Address), val.StakedAmount, val.Committees); err != nil {
160 return err
161 }
162 } else {
163 if err := s.SetCommittees(crypto.NewAddressFromBytes(val.Address), val.StakedAmount, val.Committees); err != nil {
164 return err
165 }
166 }
167 }
168 //
169 // get the 'supply tracker' from state to update the local 'supply tracker' with the automatically populated committee/delegate staked pool
170 supplyFromState, err := s.GetSupply()
171 if err != nil {
172 return err
173 }
174 // update the committee staked pool
175 supply.CommitteeStaked = supplyFromState.CommitteeStaked
176 // update the delegate staked pool
177 supply.CommitteeDelegatedOnly = supplyFromState.CommitteeDelegatedOnly
178 return nil
179}
180
181// SetValidator() upserts a Validator object into the state
182func (s *StateMachine) SetValidator(validator *Validator) (err lib.ErrorI) {

Callers 15

NewStateFromGenesisMethod · 0.95
TestDeleteCommitteesFunction · 0.80
TestMessageUnstakeFunction · 0.80
TestMessagePauseFunction · 0.80
TestMessageUnpauseFunction · 0.80
TestBeginBlockFunction · 0.80
TestSetGetValidatorsFunction · 0.80
TestUpdateValidatorStakeFunction · 0.80

Calls 8

SetValidatorUnstakingMethod · 0.95
SetValidatorPausedMethod · 0.95
SetValidatorMethod · 0.95
SetDelegationsMethod · 0.95
SetCommitteesMethod · 0.95
GetSupplyMethod · 0.95
NewAddressFunction · 0.92
NewAddressFromBytesFunction · 0.92

Tested by 15

TestDeleteCommitteesFunction · 0.64
TestMessageUnstakeFunction · 0.64
TestMessagePauseFunction · 0.64
TestMessageUnpauseFunction · 0.64
TestBeginBlockFunction · 0.64
TestSetGetValidatorsFunction · 0.64
TestUpdateValidatorStakeFunction · 0.64
TestDeleteValidatorFunction · 0.64