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

Method HandleMessagePause

fsm/message.go:233–262  ·  view source on GitHub ↗

HandleMessagePause() is the proper handler for an `Pause` message

(msg *MessagePause)

Source from the content-addressed store, hash-verified

231
232// HandleMessagePause() is the proper handler for an `Pause` message
233func (s *StateMachine) HandleMessagePause(msg *MessagePause) lib.ErrorI {
234 // extract the address object from the address bytes from the pause message
235 address := crypto.NewAddressFromBytes(msg.Address)
236 // get the validator from the state
237 validator, err := s.GetValidator(address)
238 if err != nil {
239 return err
240 }
241 // ensure the validator is not already paused
242 if validator.MaxPausedHeight != 0 {
243 return ErrValidatorPaused()
244 }
245 // ensure the validator is not unstaking
246 if validator.UnstakingHeight != 0 {
247 return ErrValidatorUnstaking()
248 }
249 // ensure the validator is not a delegate
250 if validator.Delegate {
251 return ErrValidatorIsADelegate()
252 }
253 // get validator the parameters from state
254 params, err := s.GetParamsVal()
255 if err != nil {
256 return err
257 }
258 // calculate the max paused height by adding MaxPauseBlocks to current height
259 maxPausedHeight := s.Height() + params.MaxPauseBlocks
260 // set the validator as paused in the state
261 return s.SetValidatorPaused(address, validator, maxPausedHeight)
262}
263
264// HandleMessageUnpause() is the proper handler for an `Unpause` message
265func (s *StateMachine) HandleMessageUnpause(msg *MessageUnpause) lib.ErrorI {

Callers 3

HandleMessageMethod · 0.95
SetValidatorsPausedMethod · 0.95
TestMessagePauseFunction · 0.80

Calls 8

GetValidatorMethod · 0.95
GetParamsValMethod · 0.95
HeightMethod · 0.95
SetValidatorPausedMethod · 0.95
NewAddressFromBytesFunction · 0.92
ErrValidatorPausedFunction · 0.85
ErrValidatorUnstakingFunction · 0.85
ErrValidatorIsADelegateFunction · 0.85

Tested by 1

TestMessagePauseFunction · 0.64