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

Method BeginBlock

fsm/automatic.go:10–66  ·  view source on GitHub ↗

* This file handles 'automatic' (non-transaction-induced) state changes that occur at the beginning and ending of a block */ BeginBlock() is code that is executed at the start of `applying` the block

()

Source from the content-addressed store, hash-verified

8
9// BeginBlock() is code that is executed at the start of `applying` the block
10func (s *StateMachine) BeginBlock() (lib.Events, lib.ErrorI) {
11 s.events.Refer(lib.EventStageBeginBlock)
12 // execute plugin begin block if enabled
13 if s.Plugin != nil {
14 resp, err := s.Plugin.BeginBlock(s, &lib.PluginBeginRequest{Height: s.height})
15 if err != nil {
16 return nil, err
17 }
18 if resp != nil {
19 if err = resp.Error.E(); err != nil {
20 return nil, err
21 }
22 if err = s.addPluginEvents(resp.Events); err != nil {
23 return nil, err
24 }
25 }
26 }
27 // prevent attempting to load the certificate for height 0
28 if s.Height() <= 1 {
29 return nil, nil
30 }
31 // enforce protocol upgrades
32 if err := s.CheckProtocolVersion(); err != nil {
33 return nil, err
34 }
35 // reward committees
36 if err := s.FundCommitteeRewardPools(); err != nil {
37 return nil, err
38 }
39 // handle last certificate results
40 lastCertificate, err := s.LoadCertificate(s.Height() - 1)
41 if err != nil {
42 return nil, err
43 }
44 // load the root chain id at the certificate height
45 rootChainId, err := s.LoadRootChainId(s.Height() - 1)
46 if err != nil {
47 return nil, err
48 }
49 // if not root-chain: the committee won't match the certificate result
50 // so just set the committee to nil to ignore the byzantine evidence
51 // the byzantine evidence is handled at `Transaction Level` on the root
52 // chain with a HandleMessageCertificateResults
53 if s.Config.ChainId != rootChainId {
54 err = s.HandleCertificateResults(lastCertificate, nil)
55 return s.events.Reset(), err
56 }
57 // load the validator set for the previous height
58 lastValidatorSet, err := s.LoadCommittee(s.Config.ChainId, s.Height()-1)
59 if err != nil {
60 return nil, err
61 }
62 // if is root-chain: load the committee from state as the certificate result
63 // will match the evidence and there's no Transaction to HandleMessageCertificateResults
64 err = s.HandleCertificateResults(lastCertificate, &lastValidatorSet)
65 return s.events.Reset(), err
66}
67

Callers 2

ApplyBlockMethod · 0.95
TestBeginBlockFunction · 0.45

Calls 11

addPluginEventsMethod · 0.95
HeightMethod · 0.95
CheckProtocolVersionMethod · 0.95
LoadCertificateMethod · 0.95
LoadRootChainIdMethod · 0.95
LoadCommitteeMethod · 0.95
ReferMethod · 0.80
EMethod · 0.80
ResetMethod · 0.65

Tested by 1

TestBeginBlockFunction · 0.36