diff --git a/Makefile b/Makefile index 68e04125f..9e0517d56 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) -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" 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 67c3ab30d..d21b56028 100644 --- a/runtime/configs/proto/p2p_config.proto +++ b/runtime/configs/proto/p2p_config.proto @@ -2,18 +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; } - -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; +} 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" diff --git a/runtime/docs/CHANGELOG.md b/runtime/docs/CHANGELOG.md index defd03ec0..6d6c0457d 100644 --- a/runtime/docs/CHANGELOG.md +++ b/runtime/docs/CHANGELOG.md @@ -7,10 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [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` 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,