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

Method HandleMessageCertificateResults

fsm/message.go:321–359  ·  view source on GitHub ↗

HandleMessageCertificateResults() is the proper handler for a `CertificateResults` message

(msg *MessageCertificateResults)

Source from the content-addressed store, hash-verified

319
320// HandleMessageCertificateResults() is the proper handler for a `CertificateResults` message
321func (s *StateMachine) HandleMessageCertificateResults(msg *MessageCertificateResults) lib.ErrorI {
322 // load the root chain id from state
323 rootChainId, err := s.GetRootChainId()
324 if err != nil {
325 return err
326 }
327 // block any tx message certificate result for root or self chain id, as it is stored in the qc
328 if msg.Qc.Header.ChainId == rootChainId || msg.Qc.Header.ChainId == s.Config.ChainId {
329 return ErrInvalidCertificateResults()
330 }
331 s.log.Debugf("Handling certificate results msg with height %d:%d", msg.Qc.Header.Height, msg.Qc.Header.RootHeight)
332 // define convenience variables
333 chainId := msg.Qc.Header.ChainId
334 // get committee for the QC from the cache
335 var committee *lib.ValidatorSet
336 if s.LastValidatorSet != nil {
337 committee = s.LastValidatorSet[msg.Qc.Header.RootHeight+1][chainId]
338 }
339 if committee == nil {
340 // otherwise, retrieve it from the store
341 valSet, err := s.LoadCommittee(chainId, msg.Qc.Header.RootHeight)
342 if err != nil {
343 return err
344 }
345 committee = &valSet
346 }
347 // ensure it's a valid QC
348 // max block size is 0 here because there should not be a block attached to this QC
349 isPartialQC, err := msg.Qc.Check(*committee, 0, &lib.View{NetworkId: uint64(s.NetworkID), ChainId: chainId}, false)
350 if err != nil {
351 return err
352 }
353 // if it's not signed by a +2/3rds committee majority
354 if isPartialQC {
355 return lib.ErrNoMaj23()
356 }
357 // handle the certificate results
358 return s.HandleCertificateResults(msg.Qc, committee)
359}
360
361// HandleMessageSubsidy() is the proper handler for a `Subsidy` message
362func (s *StateMachine) HandleMessageSubsidy(msg *MessageSubsidy) lib.ErrorI {

Callers 2

HandleMessageMethod · 0.95

Calls 7

GetRootChainIdMethod · 0.95
LoadCommitteeMethod · 0.95
ErrNoMaj23Function · 0.92
DebugfMethod · 0.65
CheckMethod · 0.65

Tested by 1