-
Notifications
You must be signed in to change notification settings - Fork 33
[Core] KISS 1 - Finite State Machine [Merge me first] - (Issue: #499) #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
143feaa
a046984
82505e4
da9774b
f784dab
049023c
a18ecf5
e01c75c
142d53b
3c84eae
4eed45a
b094622
e6e8fe5
f8ed453
2a21542
e70b308
0d20ada
963212a
8871a3d
8d50538
5141f07
1d98c9f
f5f9777
4c5f50c
7023ca0
34f3d87
74d012f
d697a7f
8e89219
c66a5c8
eb4174b
7b974a9
8a5de14
3a71510
a2e3348
f006a1d
8cdc827
5514fc3
72f96d9
934fe00
9bf8b81
724a326
c0cdeac
e5c93f7
7381c8b
51e971e
43d31cd
61bdd35
65ac7ce
8c5ad05
9fe0dc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package consensus | ||
|
|
||
| import ( | ||
| "github.com/pokt-network/pocket/shared/messaging" | ||
| ) | ||
|
|
||
| // publishNewHeightEvent publishes a new height event to the bus so that other interested IntegratableModules can react to it if necessary | ||
| func (m *consensusModule) publishNewHeightEvent(height uint64) { | ||
| newHeightEvent, err := messaging.PackMessage(&messaging.ConsensusNewHeightEvent{Height: height}) | ||
| if err != nil { | ||
| m.logger.Fatal().Err(err).Msg("Failed to pack consensus new height event") | ||
| } | ||
| m.GetBus().PublishEventToBus(newHeightEvent) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import ( | |
| coreTypes "github.com/pokt-network/pocket/shared/core/types" | ||
| cryptoPocket "github.com/pokt-network/pocket/shared/crypto" | ||
| "github.com/pokt-network/pocket/shared/modules" | ||
| "github.com/pokt-network/pocket/shared/modules/base_modules" | ||
| "google.golang.org/protobuf/types/known/anypb" | ||
| ) | ||
|
|
||
|
|
@@ -30,7 +31,8 @@ var ( | |
| ) | ||
|
|
||
| type consensusModule struct { | ||
| bus modules.Bus | ||
| base_modules.IntegratableModule | ||
|
|
||
| privateKey cryptoPocket.Ed25519PrivateKey | ||
|
|
||
| consCfg *configs.ConsensusConfig | ||
|
|
@@ -90,6 +92,7 @@ type ConsensusDebugModule interface { | |
|
|
||
| func (m *consensusModule) SetHeight(height uint64) { | ||
| m.height = height | ||
| m.publishNewHeightEvent(height) | ||
| } | ||
|
|
||
| func (m *consensusModule) SetRound(round uint64) { | ||
|
|
@@ -136,11 +139,11 @@ func (m *consensusModule) ClearLeaderMessagesPool() { | |
| m.clearMessagesPool() | ||
| } | ||
|
|
||
| func Create(bus modules.Bus) (modules.Module, error) { | ||
| return new(consensusModule).Create(bus) | ||
| func Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { | ||
| return new(consensusModule).Create(bus, options...) | ||
| } | ||
|
|
||
| func (*consensusModule) Create(bus modules.Bus) (modules.Module, error) { | ||
| func (*consensusModule) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { | ||
| leaderElectionMod, err := leader_election.Create(bus) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -179,10 +182,13 @@ func (*consensusModule) Create(bus modules.Bus) (modules.Module, error) { | |
|
|
||
| hotstuffMempool: make(map[typesCons.HotstuffStep]*hotstuffFIFOMempool), | ||
| } | ||
| if err := bus.RegisterModule(m); err != nil { | ||
| return nil, err | ||
|
|
||
| for _, option := range options { | ||
| option(m) | ||
| } | ||
|
|
||
| bus.RegisterModule(m) | ||
|
|
||
| runtimeMgr := bus.GetRuntimeMgr() | ||
|
|
||
| consensusCfg := runtimeMgr.GetConfig().Consensus | ||
|
|
@@ -259,15 +265,8 @@ func (m *consensusModule) GetModuleName() string { | |
| return modules.ConsensusModuleName | ||
| } | ||
|
|
||
| func (m *consensusModule) GetBus() modules.Bus { | ||
| if m.bus == nil { | ||
| logger.Global.Fatal().Msg("PocketBus is not initialized") | ||
| } | ||
| return m.bus | ||
| } | ||
|
|
||
| func (m *consensusModule) SetBus(pocketBus modules.Bus) { | ||
| m.bus = pocketBus | ||
| m.IntegratableModule.SetBus(pocketBus) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your example is not representative of the scenario. If I did what you are suggesting I guess we would have this 🤔: Let's play dumb and try it out... overloading.mp4nothing happens! If I try to "walk my way into the stack"... it stops there, suggesting that my solution seems to be the right approach. overloading2.mp4If you wanna play along:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I understand what I was missing and why you're solution works. However, now I'm trying to understand:
I can understand why (1) is not happening, but without researching, this makes me feel that the playground abstracts (2) away for us. |
||
| if m.paceMaker != nil { | ||
| m.paceMaker.SetBus(pocketBus) | ||
| } | ||
|
|
||



Uh oh!
There was an error while loading. Please reload this page.