Skip to content

Commit 08e438b

Browse files
deblasisOlshansk
andauthored
[SPIKE][Consensus] Remove validatorMap from the consensusModule struct - (Issue #331) (#425)
## Description This PR builds upon #402 and removes `validatorMap` from the `consensusModule` struct, encapsulating the logic so that the validator set is dynamic and retrieved from the `persistence` module. Also, since the change introduced the natural dependency on `persistence`, it made me question and revisit the way the modules register themselves with the `bus` and also how the modules are instantiated. In an effort to simply the codebase and testing, while we improve the way we do dependency injection, the modules now are instantiated with a `bus` that will allow them to access to all the dependencies they need. Previously the modules required a `runtimeMgr` in their constructor and the bus registration was handled like an after-thought. ## Issue Fixes #331 ## Type of change Please mark the relevant option(s): - [x] New feature, functionality or library - [ ] Bug fix - [x] Code health or cleanup - [x] Major breaking change - [ ] Documentation - [ ] Other <!-- add details here if it a different type of change --> ## List of changes - Removed `validatorMap` from `consensusModule` and encapsulated the logic so that it's dynamic, per-height and sourced from `persistence` - Refactored module registration in `bus` - Refactored modules instantiation and DI (`runtimeMgr` -> `bus`) - The `runtimeMgr` is now a dependency and it can be accessed via the bus - Minor improvements in tests ## Testing - [x] `make develop_test` - [x] [LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md) w/ all of the steps outlined in the `README` ## Required Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have tested my changes using the available tooling - [ ] I have updated the corresponding CHANGELOG ### If Applicable Checklist - [x] I have updated the corresponding README(s); local and/or global - [x] I have added tests that prove my fix is effective or that my feature works - [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s) - [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s) Signed-off-by: Alessandro De Blasis <[email protected]> Co-authored-by: Daniel Olshansky <[email protected]>
1 parent a86c0e6 commit 08e438b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1141
-795
lines changed

app/client/cli/debug.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewDebugCommand() *cobra.Command {
5858
Args: cobra.ExactArgs(0),
5959
PersistentPreRun: func(cmd *cobra.Command, args []string) {
6060
var err error
61-
runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK())
61+
runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithClientDebugMode(), runtime.WithRandomPK())
6262

6363
// HACK(#416): this is a temporary solution that guarantees backward compatibility while we implement peer discovery.
6464
validators = runtimeMgr.GetGenesis().Validators
@@ -74,7 +74,8 @@ func NewDebugCommand() *cobra.Command {
7474

7575
debugCurrentHeightProvider := debugCHP.NewDebugCurrentHeightProvider(0)
7676

77-
p2pM, err := p2p.CreateWithProviders(runtimeMgr, debugAddressBookProvider, debugCurrentHeightProvider)
77+
// TODO(#429): refactor injecting the dependencies into the bus so that they can be consumed in an updated `P2PModule.Create()` implementation
78+
p2pM, err := p2p.CreateWithProviders(runtimeMgr.GetBus(), debugAddressBookProvider, debugCurrentHeightProvider)
7879
if err != nil {
7980
log.Fatalf("[ERROR] Failed to create p2p module: %v", err.Error())
8081
}

app/client/cli/doc/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [0.0.0.4] - 2023-01-09
10+
## [0.0.0.4] - 2023-01-10
1111

1212
- The `client` (i.e. CLI) no longer instantiates a `P2P` module along with a bus of optional modules. Instead, it instantiates a `client-only` `P2P` module that is disconnected from consensus and persistence. Interactions with the persistence & consensus layer happen via RPC.
1313
- Replaced previous implementation, reliant on `ValidatorMap`, with a temporary fetch from genesis. This will be replaced with a lightweight peer discovery mechanism in #416

app/pocket/doc/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.0.0.1] - 2023-01-10
11+
12+
- Updated module constructor to accept a `bus` and not a `runtimeMgr` anymore
13+
1014
## [0.0.0.0] - 2022-11-02
1115

1216
### Added

app/pocket/main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ func main() {
2222
}
2323

2424
runtimeMgr := runtime.NewManagerFromFiles(*configFilename, *genesisFilename)
25+
bus, err := runtime.CreateBus(runtimeMgr)
26+
if err != nil {
27+
log.Fatalf("Failed to create bus: %s", err)
28+
}
2529

26-
pocketNode, err := shared.CreateNode(runtimeMgr)
30+
pocketNode, err := shared.CreateNode(bus)
2731
if err != nil {
2832
log.Fatalf("Failed to create pocket node: %s", err)
2933
}

build/config/config1.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
"use_rain_tree": true,
2727
"is_empty_connection_type": false,
2828
"private_key": "6fd0bc54cc2dd205eaf226eebdb0451629b321f11d279013ce6fdd5a33059256b2eda2232ffb2750bf761141f70f75a03a025f65b2b2b417c7f8b3c9ca91e8e4",
29-
"max_mempool_count": 100000,
30-
"is_client_only": false
29+
"max_mempool_count": 100000
3130
},
3231
"telemetry": {
3332
"enabled": true,

build/docs/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [0.0.0.2] - 2023-01-09
10+
## [0.0.0.2] - 2023-01-10
1111

1212
- Removed `BaseConfig` from `configs`
1313
- Centralized `PersistenceGenesisState` and `ConsensusGenesisState` into `GenesisState`
14+
- Removed `is_client_only` since it's set programmatically in the CLI
1415

1516
## [0.0.0.1] - 2022-12-29
1617

consensus/consensus_tests/hotstuff_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ func TestHotstuff4Nodes1BlockHappyPath(t *testing.T) {
1616
clockMock := clock.NewMock()
1717
// Test configs
1818
runtimeMgrs := GenerateNodeRuntimeMgrs(t, numValidators, clockMock)
19-
19+
buses := GenerateBuses(t, runtimeMgrs)
2020
go timeReminder(clockMock, 100*time.Millisecond)
2121

2222
// Create & start test pocket nodes
2323
testChannel := make(modules.EventsChannel, 100)
24-
pocketNodes := CreateTestConsensusPocketNodes(t, runtimeMgrs, testChannel)
24+
pocketNodes := CreateTestConsensusPocketNodes(t, buses, testChannel)
2525
StartAllTestPocketNodes(t, pocketNodes)
2626

2727
// Debug message to start consensus by triggering first view change

consensus/consensus_tests/pacemaker_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ func TestTinyPacemakerTimeouts(t *testing.T) {
2828
consCfg := runtimeConfig.GetConfig().Consensus.PacemakerConfig
2929
consCfg.TimeoutMsec = paceMakerTimeoutMsec
3030
}
31+
buses := GenerateBuses(t, runtimeMgrs)
3132

3233
// Create & start test pocket nodes
3334
testChannel := make(modules.EventsChannel, 100)
34-
pocketNodes := CreateTestConsensusPocketNodes(t, runtimeMgrs, testChannel)
35+
pocketNodes := CreateTestConsensusPocketNodes(t, buses, testChannel)
3536
StartAllTestPocketNodes(t, pocketNodes)
3637

3738
// Debug message to start consensus by triggering next view.
@@ -124,12 +125,13 @@ func TestTinyPacemakerTimeouts(t *testing.T) {
124125
func TestPacemakerCatchupSameStepDifferentRounds(t *testing.T) {
125126
clockMock := clock.NewMock()
126127
runtimeConfigs := GenerateNodeRuntimeMgrs(t, numValidators, clockMock)
128+
buses := GenerateBuses(t, runtimeConfigs)
127129

128130
timeReminder(clockMock, 100*time.Millisecond)
129131

130132
// Create & start test pocket nodes
131133
testChannel := make(modules.EventsChannel, 100)
132-
pocketNodes := CreateTestConsensusPocketNodes(t, runtimeConfigs, testChannel)
134+
pocketNodes := CreateTestConsensusPocketNodes(t, buses, testChannel)
133135
StartAllTestPocketNodes(t, pocketNodes)
134136

135137
// Starting point
@@ -204,9 +206,9 @@ func TestPacemakerCatchupSameStepDifferentRounds(t *testing.T) {
204206
for nodeId, pocketNode := range pocketNodes {
205207
nodeState := GetConsensusNodeState(pocketNode)
206208
if nodeId == leaderId {
207-
require.Equal(t, uint8(consensus.Prepare), nodeState.Step)
209+
require.Equal(t, consensus.Prepare.String(), typesCons.HotstuffStep(nodeState.Step).String())
208210
} else {
209-
require.Equal(t, uint8(consensus.PreCommit), nodeState.Step)
211+
require.Equal(t, consensus.PreCommit.String(), typesCons.HotstuffStep(nodeState.Step).String())
210212
}
211213
require.Equal(t, uint64(3), nodeState.Height)
212214
require.Equal(t, uint8(6), nodeState.Round)

0 commit comments

Comments
 (0)