Skip to content

Commit

Permalink
config fix
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed May 14, 2024
1 parent d53728c commit abf5bc2
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 37 deletions.
1 change: 0 additions & 1 deletion block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func TestInitialState(t *testing.T) {
ListenAddress: config.DefaultListenAddress,
GossipedBlocksCacheSize: 50,
BootstrapTime: 30 * time.Second,
AdvertisingEnabled: true,
}, privKey, "TestChain", pubsubServer, logger)
assert.NoError(err)
assert.NotNil(p2pClient)
Expand Down
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type NodeConfig struct {
// parameters below are translated from existing config
RootDir string
DBPath string
P2P P2PConfig
RPC RPCConfig
MempoolConfig tmcfg.MempoolConfig

Expand All @@ -38,6 +37,8 @@ type NodeConfig struct {
Instrumentation *InstrumentationConfig `mapstructure:"instrumentation"`
// Config params for mock grpc da
DAGrpc grpc.Config `mapstructure:",squash"`
//P2P Options
P2PConfig `mapstructure:",squash"`
}

// BlockManagerConfig consists of all parameters required by BlockManagerConfig
Expand Down Expand Up @@ -98,8 +99,8 @@ func (nc NodeConfig) Validate() error {
return fmt.Errorf("BlockManagerConfig: %w", err)
}

if err := nc.P2P.Validate(); err != nil {
return fmt.Errorf("BlockManagerConfig: %w", err)
if err := nc.P2PConfig.Validate(); err != nil {
return fmt.Errorf("P2PConfig: %w", err)
}

if err := nc.validateSettlementLayer(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func fullNodeConfig() config.NodeConfig {
Host: "localhost",
Port: 9090,
},
P2P: config.P2PConfig{
P2PConfig: config.P2PConfig{
GossipedBlocksCacheSize: 50,
BootstrapTime: 30 * time.Second,
ListenAddress: config.DefaultListenAddress,
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func DefaultConfig(home, chainId string) *NodeConfig {
Prometheus: false,
PrometheusListenAddr: ":2112",
},
P2P: P2PConfig{
P2PConfig: P2PConfig{
GossipedBlocksCacheSize: 50,
BootstrapTime: 30 * time.Second,
ListenAddress: DefaultListenAddress,
Expand Down
23 changes: 23 additions & 0 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const (
FlagRollappID = "dymint.settlement_config.rollapp_id"
)

const (
FlagP2PListenAddress = "dymint.p2p_config.listen_address"
FlagP2PBootstrapNodes = "dymint.p2p_config.bootstrap_nodes"
FlagP2PGossipCacheSize = "dymint.p2p_config.gossip_cache_size"
FlagP2PBootstrapTime = "dymint.p2p_config.bootstrap_time"
)

// AddNodeFlags adds Dymint specific configuration options to cobra Command.
//
// This function is called in cosmos-sdk.
Expand All @@ -54,6 +61,12 @@ func AddNodeFlags(cmd *cobra.Command) {
cmd.Flags().String(FlagSLGasPrices, def.SettlementConfig.GasPrices, "Settlement Layer gas prices")
cmd.Flags().Uint64(FlagSLGasLimit, def.SettlementConfig.GasLimit, "Settlement Layer batch submit gas limit")
cmd.Flags().String(FlagRollappID, def.SettlementConfig.RollappID, "The chainID of the rollapp")

cmd.Flags().String(FlagP2PListenAddress, def.P2PConfig.ListenAddress, "P2P listen address")
cmd.Flags().String(FlagP2PBootstrapNodes, def.P2PConfig.BootstrapNodes, "P2P bootstrap nodes")
cmd.Flags().Duration(FlagP2PBootstrapTime, def.P2PConfig.BootstrapTime, "P2P bootstrap time")
cmd.Flags().Uint64(FlagP2PGossipCacheSize, uint64(def.P2PConfig.GossipedBlocksCacheSize), "P2P Gossiped blocks cache size")

}

func BindDymintFlags(cmd *cobra.Command, v *viper.Viper) error {
Expand Down Expand Up @@ -105,5 +118,15 @@ func BindDymintFlags(cmd *cobra.Command, v *viper.Viper) error {
if err := v.BindPFlag("rollapp_id", cmd.Flags().Lookup(FlagRollappID)); err != nil {
return err
}
if err := v.BindPFlag("p2p_listen_address", cmd.Flags().Lookup(FlagP2PListenAddress)); err != nil {
return err
}
if err := v.BindPFlag("gossiped_blocks_cache_size", cmd.Flags().Lookup(FlagP2PGossipCacheSize)); err != nil {
return err
}
if err := v.BindPFlag("bootstrap_time", cmd.Flags().Lookup(FlagP2PBootstrapTime)); err != nil {
return err
}

return nil
}
10 changes: 3 additions & 7 deletions config/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ type P2PConfig struct {
BootstrapNodes string `mapstructure:"p2p_bootstrap_nodes"`
//Size of the Gossipsub router cache
GossipedBlocksCacheSize int `mapstructure:"gossiped_blocks_cache_size"`
//If true, the node is advertised in the DHT
AdvertisingEnabled bool `mapstructure:"advertising"`
//Time interval a node tries to bootstrap again, in case no nodes connected
BootstrapTime time.Duration `mapstructure:"bootstrap_time"`
}

// Validate BlockManagerConfig
// Validate P2PConfig
func (c P2PConfig) Validate() error {

if c.GossipedBlocksCacheSize < 0 {
return fmt.Errorf("gossipsub cache size cannot be negative.")
return fmt.Errorf("gossipsub cache size cannot be negative")
}

if c.BootstrapTime <= 0 {
return fmt.Errorf("bootstrap time must be positive.")
return fmt.Errorf("bootstrap time must be positive")
}
return nil
}
5 changes: 1 addition & 4 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,9 @@ da_config = "{{ .DAConfig }}"
# p2p listen address in the format of /ip4/ip_address/tcp/tcp_port
p2p_listen_address = "{{ .P2P.ListenAddress }}"
# list of nodes used for P2P bootstrapping
# list of nodes used for P2P bootstrapping in the format of /ip4/ip_address/tcp/port/p2p/ID
p2p_bootstrap_nodes = "{{ .P2P.BootstrapNodes }}"
# if not enabled, nodes will not advertised to other nodes to accept connections
advertising = "{{ .P2P.AdvertisingEnabled }}"
# max number of cached messages by gossipsub protocol
gossiped_blocks_cache_size = {{ .P2P.GossipedBlocksCacheSize }}
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func NewNode(
// Set p2p client and it's validators
p2pValidator := p2p.NewValidator(logger.With("module", "p2p_validator"), settlementlc)

p2pClient, err := p2p.NewClient(conf.P2P, p2pKey, genesis.ChainID, pubsubServer, logger.With("module", "p2p"))
p2pClient, err := p2p.NewClient(conf.P2PConfig, p2pKey, genesis.ChainID, pubsubServer, logger.With("module", "p2p"))
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ func TestMempoolDirectly(t *testing.T) {
nodeConfig := config.NodeConfig{
RootDir: "",
DBPath: "",
P2P: config.P2PConfig{
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
GossipedBlocksCacheSize: 50,
AdvertisingEnabled: true,
BootstrapTime: 30 * time.Second,
BootstrapNodes: "",
},
Expand Down
1 change: 0 additions & 1 deletion p2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func NewClient(conf config.P2PConfig, privKey crypto.PrivKey, chainID string, lo
func (c *Client) Start(ctx context.Context) error {
// create new, cancelable context
ctx, c.cancel = context.WithCancel(ctx)
c.logger.Debug("starting P2P client")
host, err := c.listen(ctx)
if err != nil {
return err
Expand Down
2 changes: 0 additions & 2 deletions p2p/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func TestClientStartup(t *testing.T) {
client, err := p2p.NewClient(config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
GossipedBlocksCacheSize: 50,
AdvertisingEnabled: true,
BootstrapTime: 30 * time.Second,
}, privKey, "TestChain", pubsubServer, log.TestingLogger())
assert := assert.New(t)
Expand Down Expand Up @@ -181,7 +180,6 @@ func TestSeedStringParsing(t *testing.T) {
logger := &testutil.MockLogger{}
client, err := p2p.NewClient(config.P2PConfig{
GossipedBlocksCacheSize: 50,
AdvertisingEnabled: true,
BootstrapTime: 30 * time.Second,
}, privKey, "TestNetwork", pubsubServer, logger)
require.NoError(err)
Expand Down
15 changes: 5 additions & 10 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ func TestGenesisChunked(t *testing.T) {
config := config.NodeConfig{
RootDir: "",
DBPath: "",
P2P: config.P2PConfig{
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
AdvertisingEnabled: true,
BootstrapNodes: "",
GossipedBlocksCacheSize: 50,
BootstrapTime: 30 * time.Second,
Expand Down Expand Up @@ -701,9 +700,8 @@ func TestValidatorSetHandling(t *testing.T) {
nodeConfig := config.NodeConfig{
DALayer: "mock",
SettlementLayer: "mock",
P2P: config.P2PConfig{
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
AdvertisingEnabled: true,
BootstrapNodes: "",
GossipedBlocksCacheSize: 50,
BootstrapTime: 30 * time.Second,
Expand Down Expand Up @@ -854,9 +852,8 @@ func getRPCInternal(t *testing.T, aggregator bool) (*tmmocks.MockApplication, *C
config := config.NodeConfig{
RootDir: "",
DBPath: "",
P2P: config.P2PConfig{
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
AdvertisingEnabled: true,
BootstrapNodes: "",
GossipedBlocksCacheSize: 50,
BootstrapTime: 30 * time.Second,
Expand Down Expand Up @@ -966,9 +963,8 @@ func TestMempool2Nodes(t *testing.T) {
ProposerPubKey: hex.EncodeToString(proposerPK),
RollappID: rollappID,
},
P2P: config.P2PConfig{
P2PConfig: config.P2PConfig{
ListenAddress: "/ip4/127.0.0.1/tcp/9001",
AdvertisingEnabled: true,
BootstrapNodes: "",
GossipedBlocksCacheSize: 50,
BootstrapTime: 30 * time.Second,
Expand Down Expand Up @@ -997,10 +993,9 @@ func TestMempool2Nodes(t *testing.T) {
BlockBatchMaxSizeBytes: 1000,
MaxSupportedBatchSkew: 10,
},
P2P: config.P2PConfig{
P2PConfig: config.P2PConfig{
ListenAddress: "/ip4/127.0.0.1/tcp/9002",
BootstrapNodes: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.String(),
AdvertisingEnabled: true,
BootstrapTime: 30 * time.Second,
GossipedBlocksCacheSize: 50,
},
Expand Down
3 changes: 1 addition & 2 deletions rpc/json/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,9 @@ func getRPC(t *testing.T) (*tmmocks.MockApplication, *client.Client) {
ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes),
RollappID: rollappID,
},
P2P: config.P2PConfig{
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
GossipedBlocksCacheSize: 50,
AdvertisingEnabled: true,
BootstrapTime: 30 * time.Second,
},
}
Expand Down
1 change: 0 additions & 1 deletion testutil/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func GetManagerWithProposerKey(conf config.BlockManagerConfig, proposerKey crypt
// Init p2p client and validator
p2pKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
p2pClient, err := p2p.NewClient(config.P2PConfig{
AdvertisingEnabled: true,
GossipedBlocksCacheSize: 50,
BootstrapTime: 30 * time.Second,
}, p2pKey, "TestChain", pubsubServer, logger)
Expand Down
1 change: 0 additions & 1 deletion testutil/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func StartTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]Hos
BootstrapNodes: seeds[i],
GossipedBlocksCacheSize: 50,
BootstrapTime: 30 * time.Second,
AdvertisingEnabled: true,
ListenAddress: config.DefaultListenAddress,
},
mnet.Hosts()[i].Peerstore().PrivKey(mnet.Hosts()[i].ID()),
Expand Down

0 comments on commit abf5bc2

Please sign in to comment.