diff --git a/block/manager_test.go b/block/manager_test.go index 4c08adee6..4faef569a 100644 --- a/block/manager_test.go +++ b/block/manager_test.go @@ -53,8 +53,9 @@ func TestInitialState(t *testing.T) { // Init p2p client privKey, _, _ := crypto.GenerateEd25519Key(rand.Reader) p2pClient, err := p2p.NewClient(config.P2PConfig{ - GossipCacheSize: 50, - BoostrapTime: 30 * time.Second, + ListenAddress: config.DefaultListenAddress, + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, }, privKey, "TestChain", pubsubServer, logger) assert.NoError(err) assert.NotNil(p2pClient) diff --git a/block/submit_test.go b/block/submit_test.go index 881644f65..31667df46 100644 --- a/block/submit_test.go +++ b/block/submit_test.go @@ -122,12 +122,11 @@ func TestSubmissionByTime(t *testing.T) { // Init manager with empty blocks feature enabled managerConfig := config.BlockManagerConfig{ - BlockTime: blockTime, - MaxIdleTime: 0, - MaxSupportedBatchSkew: 10, - BatchSubmitMaxTime: submitTimeout, - BlockBatchMaxSizeBytes: 1000, - GossipedBlocksCacheSize: 50, + BlockTime: blockTime, + MaxIdleTime: 0, + MaxSupportedBatchSkew: 10, + BatchSubmitMaxTime: submitTimeout, + BlockBatchMaxSizeBytes: 1000, } manager, err := testutil.GetManager(managerConfig, nil, nil, 1, 1, 0, proxyApp, nil) diff --git a/config/config.go b/config/config.go index d2418e29e..9fbbae5e0 100644 --- a/config/config.go +++ b/config/config.go @@ -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 @@ -37,8 +36,9 @@ type NodeConfig struct { SettlementConfig settlement.Config `mapstructure:",squash"` Instrumentation *InstrumentationConfig `mapstructure:"instrumentation"` // Config params for mock grpc da - DAGrpc grpc.Config `mapstructure:",squash"` - BootstrapTime time.Duration `mapstructure:"bootstrap_time"` + DAGrpc grpc.Config `mapstructure:",squash"` + // P2P Options + P2PConfig `mapstructure:",squash"` } // BlockManagerConfig consists of all parameters required by BlockManagerConfig @@ -55,9 +55,8 @@ type BlockManagerConfig struct { MaxSupportedBatchSkew uint64 `mapstructure:"max_supported_batch_skew"` // The size of the batch in Bytes. Every batch we'll write to the DA and the settlement layer. BlockBatchMaxSizeBytes uint64 `mapstructure:"block_batch_max_size_bytes"` - // The number of messages cached by gossipsub protocol - GossipedBlocksCacheSize int `mapstructure:"gossiped_blocks_cache_size"` - NamespaceID string `mapstructure:"namespace_id"` + // Namespaceid included in the header (not used) + NamespaceID string `mapstructure:"namespace_id"` } // GetViperConfig reads configuration parameters from Viper instance. @@ -100,6 +99,10 @@ func (nc NodeConfig) Validate() error { return fmt.Errorf("BlockManagerConfig: %w", err) } + if err := nc.P2PConfig.Validate(); err != nil { + return fmt.Errorf("p2p config: %w", err) + } + if err := nc.validateSettlementLayer(); err != nil { return fmt.Errorf("SettlementLayer: %w", err) } @@ -150,10 +153,6 @@ func (c BlockManagerConfig) Validate() error { return fmt.Errorf("block_batch_size_bytes must be positive") } - if c.GossipedBlocksCacheSize <= 0 { - return fmt.Errorf("gossiped_blocks_cache_size must be positive") - } - if c.MaxSupportedBatchSkew <= 0 { return fmt.Errorf("max_supported_batch_skew must be positive") } diff --git a/config/config_test.go b/config/config_test.go index ab2e088bc..f8a06d8f1 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -89,12 +89,6 @@ func TestNodeConfig_Validate(t *testing.T) { nc.BlockManagerConfig.BlockBatchMaxSizeBytes = 0 }, wantErr: assert.Error, - }, { - name: "missing gossiped blocks cache size", - malleate: func(nc *config.NodeConfig) { - nc.BlockManagerConfig.GossipedBlocksCacheSize = 0 - }, - wantErr: assert.Error, }, { name: "empty settlement layer", malleate: func(nc *config.NodeConfig) { @@ -193,14 +187,13 @@ func TestNodeConfig_Validate(t *testing.T) { func fullNodeConfig() config.NodeConfig { return config.NodeConfig{ BlockManagerConfig: config.BlockManagerConfig{ - BlockTime: 1 * time.Second, - MaxIdleTime: 20 * time.Second, - MaxProofTime: 20 * time.Second, - BatchSubmitMaxTime: 20 * time.Second, - MaxSupportedBatchSkew: 10, - NamespaceID: "test", - BlockBatchMaxSizeBytes: 1, - GossipedBlocksCacheSize: 1, + BlockTime: 1 * time.Second, + MaxIdleTime: 20 * time.Second, + MaxProofTime: 20 * time.Second, + BatchSubmitMaxTime: 20 * time.Second, + MaxSupportedBatchSkew: 10, + NamespaceID: "test", + BlockBatchMaxSizeBytes: 1, }, DALayer: "celestia", DAConfig: "da-config", @@ -229,5 +222,11 @@ func fullNodeConfig() config.NodeConfig { Host: "localhost", Port: 9090, }, + P2PConfig: config.P2PConfig{ + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, + ListenAddress: config.DefaultListenAddress, + BootstrapNodes: "", + }, } } diff --git a/config/defaults.go b/config/defaults.go index ec3349579..40e0a6dc8 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -10,7 +10,7 @@ import ( const ( // DefaultListenAddress is a default listen address for P2P client. - DefaultListenAddress = "/ip4/0.0.0.0/tcp/7676" + DefaultListenAddress = "/ip4/0.0.0.0/tcp/26656" DefaultHomeDir = "sequencer_keys" DefaultChainID = "dymint-testnet" @@ -22,19 +22,14 @@ var DefaultNodeConfig = *DefaultConfig("", "") // DefaultConfig returns a default configuration for dymint node. func DefaultConfig(home, chainId string) *NodeConfig { cfg := &NodeConfig{ - P2P: P2PConfig{ - ListenAddress: DefaultListenAddress, - Seeds: "", - }, BlockManagerConfig: BlockManagerConfig{ - BlockTime: 200 * time.Millisecond, - MaxIdleTime: 3600 * time.Second, - MaxProofTime: 100 * time.Second, - BatchSubmitMaxTime: 3600 * time.Second, - MaxSupportedBatchSkew: 20, - NamespaceID: "0000000000000000ffff", - BlockBatchMaxSizeBytes: 500000, - GossipedBlocksCacheSize: 50, + BlockTime: 200 * time.Millisecond, + MaxIdleTime: 3600 * time.Second, + MaxProofTime: 100 * time.Second, + BatchSubmitMaxTime: 3600 * time.Second, + MaxSupportedBatchSkew: 20, + NamespaceID: "0000000000000000ffff", + BlockBatchMaxSizeBytes: 500000, }, DALayer: "mock", SettlementLayer: "mock", @@ -42,7 +37,12 @@ func DefaultConfig(home, chainId string) *NodeConfig { Prometheus: false, PrometheusListenAddr: ":2112", }, - BootstrapTime: 30 * time.Second, + P2PConfig: P2PConfig{ + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, + ListenAddress: DefaultListenAddress, + BootstrapNodes: "", + }, } if home == "" { diff --git a/config/flags.go b/config/flags.go index b775f21ef..d8470567b 100644 --- a/config/flags.go +++ b/config/flags.go @@ -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" + FlagP2PBootstrapRetryTime = "dymint.p2p_config.bootstrap_retry_time" +) + // AddNodeFlags adds Dymint specific configuration options to cobra Command. // // This function is called in cosmos-sdk. @@ -54,6 +61,11 @@ 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(FlagP2PBootstrapRetryTime, def.P2PConfig.BootstrapRetryTime, "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 { @@ -105,5 +117,18 @@ 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("p2p_gossiped_blocks_cache_size", cmd.Flags().Lookup(FlagP2PGossipCacheSize)); err != nil { + return err + } + if err := v.BindPFlag("p2p_bootstrap_retry_time", cmd.Flags().Lookup(FlagP2PBootstrapRetryTime)); err != nil { + return err + } + if err := v.BindPFlag("p2p_bootstrap_nodes", cmd.Flags().Lookup(FlagP2PBootstrapNodes)); err != nil { + return err + } + return nil } diff --git a/config/p2p.go b/config/p2p.go index c6c6e57d9..f679aeddc 100644 --- a/config/p2p.go +++ b/config/p2p.go @@ -1,11 +1,29 @@ package config -import "time" +import ( + "fmt" + "time" +) // P2PConfig stores configuration related to peer-to-peer networking. type P2PConfig struct { - ListenAddress string // Address to listen for incoming connections - Seeds string // Comma separated list of seed nodes to connect to - GossipCacheSize int - BoostrapTime time.Duration + // Listening address for P2P connections + ListenAddress string `mapstructure:"p2p_listen_address"` + // List of nodes used for P2P bootstrapping + BootstrapNodes string `mapstructure:"p2p_bootstrap_nodes"` + // Size of the Gossipsub router cache + GossipedBlocksCacheSize int `mapstructure:"p2p_gossiped_blocks_cache_size"` + // Time interval a node tries to bootstrap again, in case no nodes connected + BootstrapRetryTime time.Duration `mapstructure:"p2p_bootstrap_retry_time"` +} + +// Validate P2PConfig +func (c P2PConfig) Validate() error { + if c.GossipedBlocksCacheSize < 0 { + return fmt.Errorf("gossipsub cache size cannot be negative") + } + if c.BootstrapRetryTime <= 0 { + return fmt.Errorf("bootstrap time must be positive") + } + return nil } diff --git a/config/toml.go b/config/toml.go index 28dd23acb..88dea5582 100644 --- a/config/toml.go +++ b/config/toml.go @@ -86,11 +86,19 @@ namespace_id = "{{ .BlockManagerConfig.NamespaceID }}" da_config = "{{ .DAConfig }}" +### p2p config ### + +# p2p listen address in the format of /ip4/ip_address/tcp/tcp_port +p2p_listen_address = "{{ .P2PConfig.ListenAddress }}" + +# list of nodes used for P2P bootstrapping in the format of /ip4/ip_address/tcp/port/p2p/ID +p2p_bootstrap_nodes = "{{ .P2PConfig.BootstrapNodes }}" + # max number of cached messages by gossipsub protocol -gossiped_blocks_cache_size = {{ .BlockManagerConfig.GossipedBlocksCacheSize }} +p2p_gossiped_blocks_cache_size = {{ .P2PConfig.GossipedBlocksCacheSize }} # time interval to check if no p2p nodes are connected to bootstrap again -bootstrap_time = "{{ .BootstrapTime }}" +p2p_bootstrap_retry_time = "{{ .P2PConfig.BootstrapRetryTime }}" #celestia config example: # da_config = "{\"base_url\":\"http:\/\/127.0.0.1:26658\",\"timeout\":5000000000,\"gas_prices\":0.1,\"auth_token\":\"TOKEN\",\"backoff\":{\"initial_delay\":6000000000,\"max_delay\":6000000000,\"growth_factor\":2},\"retry_attempts\":4,\"retry_delay\":3000000000}" diff --git a/conv/addr.go b/conv/addr.go deleted file mode 100644 index e015e8c74..000000000 --- a/conv/addr.go +++ /dev/null @@ -1,67 +0,0 @@ -package conv - -import ( - "strings" - - "github.com/multiformats/go-multiaddr" - - "github.com/dymensionxyz/dymint/config" -) - -// TranslateAddresses updates conf by changing Cosmos-style addresses to Multiaddr format. -func TranslateAddresses(conf *config.NodeConfig) error { - if conf.P2P.ListenAddress != "" { - addr, err := GetMultiAddr(conf.P2P.ListenAddress) - if err != nil { - return err - } - conf.P2P.ListenAddress = addr.String() - } - - seeds := strings.Split(conf.P2P.Seeds, ",") - for i, seed := range seeds { - if seed != "" { - addr, err := GetMultiAddr(seed) - if err != nil { - return err - } - seeds[i] = addr.String() - } - } - conf.P2P.Seeds = strings.Join(seeds, ",") - - return nil -} - -// GetMultiAddr converts single Cosmos-style network address into Multiaddr. -// Input format: [protocol://][@]: -func GetMultiAddr(addr string) (multiaddr.Multiaddr, error) { - var err error - var p2pID multiaddr.Multiaddr - parts := strings.Split(addr, "://") - proto := "tcp" - if len(parts) == 2 { - proto = parts[0] - addr = parts[1] - } - - if at := strings.IndexRune(addr, '@'); at != -1 { - p2pID, err = multiaddr.NewMultiaddr("/p2p/" + addr[:at]) - if err != nil { - return nil, err - } - addr = addr[at+1:] - } - parts = strings.Split(addr, ":") - if len(parts) != 2 { - return nil, ErrInvalidAddress - } - maddr, err := multiaddr.NewMultiaddr("/ip4/" + parts[0] + "/" + proto + "/" + parts[1]) - if err != nil { - return nil, err - } - if p2pID != nil { - maddr = maddr.Encapsulate(p2pID) - } - return maddr, nil -} diff --git a/conv/addr_test.go b/conv/addr_test.go deleted file mode 100644 index 887836070..000000000 --- a/conv/addr_test.go +++ /dev/null @@ -1,115 +0,0 @@ -package conv_test - -import ( - "strings" - "testing" - - "github.com/multiformats/go-multiaddr" - "github.com/stretchr/testify/assert" - - "github.com/dymensionxyz/dymint/config" - "github.com/dymensionxyz/dymint/conv" -) - -func TestTranslateAddresses(t *testing.T) { - t.Parallel() - - invalidCosmos := "foobar" - validCosmos := "127.0.0.1:1234" - validDymint := "/ip4/127.0.0.1/tcp/1234" - - cases := []struct { - name string - input config.NodeConfig - expected config.NodeConfig - expectedErr string - }{ - {"empty", config.NodeConfig{}, config.NodeConfig{}, ""}, - { - "valid listen address", - config.NodeConfig{P2P: config.P2PConfig{ListenAddress: validCosmos}}, - config.NodeConfig{P2P: config.P2PConfig{ListenAddress: validDymint}}, - "", - }, - { - "valid seed address", - config.NodeConfig{P2P: config.P2PConfig{Seeds: validCosmos + "," + validCosmos}}, - config.NodeConfig{P2P: config.P2PConfig{Seeds: validDymint + "," + validDymint}}, - "", - }, - { - "invalid listen address", - config.NodeConfig{P2P: config.P2PConfig{ListenAddress: invalidCosmos}}, - config.NodeConfig{}, - conv.ErrInvalidAddress.Error(), - }, - { - "invalid seed address", - config.NodeConfig{P2P: config.P2PConfig{Seeds: validCosmos + "," + invalidCosmos}}, - config.NodeConfig{}, - conv.ErrInvalidAddress.Error(), - }, - } - - for _, c := range cases { - t.Run(c.name, func(t *testing.T) { - assert := assert.New(t) - // c.input is changed in place - err := conv.TranslateAddresses(&c.input) - if c.expectedErr != "" { - assert.Error(err) - assert.True(strings.HasPrefix(err.Error(), c.expectedErr), "invalid error message") - } else { - assert.NoError(err) - assert.Equal(c.expected, c.input) - } - }) - } -} - -func TestGetMultiaddr(t *testing.T) { - t.Parallel() - - valid := mustGetMultiaddr(t, "/ip4/127.0.0.1/tcp/1234") - withID := mustGetMultiaddr(t, "/ip4/127.0.0.1/tcp/1234/p2p/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7") - udpWithID := mustGetMultiaddr(t, "/ip4/127.0.0.1/udp/1234/p2p/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7") - - cases := []struct { - name string - input string - expected multiaddr.Multiaddr - expectedErr string - }{ - {"empty", "", nil, conv.ErrInvalidAddress.Error()}, - {"no port", "127.0.0.1:", nil, "failed to parse multiaddr"}, - {"ip only", "127.0.0.1", nil, conv.ErrInvalidAddress.Error()}, - {"with invalid id", "deadbeef@127.0.0.1:1234", nil, "failed to parse multiaddr"}, - {"valid", "127.0.0.1:1234", valid, ""}, - {"valid with id", "k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7@127.0.0.1:1234", withID, ""}, - {"valid with id and proto", "udp://k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7@127.0.0.1:1234", udpWithID, ""}, - } - - for _, c := range cases { - t.Run(c.name, func(t *testing.T) { - assert := assert.New(t) - actual, err := conv.GetMultiAddr(c.input) - if c.expectedErr != "" { - assert.Error(err) - assert.Nil(actual) - assert.True(strings.HasPrefix(err.Error(), c.expectedErr), "invalid error message") - } else { - assert.NoError(err) - assert.Equal(c.expected, actual) - } - }) - } -} - -func mustGetMultiaddr(t *testing.T, addr string) multiaddr.Multiaddr { - t.Helper() - maddr, err := multiaddr.NewMultiaddr(addr) - if err != nil { - t.Fatal(err) - } - return maddr -} diff --git a/conv/config.go b/conv/config.go index 6e714fc78..65498dc12 100644 --- a/conv/config.go +++ b/conv/config.go @@ -18,10 +18,7 @@ func GetNodeConfig(nodeConf *config.NodeConfig, tmConf *tmcfg.Config) error { } nodeConf.RootDir = tmConf.RootDir nodeConf.DBPath = tmConf.DBPath - if tmConf.P2P != nil { - nodeConf.P2P.ListenAddress = tmConf.P2P.ListenAddress - nodeConf.P2P.Seeds = tmConf.P2P.Seeds - } + if tmConf.RPC != nil { nodeConf.RPC.ListenAddress = tmConf.RPC.ListenAddress nodeConf.RPC.CORSAllowedOrigins = tmConf.RPC.CORSAllowedOrigins @@ -42,10 +39,5 @@ func GetNodeConfig(nodeConf *config.NodeConfig, tmConf *tmcfg.Config) error { */ nodeConf.MempoolConfig = *tmConf.Mempool - err := TranslateAddresses(nodeConf) - if err != nil { - return err - } - return nil } diff --git a/conv/config_test.go b/conv/config_test.go index 0f488d194..b8707096d 100644 --- a/conv/config_test.go +++ b/conv/config_test.go @@ -13,9 +13,6 @@ import ( func TestGetNodeConfig(t *testing.T) { t.Parallel() - validCosmos := "127.0.0.1:1234" - validDymint := "/ip4/127.0.0.1/tcp/1234" - cases := []struct { name string input func(*tmcfg.Config) @@ -30,23 +27,6 @@ func TestGetNodeConfig(t *testing.T) { nil, true, }, - { - "Seeds", - func(c *tmcfg.Config) { - c.P2P.Seeds = validCosmos + "," + validCosmos - }, - func(nc *config.NodeConfig) bool { return nc.P2P.Seeds == validDymint+","+validDymint }, - false, - }, - // GetNodeConfig translates the listen address, so we expect the translated address - { - "ListenAddress", - func(c *tmcfg.Config) { - c.P2P.ListenAddress = validCosmos - }, - func(nc *config.NodeConfig) bool { return nc.P2P.ListenAddress == validDymint }, - false, - }, { "RootDir", func(c *tmcfg.Config) { diff --git a/node/node.go b/node/node.go index a77c4c376..5c8a9871f 100644 --- a/node/node.go +++ b/node/node.go @@ -164,9 +164,7 @@ func NewNode( // Set p2p client and it's validators p2pValidator := p2p.NewValidator(logger.With("module", "p2p_validator"), settlementlc) - conf.P2P.GossipCacheSize = conf.BlockManagerConfig.GossipedBlocksCacheSize - conf.P2P.BoostrapTime = conf.BootstrapTime - 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 } diff --git a/node/node_test.go b/node/node_test.go index 229e9d69f..ddd743d4e 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -62,17 +62,21 @@ func TestMempoolDirectly(t *testing.T) { rollappID := "rollapp_1234-1" nodeConfig := config.NodeConfig{ - RootDir: "", - DBPath: "", - P2P: config.P2PConfig{}, + RootDir: "", + DBPath: "", + P2PConfig: config.P2PConfig{ + ListenAddress: config.DefaultListenAddress, + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, + BootstrapNodes: "", + }, RPC: config.RPCConfig{}, MempoolConfig: *tmcfg.DefaultMempoolConfig(), BlockManagerConfig: config.BlockManagerConfig{ - BlockTime: 100 * time.Millisecond, - BatchSubmitMaxTime: 60 * time.Second, - BlockBatchMaxSizeBytes: 1000, - MaxSupportedBatchSkew: 10, - GossipedBlocksCacheSize: 50, + BlockTime: 100 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + MaxSupportedBatchSkew: 10, }, DALayer: "mock", DAConfig: "", diff --git a/p2p/client.go b/p2p/client.go index ac84fcd72..29feda4c0 100644 --- a/p2p/client.go +++ b/p2p/client.go @@ -82,6 +82,7 @@ func NewClient(conf config.P2PConfig, privKey crypto.PrivKey, chainID string, lo if conf.ListenAddress == "" { conf.ListenAddress = config.DefaultListenAddress } + return &Client{ conf: conf, privKey: privKey, @@ -101,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 @@ -229,7 +229,7 @@ func (c *Client) listen(ctx context.Context) (host.Host, error) { } func (c *Client) setupDHT(ctx context.Context) error { - seedNodes := c.GetSeedAddrInfo(c.conf.Seeds) + seedNodes := c.GetSeedAddrInfo(c.conf.BootstrapNodes) if len(seedNodes) == 0 { c.logger.Info("no seed nodes - only listening for connections") } @@ -318,8 +318,8 @@ func (c *Client) tryConnect(ctx context.Context, peer peer.AddrInfo) { } func (c *Client) setupGossiping(ctx context.Context) error { - pubsub.GossipSubHistoryGossip = c.conf.GossipCacheSize - pubsub.GossipSubHistoryLength = c.conf.GossipCacheSize + pubsub.GossipSubHistoryGossip = c.conf.GossipedBlocksCacheSize + pubsub.GossipSubHistoryLength = c.conf.GossipedBlocksCacheSize // We add WithSeenMessagesTTL (with 1 year time) option to avoid ever requesting already seen blocks ps, err := pubsub.NewGossipSub(ctx, c.Host) @@ -402,7 +402,7 @@ func (c *Client) gossipedBlockReceived(msg *GossipMessage) { } func (c *Client) bootstrapLoop(ctx context.Context) { - ticker := time.NewTicker(c.conf.BoostrapTime) + ticker := time.NewTicker(c.conf.BootstrapRetryTime) defer ticker.Stop() for { select { diff --git a/p2p/client_test.go b/p2p/client_test.go index f9e467bae..c519996c5 100644 --- a/p2p/client_test.go +++ b/p2p/client_test.go @@ -27,8 +27,9 @@ func TestClientStartup(t *testing.T) { err := pubsubServer.Start() require.NoError(t, err) client, err := p2p.NewClient(config.P2PConfig{ - GossipCacheSize: 50, - BoostrapTime: 30 * time.Second, + ListenAddress: config.DefaultListenAddress, + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, }, privKey, "TestChain", pubsubServer, log.TestingLogger()) assert := assert.New(t) assert.NoError(err) @@ -178,8 +179,8 @@ func TestSeedStringParsing(t *testing.T) { require := require.New(t) logger := &testutil.MockLogger{} client, err := p2p.NewClient(config.P2PConfig{ - GossipCacheSize: 50, - BoostrapTime: 30 * time.Second, + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, }, privKey, "TestNetwork", pubsubServer, logger) require.NoError(err) require.NotNil(client) diff --git a/rpc/client/client_test.go b/rpc/client/client_test.go index 81dc1fc4a..99e004970 100644 --- a/rpc/client/client_test.go +++ b/rpc/client/client_test.go @@ -102,16 +102,19 @@ func TestGenesisChunked(t *testing.T) { config := config.NodeConfig{ RootDir: "", DBPath: "", - P2P: config.P2PConfig{}, - RPC: config.RPCConfig{}, - BlockManagerConfig: config.BlockManagerConfig{ - BlockTime: 100 * time.Millisecond, - BatchSubmitMaxTime: 60 * time.Second, - BlockBatchMaxSizeBytes: 1000, + P2PConfig: config.P2PConfig{ + ListenAddress: config.DefaultListenAddress, + BootstrapNodes: "", GossipedBlocksCacheSize: 50, - MaxSupportedBatchSkew: 10, + BootstrapRetryTime: 30 * time.Second, + }, + RPC: config.RPCConfig{}, + BlockManagerConfig: config.BlockManagerConfig{ + BlockTime: 100 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + MaxSupportedBatchSkew: 10, }, - BootstrapTime: 30 * time.Second, DALayer: "mock", DAConfig: "", SettlementLayer: "mock", @@ -700,14 +703,18 @@ func TestValidatorSetHandling(t *testing.T) { nodeConfig := config.NodeConfig{ DALayer: "mock", SettlementLayer: "mock", - BlockManagerConfig: config.BlockManagerConfig{ - BlockTime: 10 * time.Millisecond, - BatchSubmitMaxTime: 60 * time.Second, - BlockBatchMaxSizeBytes: 1000, + P2PConfig: config.P2PConfig{ + ListenAddress: config.DefaultListenAddress, + BootstrapNodes: "", GossipedBlocksCacheSize: 50, - MaxSupportedBatchSkew: 10, + BootstrapRetryTime: 30 * time.Second, + }, + BlockManagerConfig: config.BlockManagerConfig{ + BlockTime: 10 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + MaxSupportedBatchSkew: 10, }, - BootstrapTime: 30 * time.Second, SettlementConfig: settlement.Config{ ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes), RollappID: rollappID, @@ -851,19 +858,22 @@ func getRPCInternal(t *testing.T, sequencer bool) (*tmmocks.MockApplication, *cl rollappID := "rollapp_1234-1" config := config.NodeConfig{ - RootDir: "", - DBPath: "", - P2P: config.P2PConfig{}, + RootDir: "", + DBPath: "", + P2PConfig: config.P2PConfig{ + ListenAddress: config.DefaultListenAddress, + BootstrapNodes: "", + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, + }, RPC: config.RPCConfig{}, MempoolConfig: *tmcfg.DefaultMempoolConfig(), BlockManagerConfig: config.BlockManagerConfig{ - BlockTime: 100 * time.Millisecond, - BatchSubmitMaxTime: 60 * time.Second, - BlockBatchMaxSizeBytes: 1000, - GossipedBlocksCacheSize: 50, - MaxSupportedBatchSkew: 10, + BlockTime: 100 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + MaxSupportedBatchSkew: 10, }, - BootstrapTime: 30 * time.Second, DALayer: "mock", DAConfig: "", SettlementLayer: "mock", @@ -961,16 +971,17 @@ func TestMempool2Nodes(t *testing.T) { ProposerPubKey: hex.EncodeToString(proposerPK), RollappID: rollappID, }, - BlockManagerConfig: config.BlockManagerConfig{ - BlockTime: 100 * time.Millisecond, - BatchSubmitMaxTime: 60 * time.Second, - BlockBatchMaxSizeBytes: 1000, + P2PConfig: config.P2PConfig{ + ListenAddress: "/ip4/127.0.0.1/tcp/9001", + BootstrapNodes: "", GossipedBlocksCacheSize: 50, - MaxSupportedBatchSkew: 10, + BootstrapRetryTime: 30 * time.Second, }, - BootstrapTime: 30 * time.Second, - P2P: config.P2PConfig{ - ListenAddress: "/ip4/127.0.0.1/tcp/9001", + BlockManagerConfig: config.BlockManagerConfig{ + BlockTime: 100 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + MaxSupportedBatchSkew: 10, }, MempoolConfig: *tmcfg.DefaultMempoolConfig(), }, key1, signingKey1, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: rollappID}, log.TestingLogger(), mempool.NopMetrics()) @@ -985,16 +996,16 @@ func TestMempool2Nodes(t *testing.T) { RollappID: rollappID, }, BlockManagerConfig: config.BlockManagerConfig{ - BlockTime: 100 * time.Millisecond, - BatchSubmitMaxTime: 60 * time.Second, - BlockBatchMaxSizeBytes: 1000, - GossipedBlocksCacheSize: 50, - MaxSupportedBatchSkew: 10, + BlockTime: 100 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + MaxSupportedBatchSkew: 10, }, - BootstrapTime: 30 * time.Second, - P2P: config.P2PConfig{ - ListenAddress: "/ip4/127.0.0.1/tcp/9002", - Seeds: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.String(), + P2PConfig: config.P2PConfig{ + ListenAddress: "/ip4/127.0.0.1/tcp/9002", + BootstrapNodes: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.String(), + BootstrapRetryTime: 30 * time.Second, + GossipedBlocksCacheSize: 50, }, MempoolConfig: *tmcfg.DefaultMempoolConfig(), }, key2, signingKey2, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: rollappID}, log.TestingLogger(), mempool.NopMetrics()) diff --git a/rpc/json/service_test.go b/rpc/json/service_test.go index 30152bdb6..397c485da 100644 --- a/rpc/json/service_test.go +++ b/rpc/json/service_test.go @@ -302,18 +302,22 @@ func getRPC(t *testing.T) (*tmmocks.MockApplication, *client.Client) { config := config.NodeConfig{ DALayer: "mock", SettlementLayer: "mock", BlockManagerConfig: config.BlockManagerConfig{ - BlockTime: 1 * time.Second, - MaxIdleTime: 0, - MaxSupportedBatchSkew: 10, - BatchSubmitMaxTime: 30 * time.Minute, - NamespaceID: "0102030405060708", - BlockBatchMaxSizeBytes: 1000, - GossipedBlocksCacheSize: 50, + BlockTime: 1 * time.Second, + MaxIdleTime: 0, + MaxSupportedBatchSkew: 10, + BatchSubmitMaxTime: 30 * time.Minute, + NamespaceID: "0102030405060708", + BlockBatchMaxSizeBytes: 1000, }, SettlementConfig: settlement.Config{ ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes), RollappID: rollappID, }, + P2PConfig: config.P2PConfig{ + ListenAddress: config.DefaultListenAddress, + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, + }, } node, err := node.NewNode( context.Background(), diff --git a/testutil/block.go b/testutil/block.go index 195faa6c0..19abdef82 100644 --- a/testutil/block.go +++ b/testutil/block.go @@ -91,8 +91,8 @@ func GetManagerWithProposerKey(conf config.BlockManagerConfig, proposerKey crypt // Init p2p client and validator p2pKey, _, _ := crypto.GenerateEd25519Key(rand.Reader) p2pClient, err := p2p.NewClient(config.P2PConfig{ - GossipCacheSize: 50, - BoostrapTime: 30 * time.Second, + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, }, p2pKey, "TestChain", pubsubServer, logger) if err != nil { return nil, err @@ -146,11 +146,10 @@ func initSettlementLayerMock(settlementlc settlement.LayerI, proposer string, pu func GetManagerConfig() config.BlockManagerConfig { return config.BlockManagerConfig{ - BlockTime: 100 * time.Millisecond, - BlockBatchMaxSizeBytes: 1000000, - BatchSubmitMaxTime: 30 * time.Minute, - MaxSupportedBatchSkew: 10, - NamespaceID: "0102030405060708", - GossipedBlocksCacheSize: 50, + BlockTime: 100 * time.Millisecond, + BlockBatchMaxSizeBytes: 1000000, + BatchSubmitMaxTime: 30 * time.Minute, + MaxSupportedBatchSkew: 10, + NamespaceID: "0102030405060708", } } diff --git a/testutil/node.go b/testutil/node.go index f99559b00..0b8b9853c 100644 --- a/testutil/node.go +++ b/testutil/node.go @@ -28,11 +28,10 @@ func CreateNode(isSequencer bool, blockManagerConfig *config.BlockManagerConfig) if blockManagerConfig == nil { blockManagerConfig = &config.BlockManagerConfig{ - BlockTime: 100 * time.Millisecond, - BatchSubmitMaxTime: 60 * time.Second, - BlockBatchMaxSizeBytes: 1000, - GossipedBlocksCacheSize: 50, - MaxSupportedBatchSkew: 10, + BlockTime: 100 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + MaxSupportedBatchSkew: 10, } } nodeConfig.BlockManagerConfig = *blockManagerConfig diff --git a/testutil/p2p.go b/testutil/p2p.go index 29df50f7d..713a7aada 100644 --- a/testutil/p2p.go +++ b/testutil/p2p.go @@ -108,9 +108,10 @@ func StartTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]Hos clients := make([]*p2p.Client, n) for i := 0; i < n; i++ { client, err := p2p.NewClient(config.P2PConfig{ - Seeds: seeds[i], - GossipCacheSize: 50, - BoostrapTime: 30 * time.Second, + BootstrapNodes: seeds[i], + GossipedBlocksCacheSize: 50, + BootstrapRetryTime: 30 * time.Second, + ListenAddress: config.DefaultListenAddress, }, mnet.Hosts()[i].Peerstore().PrivKey(mnet.Hosts()[i].ID()), conf[i].ChainID,