@@ -6,21 +6,23 @@ import (
66 "io/ioutil"
77 "log"
88 "os"
9+ "path/filepath"
910
1011 cryptoPocket "github.com/pokt-network/pocket/shared/crypto"
11- "github.com/pokt-network/pocket/shared/types/genesis"
1212)
1313
1414type Config struct {
15- RootDir string `json:"root_dir"`
16- GenesisSource * genesis. GenesisSource `json:"genesis_source "` // TECHDEBT (olshansky): we should be able to pass the struct in here.
15+ RootDir string `json:"root_dir"`
16+ Genesis string `json:"genesis "` // FIXME (olshansky): we should be able to pass the struct in here.
1717
18- EnableTelemetry bool `json:"enable_telemetry"`
19- PrivateKey cryptoPocket.Ed25519PrivateKey `json:"private_key"`
18+ PrivateKey cryptoPocket.Ed25519PrivateKey `json:"private_key"`
2019
21- P2P * P2PConfig `json:"p2p"`
22- Consensus * ConsensusConfig `json:"consensus"`
23- // TECHDEBT(team): Consolidate `Persistence` and `PrePersistence`
20+ EnableTelemetry bool `json:"enable_telemetry"`
21+ GlobalLogLevel string `json:"global_log_level"`
22+
23+ Pre2P * Pre2PConfig `json:"pre2p"` // TECHDEBT(team): consolidate/replace this with P2P configs depending on next steps
24+ P2P * P2PConfig `json:"p2p"`
25+ Consensus * ConsensusConfig `json:"consensus"`
2426 PrePersistence * PrePersistenceConfig `json:"pre_persistence"`
2527 Persistence * PersistenceConfig `json:"persistence"`
2628 Utility * UtilityConfig `json:"utility"`
@@ -35,16 +37,33 @@ const (
3537)
3638
3739// TECHDEBT(team): consolidate/replace this with P2P configs depending on next steps
38- type P2PConfig struct {
40+ type Pre2PConfig struct {
3941 ConsensusPort uint32 `json:"consensus_port"`
4042 UseRainTree bool `json:"use_raintree"`
4143 ConnectionType ConnectionType `json:"connection_type"`
44+ LogLevel string `json:"log_level"`
4245}
4346
4447type PrePersistenceConfig struct {
45- Capacity int `json:"capacity"`
46- MempoolMaxBytes int `json:"mempool_max_bytes"`
47- MempoolMaxTxs int `json:"mempool_max_txs"`
48+ Capacity int `json:"capacity"`
49+ MempoolMaxBytes int `json:"mempool_max_bytes"`
50+ MempoolMaxTxs int `json:"mempool_max_txs"`
51+ LogLevel string `json:"log_level"`
52+ }
53+
54+ type P2PConfig struct {
55+ Protocol string `json:"protocol"`
56+ Address string `json:"address"`
57+ // TODO(derrandz): Fix the config imports appropriately
58+ // Address cryptoPocket.Address `json:"address"`
59+ ExternalIp string `json:"external_ip"`
60+ Peers []string `json:"peers"`
61+ MaxInbound uint32 `json:"max_inbound"`
62+ MaxOutbound uint32 `json:"max_outbound"`
63+ BufferSize uint `json:"connection_buffer_size"`
64+ WireHeaderLength uint `json:"max_wire_header_length"`
65+ TimeoutInMs uint `json:"timeout_in_ms"`
66+ LogLevel string `json:"log_level"`
4867}
4968
5069type PacemakerConfig struct {
@@ -62,20 +81,24 @@ type ConsensusConfig struct {
6281
6382 // Pacemaker
6483 Pacemaker * PacemakerConfig `json:"pacemaker"`
84+
85+ // The Log level for the consensus module
86+ LogLevel string `json:"log_level"`
6587}
6688
6789type PersistenceConfig struct {
68- PostgresUrl string `json:"postgres_url"`
69- NodeSchema string `json:"schema"`
70- BlockStorePath string `json:"block_store_path"`
90+ DataDir string `json:"datadir"`
91+ PostgresUrl string `json:"postgres_url"`
92+ NodeSchema string `json:"schema"`
93+ LogLevel string `json:"log_level"`
7194}
7295
7396type UtilityConfig struct {
7497}
7598
7699type TelemetryConfig struct {
77- Address string // The address the telemetry module will use to listen for metrics PULL requests (e.g. 0.0.0.0:9000 for prometheus)
78- Endpoint string // The endpoint available to fetch recorded metrics (e.g. /metrics for prometheus)
100+ Address string // The address that the telemetry module will use to listen for metrics pulling requests (e.g: 0.0.0.0:9000 for prometheus)
101+ Endpoint string // the endpoint that will be provided to scrapers to fetch recorded metrics (e.g: /metrics for prometheus)
79102}
80103
81104// TODO(insert tooling issue # here): Re-evaluate how load configs should be handeled.
@@ -103,35 +126,28 @@ func LoadConfig(file string) (c *Config) {
103126 return
104127}
105128
106- // TODO: Exhaust all the configuration validation checks
107129func (c * Config ) ValidateAndHydrate () error {
108130 if len (c .PrivateKey ) == 0 {
109131 return fmt .Errorf ("private key in config file cannot be empty" )
110132 }
111133
112- if c . GenesisSource == nil {
113- return fmt .Errorf ("genesis source cannot be nil in config " )
134+ if len ( c . Genesis ) == 0 {
135+ return fmt .Errorf ("must specify a genesis file or string " )
114136 }
137+ c .Genesis = rootify (c .Genesis , c .RootDir )
115138
116- if err := c .HydrateGenesisState (); err != nil {
117- return fmt . Errorf ( "error getting genesis state: %v " , err )
139+ if err := c .Consensus . ValidateAndHydrate (); err != nil {
140+ log . Fatalln ( "Error validating or completing consensus config: " , err )
118141 }
119142
120- if err := c .Consensus .ValidateAndHydrate (); err != nil {
121- return fmt . Errorf ( "error validating or completing consensus config: %v " , err )
143+ if err := c .P2P .ValidateAndHydrate (); err != nil {
144+ log . Fatalln ( "Error validating or completing P2P config: " , err )
122145 }
123146
124147 return nil
125148}
126149
127- func (c * Config ) HydrateGenesisState () error {
128- genesisState , err := genesis .GenesisStateFromGenesisSource (c .GenesisSource )
129- if err != nil {
130- return fmt .Errorf ("error getting genesis state: %v" , err )
131- }
132- c .GenesisSource .Source = & genesis.GenesisSource_State {
133- State : genesisState ,
134- }
150+ func (c * P2PConfig ) ValidateAndHydrate () error {
135151 return nil
136152}
137153
@@ -154,3 +170,11 @@ func (c *ConsensusConfig) ValidateAndHydrate() error {
154170func (c * PacemakerConfig ) ValidateAndHydrate () error {
155171 return nil
156172}
173+
174+ // Helper function to make config creation independent of root dir
175+ func rootify (path , root string ) string {
176+ if filepath .IsAbs (path ) {
177+ return path
178+ }
179+ return filepath .Join (root , path )
180+ }
0 commit comments