Skip to content
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

[Shared] Config and genesis handling refactoring idea #235

Merged
merged 107 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
9358e73
refactor(Config): runtime module
deblasis Sep 20, 2022
b05c71c
style(Client): consistency
deblasis Sep 20, 2022
0163d71
fix(Config): make configPath and genesisPath available in Base
deblasis Sep 20, 2022
5283cd5
style(Persistence): Persistance -> Persistence
deblasis Sep 20, 2022
2aa7c29
fix(Config): Base init
deblasis Sep 20, 2022
c0afedf
feat(Config): viper config parsing + environment variables
deblasis Sep 20, 2022
5e0bade
fix(Config): filename handling
deblasis Sep 20, 2022
5505933
refactor(Config): runtime module and InitializableModule interface
deblasis Sep 20, 2022
cfc88c2
feat(Config): useRandomPK in runtime
deblasis Sep 20, 2022
39f4a9d
refactor(Config): renamed Builder / updated signatures
deblasis Sep 20, 2022
1160ab9
style(Config): builder -> runtime
deblasis Sep 20, 2022
9283f64
feat(Config): implement InitlializableModule in all modules
deblasis Sep 20, 2022
8bfaafe
fix(Consensus): remove pacemakerConfig from interface
deblasis Sep 20, 2022
37f12f9
feat(Config): params/flags injection (stab @private key for CLI)
deblasis Sep 20, 2022
2fec88b
style(Client): cleanup
deblasis Sep 21, 2022
25979e3
feat(Shared): ConfigurableModule and GenesisDependentModule 👀
deblasis Sep 21, 2022
e289d3a
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Sep 21, 2022
ba15b7c
chore(go.mod): tidy
deblasis Sep 21, 2022
7c5b943
feat(Shared): KeyholderModule 👀
deblasis Sep 21, 2022
49980dc
fix(Shared): Enforcing for all modules
deblasis Sep 21, 2022
69af7f1
refactor(Runtime): renamed b to rc
deblasis Sep 21, 2022
56be675
style(Shared): renamed moduleCfg to moduleNameCfg
deblasis Sep 21, 2022
d071c13
Merge branch 'main' into issue/config_genesis_refactoring1
deblasis Sep 22, 2022
cb863cf
fix(SHARED): build error for importing unnecessary package
deblasis Sep 26, 2022
eb25f35
Update shared/modules/runtime_module.go
deblasis Sep 26, 2022
c3ac3cc
refactor(runtime): renamed RuntimeConfig -> runtimeConfig
deblasis Sep 26, 2022
66b4806
fix(runtime): improved WithRandomPK()
deblasis Sep 26, 2022
d4c1a18
Merge branch 'issue/config_genesis_refactoring1' of github.com:deblas…
deblasis Sep 26, 2022
8318c20
docs(runtime): // RuntimeConfig option helpers comment
deblasis Sep 26, 2022
d663287
refactor(Shared): nodeModule, P2PAddressableModule
deblasis Sep 26, 2022
9e5602b
refactor(Consensus): interface embedding
deblasis Sep 26, 2022
fb873b6
refactor(Consensus): consistency in naming
deblasis Sep 26, 2022
8d26fd3
refactor(Persistence): consistence in naming
deblasis Sep 26, 2022
dd78b2e
feat(P2P): P2P module now implements ConfigurableModule
deblasis Sep 26, 2022
c6c95dd
fix(Persistence): improved DEBUG_CLEAR_STATE
deblasis Sep 26, 2022
c020f2e
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Sep 26, 2022
f5ea7e4
feat(Shared): modules implement ConfigurableModule
deblasis Sep 27, 2022
c60206f
refactor(Shared): consistency: adding config *structType in modules
deblasis Sep 27, 2022
b86c4bb
Update consensus/module.go
deblasis Sep 27, 2022
3f93930
fix(Runtime): fix WithPK for when called with a nil P2PConfig
deblasis Sep 27, 2022
382eacf
fix(Shared): bus creation via runtime
deblasis Sep 28, 2022
45a5491
refactor(Shared): NewWithAddress -> NewNodeWithAddress
deblasis Sep 28, 2022
843f5f7
refactor(Shared): improved Create, making all modules unexported
deblasis Sep 28, 2022
2fa9eb8
refactor(Consensus): consistency in naming paceMaker
deblasis Sep 28, 2022
b244e17
refactor(Shared): runtime -> runtimeCfg
deblasis Sep 28, 2022
1924e0e
refactor(Shared): code review feedback
deblasis Sep 29, 2022
1611486
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Sep 29, 2022
281bb4d
fix(Shared): bugfixes
deblasis Sep 29, 2022
bd6ee3a
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Sep 29, 2022
7f6d428
fix(Consensus): merge fix
deblasis Sep 29, 2022
f0a7c7d
test(Consensus): fixed tests (StoreBlock and InsertBlock mocks cfg)
deblasis Sep 29, 2022
2837b5a
fix(Shared): removed config and genesis from bus
deblasis Sep 29, 2022
3af1aa9
style(Runtime): cleanup
deblasis Sep 29, 2022
a8530d2
style(Runtime): import alias
deblasis Sep 29, 2022
2a686db
fix(Shared): module creation failures returns err
deblasis Sep 29, 2022
fbe4a7f
refactor(Persistence): reverted converters to shared
deblasis Sep 29, 2022
d532c30
feat(Tooling): check_cross_module_imports makefile target
deblasis Sep 29, 2022
deaf36d
style(Runtime): import names
deblasis Sep 29, 2022
2a2aaa3
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Sep 30, 2022
704ff71
refactor(Shared): refactored clock to be sourced from runtimeMgr
deblasis Sep 30, 2022
8601df9
fix(Makefile): excluding makefile!
deblasis Sep 30, 2022
72f6c90
feat(Tooling): improved check_cross_module_imports
deblasis Sep 30, 2022
dee736c
docs(Shared): Updated README and CHANGELOGs
deblasis Sep 30, 2022
fa07890
docs(Runtime): missing items
deblasis Sep 30, 2022
1bfa974
test(Persistence): Tests: added missing mock configuration
deblasis Oct 3, 2022
eb392de
Merge branch 'issue/262-persistence-failing-tests' into issue/config_…
deblasis Oct 3, 2022
c04500a
fix(Tooling): execute tests sequentially fix (wrong syntax)
deblasis Oct 3, 2022
0fac63e
Merge branch 'issue/262-persistence-failing-tests' into issue/config_…
deblasis Oct 3, 2022
4955d08
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Oct 4, 2022
eaf5fd3
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Oct 4, 2022
902c524
style(Makefile): check_cross_module_imports
deblasis Oct 4, 2022
9985381
Update app/client/main.go
deblasis Oct 4, 2022
bfea53d
refactor(Consensus): keys -> validatorKeys
deblasis Oct 4, 2022
d14aedb
Update consensus/consensus_tests/utils_test.go
deblasis Oct 4, 2022
b460e5d
Merge branch 'issue/config_genesis_refactoring1' of github.com:deblas…
deblasis Oct 4, 2022
59df167
Update consensus/consensus_tests/utils_test.go
deblasis Oct 4, 2022
50090d1
refactor(Consensu): NewNodeWithAddress -> NewNodeWithP2PAddress
deblasis Oct 4, 2022
fe3a4c7
fix(Makefile): revert silent
deblasis Oct 4, 2022
eff5c0c
style(Shared): init var before return
deblasis Oct 4, 2022
8182b82
Update shared/test_artifacts/generator.go
deblasis Oct 4, 2022
ae97b03
Update utility/test/module_test.go
deblasis Oct 4, 2022
225fa53
Merge branch 'issue/config_genesis_refactoring1' of github.com:deblas…
deblasis Oct 4, 2022
6f25100
Update consensus/module.go
deblasis Oct 4, 2022
8ea9355
Update consensus/types/converters.go
deblasis Oct 4, 2022
5657b41
refactor(Consensus): s/ActorListToMap/ActorListToValidatorMap
deblasis Oct 4, 2022
0aabc23
Update consensus/types/converters.go
deblasis Oct 4, 2022
cd1a34f
Merge branch 'issue/config_genesis_refactoring1' of github.com:deblas…
deblasis Oct 4, 2022
f7ffe6e
fix(Consensus): converters fix
deblasis Oct 4, 2022
25a8607
refactor(Shared): preallocations
deblasis Oct 4, 2022
fb07ed3
docs(Shared): nits
deblasis Oct 4, 2022
f9f3c1c
style(Persistence): cleanup
deblasis Oct 4, 2022
2c078af
Update shared/modules/module.go
deblasis Oct 4, 2022
30af85d
fix(Telemetry): error management
deblasis Oct 4, 2022
05762ea
Update shared/modules/module.go
deblasis Oct 4, 2022
4d62f3f
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Oct 6, 2022
8061a4c
style(P2P): renamed p2pCfg
deblasis Oct 6, 2022
c780a5f
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Oct 6, 2022
96826d0
Merge remote-tracking branch 'upstream/main' into issue/config_genesi…
deblasis Oct 12, 2022
85bb1cf
fix(Tooling): reverted a line change introduced in #282
deblasis Oct 12, 2022
7508fd2
refactor(Shared): modules use interfaces for config and genesis
deblasis Oct 12, 2022
516f0ea
refactor(Shared): using interfaces vs structs
deblasis Oct 12, 2022
7352d39
style(Shared): formatting
deblasis Oct 12, 2022
9664cba
style(Consensus): cleanup
deblasis Oct 12, 2022
1c482af
docs(Runtime): NewManagerFromReaders comment
deblasis Oct 12, 2022
a8909bb
refactor(Shared): shared.test_artifacts -> runtime.test_artifacts
deblasis Oct 12, 2022
5b54619
fix(Persistence): leftover casts
deblasis Oct 12, 2022
d38b0e1
refactor(Shared): removed NodeModule
deblasis Oct 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,25 @@ gen_genesis_and_config:
## Clear the genesis and config files for LocalNet
clear_genesis_and_config:
rm build/config/gen.*.json

.PHONY: check_cross_module_imports
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
## Lists cross-module imports
check_cross_module_imports:
deblasis marked this conversation as resolved.
Show resolved Hide resolved
$(eval exclude_common=--exclude=Makefile --exclude-dir=shared --exclude-dir=app --exclude-dir=runtime)
echo "persistence:\n"
grep ${exclude_common} --exclude-dir=persistence -r "github.com/pokt-network/pocket/persistence" || echo "✅ OK!"
echo "-----------------------"
echo "utility:\n"
grep ${exclude_common} --exclude-dir=utility -r "github.com/pokt-network/pocket/utility" || echo "✅ OK!"
echo "-----------------------"
echo "consensus:\n"
grep ${exclude_common} --exclude-dir=consensus -r "github.com/pokt-network/pocket/consensus" || echo "✅ OK!"
echo "-----------------------"
echo "telemetry:\n"
grep ${exclude_common} --exclude-dir=telemetry -r "github.com/pokt-network/pocket/telemetry" || echo "✅ OK!"
echo "-----------------------"
echo "p2p:\n"
grep ${exclude_common} --exclude-dir=p2p -r "github.com/pokt-network/pocket/p2p" || echo "✅ OK!"
echo "-----------------------"
echo "runtime:\n"
grep ${exclude_common} --exclude-dir=runtime -r "github.com/pokt-network/pocket/runtime" || echo "✅ OK!"
17 changes: 13 additions & 4 deletions app/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"

"github.com/pokt-network/pocket/runtime"
"github.com/pokt-network/pocket/shared/debug"
"github.com/pokt-network/pocket/telemetry"

Expand Down Expand Up @@ -47,24 +48,32 @@ var consensusMod modules.ConsensusModule

func main() {
var err error
consensusMod, err = consensus.Create(defaultConfigPath, defaultGenesisPath, true) // TECHDEBT: extra param required for injecting private key hack for debug client

runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK())

consM, err := consensus.Create(runtimeMgr)
if err != nil {
log.Fatalf("[ERROR] Failed to create consensus module: %v", err.Error())
}
p2pMod, err = p2p.Create(defaultConfigPath, defaultGenesisPath, true) // TECHDEBT: extra param required for injecting private key hack for debug client
consensusMod = consM.(modules.ConsensusModule)

p2pM, err := p2p.Create(runtimeMgr)
if err != nil {
log.Fatalf("[ERROR] Failed to create p2p module: %v", err.Error())
}
p2pMod = p2pM.(modules.P2PModule)

// This telemetry module instance is a NOOP because the 'enable_telemetry' flag in the `cfg` above is set to false.
deblasis marked this conversation as resolved.
Show resolved Hide resolved
// Since this client mimics partial - networking only - functionality of a full node, some of the telemetry-related
// code paths are executed. To avoid those messages interfering with the telemetry data collected, a non-nil telemetry
// module that NOOPs (per the configs above) is injected.
telemetryMod, err := telemetry.Create(defaultConfigPath, defaultGenesisPath)
telemetryM, err := telemetry.Create(runtimeMgr)
if err != nil {
log.Fatalf("[ERROR] Failed to create NOOP telemetry module: " + err.Error())
}
telemetryMod := telemetryM.(modules.TelemetryModule)

_ = shared.CreateBusWithOptionalModules(nil, p2pMod, nil, consensusMod, telemetryMod)
_ = shared.CreateBusWithOptionalModules(runtimeMgr, nil, p2pMod, nil, consensusMod, telemetryMod)

p2pMod.Start()

Expand Down
2 changes: 1 addition & 1 deletion build/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"io/ioutil"

"github.com/pokt-network/pocket/shared/test_artifacts"
"github.com/pokt-network/pocket/runtime/test_artifacts"
)

// Utility to generate config and genesis files
Expand Down
9 changes: 9 additions & 0 deletions consensus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.6] - 2022-10-12

### [#235](https://github.com/pokt-network/pocket/pull/235) Config and genesis handling

- Updated to use `RuntimeMgr`
- Made `ConsensusModule` struct unexported
- Updated tests and mocks
- Removed some cross-module dependencies

## [0.0.0.5] - 2022-10-06

- Don't ignore the exit code of `m.Run()` in the unit tests
Expand Down
12 changes: 6 additions & 6 deletions consensus/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pokt-network/pocket/shared/codec"
)

func (m *ConsensusModule) commitBlock(block *typesCons.Block) error {
func (m *consensusModule) commitBlock(block *typesCons.Block) error {
m.nodeLog(typesCons.CommittingBlock(m.Height, len(block.Transactions)))

// Store the block in the KV store
Expand Down Expand Up @@ -41,7 +41,7 @@ func (m *ConsensusModule) commitBlock(block *typesCons.Block) error {
return nil
}

func (m *ConsensusModule) storeBlock(block *typesCons.Block, blockProtoBytes []byte) error {
func (m *consensusModule) storeBlock(block *typesCons.Block, blockProtoBytes []byte) error {
store := m.utilityContext.GetPersistenceContext()
// Store in KV Store
if err := store.StoreBlock(blockProtoBytes); err != nil {
Expand All @@ -57,7 +57,7 @@ func (m *ConsensusModule) storeBlock(block *typesCons.Block, blockProtoBytes []b
}

// TODO: Add unit tests specific to block validation
func (m *ConsensusModule) validateBlockBasic(block *typesCons.Block) error {
func (m *consensusModule) validateBlockBasic(block *typesCons.Block) error {
if block == nil && m.Step != NewRound {
return typesCons.ErrNilBlock
}
Expand All @@ -66,8 +66,8 @@ func (m *ConsensusModule) validateBlockBasic(block *typesCons.Block) error {
return typesCons.ErrBlockExists
}

if block != nil && unsafe.Sizeof(*block) > uintptr(m.consGenesis.MaxBlockBytes) {
return typesCons.ErrInvalidBlockSize(uint64(unsafe.Sizeof(*block)), m.consGenesis.MaxBlockBytes)
if block != nil && unsafe.Sizeof(*block) > uintptr(m.consGenesis.GetMaxBlockBytes()) {
return typesCons.ErrInvalidBlockSize(uint64(unsafe.Sizeof(*block)), m.consGenesis.GetMaxBlockBytes())
}

// If the current block being processed (i.e. voted on) by consensus is non nil, we need to make
Expand All @@ -84,7 +84,7 @@ func (m *ConsensusModule) validateBlockBasic(block *typesCons.Block) error {
}

// Creates a new Utility context and clears/nullifies any previous contexts if they exist
func (m *ConsensusModule) refreshUtilityContext() error {
func (m *consensusModule) refreshUtilityContext() error {
// Catch-all structure to release the previous utility context if it wasn't properly cleaned up.
// Ideally, this should not be called.
if m.utilityContext != nil {
Expand Down
6 changes: 3 additions & 3 deletions consensus/consensus_tests/hotstuff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import (
)

func TestHotstuff4Nodes1BlockHappyPath(t *testing.T) {
clockMock := clock.NewMock()
// Test configs
numNodes := 4
configs, genesisStates := GenerateNodeConfigs(t, numNodes)
runtimeMgrs := GenerateNodeRuntimeMgrs(t, numNodes, clockMock)

clockMock := clock.NewMock()
go timeReminder(clockMock, 100*time.Millisecond)

// Create & start test pocket nodes
testChannel := make(modules.EventsChannel, 100)
pocketNodes := CreateTestConsensusPocketNodes(t, configs, genesisStates, clockMock, testChannel)
pocketNodes := CreateTestConsensusPocketNodes(t, runtimeMgrs, testChannel)
StartAllTestPocketNodes(t, pocketNodes)

// Debug message to start consensus by triggering first view change
Expand Down
23 changes: 14 additions & 9 deletions consensus/consensus_tests/pacemaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ func TestTinyPacemakerTimeouts(t *testing.T) {
// Test configs
numNodes := 4
paceMakerTimeoutMsec := uint64(50) // Set a very small pacemaker timeout
paceMakerTimeout := 50 * timePkg.Millisecond
configs, genesisStates := GenerateNodeConfigs(t, numNodes)
for _, config := range configs {
config.Consensus.GetPaceMakerConfig().SetTimeoutMsec(paceMakerTimeoutMsec)
paceMakerTimeout := 50 * time.Millisecond
runtimeMgrs := GenerateNodeRuntimeMgrs(t, numNodes, clockMock)
for _, runtimeConfig := range runtimeMgrs {
if consCfg, ok := runtimeConfig.GetConfig().GetConsensusConfig().(consensus.HasPacemakerConfig); ok {
consCfg.GetPacemakerConfig().SetTimeoutMsec(paceMakerTimeoutMsec)
}
}

// Create & start test pocket nodes
testChannel := make(modules.EventsChannel, 100)
pocketNodes := CreateTestConsensusPocketNodes(t, configs, genesisStates, clockMock, testChannel)
pocketNodes := CreateTestConsensusPocketNodes(t, runtimeMgrs, testChannel)
StartAllTestPocketNodes(t, pocketNodes)

// Debug message to start consensus by triggering next view.
Expand Down Expand Up @@ -123,15 +125,15 @@ func TestTinyPacemakerTimeouts(t *testing.T) {
}

func TestPacemakerCatchupSameStepDifferentRounds(t *testing.T) {
clockMock := clock.NewMock()
numNodes := 4
configs, genesisStates := GenerateNodeConfigs(t, numNodes)
runtimeConfigs := GenerateNodeRuntimeMgrs(t, numNodes, clockMock)

clockMock := clock.NewMock()
timeReminder(clockMock, 100*time.Millisecond)

// Create & start test pocket nodes
testChannel := make(modules.EventsChannel, 100)
pocketNodes := CreateTestConsensusPocketNodes(t, configs, genesisStates, clockMock, testChannel)
pocketNodes := CreateTestConsensusPocketNodes(t, runtimeConfigs, testChannel)
StartAllTestPocketNodes(t, pocketNodes)

// Starting point
Expand All @@ -143,13 +145,16 @@ func TestPacemakerCatchupSameStepDifferentRounds(t *testing.T) {
leader := pocketNodes[leaderId]
leaderRound := uint64(6)

consensusPK, err := leader.GetBus().GetConsensusModule().GetPrivateKey()
require.NoError(t, err)

// Placeholder block
blockHeader := &typesCons.BlockHeader{
Height: int64(testHeight),
Hash: hex.EncodeToString(appHash),
NumTxs: 0,
LastBlockHash: "",
ProposerAddress: leader.Address.Bytes(),
ProposerAddress: consensusPK.Address(),
QuorumCertificate: nil,
}
block := &typesCons.Block{
Expand Down
Loading