From 33aaafd1e4bd1920ee4ac52f849608d5b0197ba5 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 19 Jan 2023 20:11:51 +0100 Subject: [PATCH 1/7] refactor: move ConnectionType to avoid cyclic import --- runtime/configs/proto/p2p_config.proto | 5 ----- runtime/configs/types/proto/connection.proto | 10 ++++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 runtime/configs/types/proto/connection.proto diff --git a/runtime/configs/proto/p2p_config.proto b/runtime/configs/proto/p2p_config.proto index 67c3ab30d..96bd65fd4 100644 --- a/runtime/configs/proto/p2p_config.proto +++ b/runtime/configs/proto/p2p_config.proto @@ -12,8 +12,3 @@ message P2PConfig { uint64 max_mempool_count = 5; // this is used to limit the number of nonces that can be stored in the mempool, after which a FIFO mechanism is used to remove the oldest nonces and make space for the new ones bool is_client_only = 6; } - -enum ConnectionType { - EmptyConnection = 0; - TCPConnection = 1; -} diff --git a/runtime/configs/types/proto/connection.proto b/runtime/configs/types/proto/connection.proto new file mode 100644 index 000000000..f4fbe76c6 --- /dev/null +++ b/runtime/configs/types/proto/connection.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package conn; + +option go_package = "github.com/pokt-network/pocket/runtime/configs/types"; + +enum ConnectionType { + EmptyConnection = 0; + TCPConnection = 1; +} From 9addbb03435d232a188a7ae11dff6fbc945827e6 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 19 Jan 2023 20:15:21 +0100 Subject: [PATCH 2/7] chore: update makefile --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3359c3741..2956afd9d 100644 --- a/Makefile +++ b/Makefile @@ -244,7 +244,8 @@ protogen_local: go_protoc-go-inject-tag ## Generate go structures for all of the $(PROTOC) -I=./shared/codec/proto --go_out=./shared/codec ./shared/codec/proto/*.proto # Runtime - $(PROTOC_SHARED) -I=./runtime/configs/proto --go_out=./runtime/configs ./runtime/configs/proto/*.proto + protoc --go_opt=paths=source_relative -I=./runtime/configs/types/proto --go_out=./runtime/configs/types ./runtime/configs/types/proto/*.proto --experimental_allow_proto3_optional + protoc --go_opt=paths=source_relative -I=./runtime/configs/proto -I=./runtime/configs/types/proto --go_out=./runtime/configs ./runtime/configs/proto/*.proto --experimental_allow_proto3_optional $(PROTOC_SHARED) -I=./runtime/genesis/proto --go_out=./runtime/genesis ./runtime/genesis/proto/*.proto protoc-go-inject-tag -input="./runtime/genesis/*.pb.go" From 0b792c7edf36861224190447311c640f86ed524a Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 19 Jan 2023 20:27:14 +0100 Subject: [PATCH 3/7] chore: replace `P2PConfig#IsEmptyConnectionType` with `P2PConfig#ConnectionType` --- p2p/CHANGELOG.md | 5 ++++- p2p/transport/transport.go | 17 +++++++++-------- p2p/utils_test.go | 9 +++++---- runtime/configs/config.go | 8 ++++---- runtime/configs/proto/p2p_config.proto | 4 +++- runtime/docs/CHANGELOG.md | 7 +++++++ runtime/manager_test.go | 21 +++++++++++---------- 7 files changed, 43 insertions(+), 28 deletions(-) diff --git a/p2p/CHANGELOG.md b/p2p/CHANGELOG.md index 27691f8fe..c6fdd1a10 100644 --- a/p2p/CHANGELOG.md +++ b/p2p/CHANGELOG.md @@ -7,10 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.20] - 2023-01-20 + +- Updated `P2PConfig#IsEmptyConnectionType` bool to `P2PConfig#ConnectionType` enum + ## [0.0.0.19] - 2023-01-19 - Rewrite `interface{}` to `any` - ## [0.0.0.18] - 2023-01-11 - Add a lock to the mempool to avoid parallel messages which has caused the node to crash in the past diff --git a/p2p/transport/transport.go b/p2p/transport/transport.go index 8943224cb..5580712e2 100644 --- a/p2p/transport/transport.go +++ b/p2p/transport/transport.go @@ -2,6 +2,7 @@ package transport import ( "fmt" + types "github.com/pokt-network/pocket/runtime/configs/types" "io/ioutil" "net" @@ -14,24 +15,24 @@ const ( ) func CreateListener(cfg *configs.P2PConfig) (typesP2P.Transport, error) { - switch cfg.IsEmptyConnectionType { // TECHDEBT kept in switch format because this should be an enum not a bool - case true: + switch cfg.ConnectionType { + case types.ConnectionType_EmptyConnection: return createEmptyListener(cfg) - case false: + case types.ConnectionType_TCPConnection: return createTCPListener(cfg) default: - return nil, fmt.Errorf("unsupported connection type for listener: %v", cfg.IsEmptyConnectionType) + return nil, fmt.Errorf("unsupported connection type for listener: %v", cfg.ConnectionType) } } func CreateDialer(cfg *configs.P2PConfig, url string) (typesP2P.Transport, error) { - switch cfg.IsEmptyConnectionType { - case true: + switch cfg.ConnectionType { + case types.ConnectionType_EmptyConnection: return createEmptyDialer(cfg, url) - case false: + case types.ConnectionType_TCPConnection: return createTCPDialer(cfg, url) default: - return nil, fmt.Errorf("unsupported connection type for dialer: %v", cfg.IsEmptyConnectionType) + return nil, fmt.Errorf("unsupported connection type for dialer: %v", cfg.ConnectionType) } } diff --git a/p2p/utils_test.go b/p2p/utils_test.go index 653be9ac3..4fa9994e8 100644 --- a/p2p/utils_test.go +++ b/p2p/utils_test.go @@ -4,6 +4,7 @@ import ( "crypto/ed25519" "encoding/binary" "fmt" + types "github.com/pokt-network/pocket/runtime/configs/types" "log" "sort" "sync" @@ -121,10 +122,10 @@ func createMockRuntimeMgrs(t *testing.T, numValidators int) []modules.RuntimeMgr RootDirectory: "", PrivateKey: valKeys[i].String(), P2P: &configs.P2PConfig{ - PrivateKey: valKeys[i].String(), - ConsensusPort: 8080, - UseRainTree: true, - IsEmptyConnectionType: true, + PrivateKey: valKeys[i].String(), + ConsensusPort: 8080, + UseRainTree: true, + ConnectionType: types.ConnectionType_EmptyConnection, }, } diff --git a/runtime/configs/config.go b/runtime/configs/config.go index ea0d0529f..21e18ea5f 100644 --- a/runtime/configs/config.go +++ b/runtime/configs/config.go @@ -36,10 +36,10 @@ func NewDefaultConfig(options ...func(*Config)) *Config { BlockStorePath: defaults.DefaultPersistenceBlockStorePath, }, P2P: &P2PConfig{ - ConsensusPort: defaults.DefaultP2PConsensusPort, - UseRainTree: defaults.DefaultP2PUseRainTree, - IsEmptyConnectionType: defaults.DefaultP2PIsEmptyConnectionType, - MaxMempoolCount: defaults.DefaultP2PMaxMempoolCount, + ConsensusPort: defaults.DefaultP2PConsensusPort, + UseRainTree: defaults.DefaultP2PUseRainTree, + ConnectionType: defaults.DefaultP2PConnectionType, + MaxMempoolCount: defaults.DefaultP2PMaxMempoolCount, }, Telemetry: &TelemetryConfig{ Enabled: defaults.DefaultTelemetryEnabled, diff --git a/runtime/configs/proto/p2p_config.proto b/runtime/configs/proto/p2p_config.proto index 96bd65fd4..d21b56028 100644 --- a/runtime/configs/proto/p2p_config.proto +++ b/runtime/configs/proto/p2p_config.proto @@ -2,13 +2,15 @@ syntax = "proto3"; package configs; +import "connection.proto"; + option go_package = "github.com/pokt-network/pocket/runtime/configs"; message P2PConfig { string private_key = 1; uint32 consensus_port = 2; bool use_rain_tree = 3; - bool is_empty_connection_type = 4; // TODO: Switch back to enum + conn.ConnectionType connection_type = 4; uint64 max_mempool_count = 5; // this is used to limit the number of nonces that can be stored in the mempool, after which a FIFO mechanism is used to remove the oldest nonces and make space for the new ones bool is_client_only = 6; } diff --git a/runtime/docs/CHANGELOG.md b/runtime/docs/CHANGELOG.md index 0d0dd6fb3..9cf4ec34b 100644 --- a/runtime/docs/CHANGELOG.md +++ b/runtime/docs/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.9] - 2023-01-20 + +- move ConnectionType enum into its own package to avoid a cyclic import between configs and defaults packages (i.e. configs -> defaults -> configs) in the resulting, generated go package +- update makefile protogen_local target to build additional proto file and include it in the import path for runtime/configs/proto/p2p_config.proto +- replace `P2PConfig#IsEmptyConnectionType` bool with `P2PConfig#ConnectionType` enum +- replace `DefaultP2PIsEmptyConnectionType` bool with `DefaultP2PConnectionType` enum + ## [0.0.0.8] - 2023-01-19 - Rewrite `interface{}` to `any` diff --git a/runtime/manager_test.go b/runtime/manager_test.go index 8bdc12fd3..4dbdf9283 100644 --- a/runtime/manager_test.go +++ b/runtime/manager_test.go @@ -8,6 +8,7 @@ import ( "github.com/benbjohnson/clock" "github.com/pokt-network/pocket/runtime/configs" + configTypes "github.com/pokt-network/pocket/runtime/configs/types" "github.com/pokt-network/pocket/runtime/defaults" "github.com/pokt-network/pocket/runtime/genesis" "github.com/pokt-network/pocket/runtime/test_artifacts" @@ -226,11 +227,11 @@ func TestNewManagerFromReaders(t *testing.T) { HealthCheckPeriod: "5m", }, P2P: &configs.P2PConfig{ - PrivateKey: "c6c136d010d07d7f5e9944aa3594a10f9210dd3e26ebc1bc1516a6d957fd0df353ee26c82826694ffe1773d7b60d5f20dd9e91bdf8745544711bec5ff9c6fb4a", - ConsensusPort: 8080, - UseRainTree: true, - IsEmptyConnectionType: false, - MaxMempoolCount: 1e5, + PrivateKey: "c6c136d010d07d7f5e9944aa3594a10f9210dd3e26ebc1bc1516a6d957fd0df353ee26c82826694ffe1773d7b60d5f20dd9e91bdf8745544711bec5ff9c6fb4a", + ConsensusPort: 8080, + UseRainTree: true, + ConnectionType: configTypes.ConnectionType_TCPConnection, + MaxMempoolCount: 1e5, }, Telemetry: &configs.TelemetryConfig{ Enabled: true, @@ -272,11 +273,11 @@ func TestNewManagerFromReaders(t *testing.T) { want: &Manager{ config: &configs.Config{ P2P: &configs.P2PConfig{ - PrivateKey: "6fd0bc54cc2dd205eaf226eebdb0451629b321f11d279013ce6fdd5a33059256b2eda2232ffb2750bf761141f70f75a03a025f65b2b2b417c7f8b3c9ca91e8e4", - ConsensusPort: 8080, - UseRainTree: true, - IsEmptyConnectionType: false, - MaxMempoolCount: defaults.DefaultP2PMaxMempoolCount, + PrivateKey: "6fd0bc54cc2dd205eaf226eebdb0451629b321f11d279013ce6fdd5a33059256b2eda2232ffb2750bf761141f70f75a03a025f65b2b2b417c7f8b3c9ca91e8e4", + ConsensusPort: 8080, + UseRainTree: true, + ConnectionType: configTypes.ConnectionType_TCPConnection, + MaxMempoolCount: defaults.DefaultP2PMaxMempoolCount, }, }, genesisState: expectedGenesis, From 0fa1cd7665db0106427e128bf7f12de06d36306b Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 19 Jan 2023 20:27:37 +0100 Subject: [PATCH 4/7] chore: replace DefaultIsEmptyConnectionType with DefaultConnectionType --- runtime/defaults/defaults.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/runtime/defaults/defaults.go b/runtime/defaults/defaults.go index 35a4bebd9..f83bdf815 100644 --- a/runtime/defaults/defaults.go +++ b/runtime/defaults/defaults.go @@ -2,6 +2,8 @@ package defaults import ( "fmt" + + types "github.com/pokt-network/pocket/runtime/configs/types" ) const ( @@ -27,10 +29,10 @@ var ( DefaultPersistencePostgresUrl = "postgres://postgres:postgres@pocket-db:5432/postgres" DefaultPersistenceBlockStorePath = "/var/blockstore" // p2p - DefaultP2PConsensusPort = uint32(8080) - DefaultP2PUseRainTree = true - DefaultP2PIsEmptyConnectionType = false - DefaultP2PMaxMempoolCount = uint64(1e5) + DefaultP2PConsensusPort = uint32(8080) + DefaultP2PUseRainTree = true + DefaultP2PConnectionType = types.ConnectionType_TCPConnection + DefaultP2PMaxMempoolCount = uint64(1e5) // telemetry DefaultTelemetryEnabled = true DefaultTelemetryAddress = "0.0.0.0:9000" From 49c177b1d378697e70cc5ac3219f75ca2d16ba82 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 23 Jan 2023 10:10:05 +0100 Subject: [PATCH 5/7] fix: use PROTOC_SHARED in makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2956afd9d..b754ce85c 100644 --- a/Makefile +++ b/Makefile @@ -244,8 +244,8 @@ protogen_local: go_protoc-go-inject-tag ## Generate go structures for all of the $(PROTOC) -I=./shared/codec/proto --go_out=./shared/codec ./shared/codec/proto/*.proto # Runtime - protoc --go_opt=paths=source_relative -I=./runtime/configs/types/proto --go_out=./runtime/configs/types ./runtime/configs/types/proto/*.proto --experimental_allow_proto3_optional - protoc --go_opt=paths=source_relative -I=./runtime/configs/proto -I=./runtime/configs/types/proto --go_out=./runtime/configs ./runtime/configs/proto/*.proto --experimental_allow_proto3_optional + $(PROTOC) --go_opt=paths=source_relative -I=./runtime/configs/types/proto --go_out=./runtime/configs/types ./runtime/configs/types/proto/*.proto --experimental_allow_proto3_optional + $(PROTOC) --go_opt=paths=source_relative -I=./runtime/configs/proto -I=./runtime/configs/types/proto --go_out=./runtime/configs ./runtime/configs/proto/*.proto --experimental_allow_proto3_optional $(PROTOC_SHARED) -I=./runtime/genesis/proto --go_out=./runtime/genesis ./runtime/genesis/proto/*.proto protoc-go-inject-tag -input="./runtime/genesis/*.pb.go" From 246e670e40c4d24ece72199fc426917d0741177b Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 24 Jan 2023 09:14:20 +0100 Subject: [PATCH 6/7] chore: remove redundant protoc args Co-authored-by: Daniel Olshansky --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b754ce85c..ea170b5b7 100644 --- a/Makefile +++ b/Makefile @@ -244,8 +244,8 @@ protogen_local: go_protoc-go-inject-tag ## Generate go structures for all of the $(PROTOC) -I=./shared/codec/proto --go_out=./shared/codec ./shared/codec/proto/*.proto # Runtime - $(PROTOC) --go_opt=paths=source_relative -I=./runtime/configs/types/proto --go_out=./runtime/configs/types ./runtime/configs/types/proto/*.proto --experimental_allow_proto3_optional - $(PROTOC) --go_opt=paths=source_relative -I=./runtime/configs/proto -I=./runtime/configs/types/proto --go_out=./runtime/configs ./runtime/configs/proto/*.proto --experimental_allow_proto3_optional + $(PROTOC) -I=./runtime/configs/types/proto --go_out=./runtime/configs/types ./runtime/configs/types/proto/*.proto + $(PROTOC) -I=./runtime/configs/proto -I=./runtime/configs/types/proto --go_out=./runtime/configs ./runtime/configs/proto/*.proto $(PROTOC_SHARED) -I=./runtime/genesis/proto --go_out=./runtime/genesis ./runtime/genesis/proto/*.proto protoc-go-inject-tag -input="./runtime/genesis/*.pb.go" From 5dfadfd11c69880bfb3aea5ea8026c860a81fb93 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 25 Jan 2023 18:48:03 +0100 Subject: [PATCH 7/7] fix: revert unreleased version numbers & push date Co-authored-by: Daniel Olshansky --- runtime/docs/CHANGELOG.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/runtime/docs/CHANGELOG.md b/runtime/docs/CHANGELOG.md index ed84e14ab..6d6c0457d 100644 --- a/runtime/docs/CHANGELOG.md +++ b/runtime/docs/CHANGELOG.md @@ -7,17 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.0.0.10] - 2023-01-23 - -- Updated README.md with information about node profiling - -## [0.0.0.9] - 2023-01-20 +## [0.0.0.10] - 2023-01-25 - move ConnectionType enum into its own package to avoid a cyclic import between configs and defaults packages (i.e. configs -> defaults -> configs) in the resulting, generated go package - update makefile protogen_local target to build additional proto file and include it in the import path for runtime/configs/proto/p2p_config.proto - replace `P2PConfig#IsEmptyConnectionType` bool with `P2PConfig#ConnectionType` enum - replace `DefaultP2PIsEmptyConnectionType` bool with `DefaultP2PConnectionType` enum +## [0.0.0.9] - 2023-01-23 + +- Updated README.md with information about node profiling ## [0.0.0.8] - 2023-01-19 - Rewrite `interface{}` to `any`