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

Method HandleCertificateResults

fsm/automatic.go:130–194  ·  view source on GitHub ↗

HandleCertificateResults() is a handler for the results of a quorum certificate

(qc *lib.QuorumCertificate, committee *lib.ValidatorSet)

Source from the content-addressed store, hash-verified

128
129// HandleCertificateResults() is a handler for the results of a quorum certificate
130func (s *StateMachine) HandleCertificateResults(qc *lib.QuorumCertificate, committee *lib.ValidatorSet) lib.ErrorI {
131 // ensure the certificate results are not nil
132 if qc == nil || qc.Results == nil {
133 return lib.ErrNilCertResults()
134 }
135 // ensure the committee isn't retired
136 retired, err := s.CommitteeIsRetired(qc.Header.ChainId)
137 if err != nil {
138 return err
139 }
140 // block the certificate results message
141 if retired {
142 return ErrNonSubsidizedCommittee()
143 }
144 // get the last data for the committee
145 data, err := s.GetCommitteeData(qc.Header.ChainId)
146 if err != nil {
147 return err
148 }
149 // ensure the root height isn't too old
150 if qc.Header.RootHeight < data.LastRootHeightUpdated {
151 return lib.ErrInvalidQCRootChainHeight()
152 }
153 // ensure the chain height isn't too old
154 if qc.Header.Height <= data.LastChainHeightUpdated {
155 return lib.ErrInvalidQCCommitteeHeight()
156 }
157 // setup convenience variables
158 results, chainId, isNested := qc.Results, qc.Header.ChainId, committee == nil
159 // handle dex action ordered by the quorum
160 if qc.Header.ChainId != s.Config.ChainId || isNested {
161 if err = s.HandleDexBatch(qc.Header.ChainId, results, isNested); err != nil {
162 s.log.Error(err.Error()) // log error only - allow the rest of the receipt to be processed
163 }
164 }
165 // handle the token swaps ordered by the quorum
166 s.HandleCommitteeSwaps(results.Orders, chainId)
167 // index the 'nested chain' checkpoint
168 if err = s.HandleCheckpoint(chainId, results); err != nil {
169 return err
170 }
171 // handle byzantine evidence
172 nonSignerPercent, err := s.HandleByzantine(qc, committee)
173 if err != nil {
174 return err
175 }
176 // reduce all payment percents proportional to the non-signer percent
177 for i, p := range results.RewardRecipients.PaymentPercents {
178 results.RewardRecipients.PaymentPercents[i].Percent = lib.Uint64ReducePercentage(p.Percent, uint64(nonSignerPercent))
179 }
180 // if the quorum is signalling 'retire' for a 'nestedChain'
181 if qc.Results.Retired && qc.Header.ChainId != s.Config.ChainId {
182 // retire the committeeId on this root
183 if err = s.RetireCommittee(qc.Header.ChainId); err != nil {
184 return err
185 }
186 }
187 // update the committee data

Callers 2

BeginBlockMethod · 0.95

Calls 14

CommitteeIsRetiredMethod · 0.95
GetCommitteeDataMethod · 0.95
HandleDexBatchMethod · 0.95
HandleCommitteeSwapsMethod · 0.95
HandleCheckpointMethod · 0.95
HandleByzantineMethod · 0.95
RetireCommitteeMethod · 0.95
UpsertCommitteeDataMethod · 0.95
ErrNilCertResultsFunction · 0.92
Uint64ReducePercentageFunction · 0.92

Tested by

no test coverage detected