diff --git a/block/manager_test.go b/block/manager_test.go index 457b1de05..a3ec388b1 100644 --- a/block/manager_test.go +++ b/block/manager_test.go @@ -60,7 +60,7 @@ func TestInitialState(t *testing.T) { assert.NoError(err) assert.NotNil(p2pClient) - err = p2pClient.Start(context.Background()) + err = p2pClient.Start(context.Background(), false) defer func() { _ = p2pClient.Close() }() diff --git a/node/node.go b/node/node.go index 906214592..688e80308 100644 --- a/node/node.go +++ b/node/node.go @@ -246,7 +246,7 @@ func (n *Node) initGenesisChunks() error { // OnStart is a part of Service interface. func (n *Node) OnStart() error { n.Logger.Info("starting P2P client") - err := n.P2P.Start(n.ctx) + err := n.P2P.Start(n.ctx, n.BlockManager.IsSequencer()) if err != nil { return fmt.Errorf("start P2P client: %w", err) } diff --git a/p2p/client.go b/p2p/client.go index 18b53ec6c..3f97700a6 100644 --- a/p2p/client.go +++ b/p2p/client.go @@ -99,17 +99,17 @@ func NewClient(conf config.P2PConfig, privKey crypto.PrivKey, chainID string, lo // 2. Setup gossibsub. // 3. Setup DHT, establish connection to seed nodes and initialize peer discovery. // 4. Use active peer discovery to look for peers from same ORU network. -func (c *Client) Start(ctx context.Context) error { +func (c *Client) Start(ctx context.Context, isSequencer bool) error { // create new, cancelable context ctx, c.cancel = context.WithCancel(ctx) host, err := c.listen() if err != nil { return err } - return c.StartWithHost(ctx, host) + return c.StartWithHost(ctx, host, isSequencer) } -func (c *Client) StartWithHost(ctx context.Context, h host.Host) error { +func (c *Client) StartWithHost(ctx context.Context, h host.Host, isSequencer bool) error { c.Host = h for _, a := range c.Host.Addrs() { c.logger.Info("Listening on:", "address", fmt.Sprintf("%s/p2p/%s", a, c.Host.ID())) @@ -127,12 +127,13 @@ func (c *Client) StartWithHost(ctx context.Context, h host.Host) error { return err } - c.logger.Debug("Setting up active peer discovery.") - err = c.peerDiscovery(ctx) - if err != nil { - return err + if !isSequencer { + c.logger.Debug("Setting up active peer discovery.") + err = c.peerDiscovery(ctx) + if err != nil { + return err + } } - return nil } @@ -264,11 +265,9 @@ func (c *Client) peerDiscovery(ctx context.Context) error { return err } - if c.conf.AdvertisingEnabled { - err = c.advertise(ctx) - if err != nil { - return err - } + err = c.advertise(ctx) + if err != nil { + return err } err = c.findPeers(ctx) diff --git a/p2p/client_test.go b/p2p/client_test.go index c519996c5..9e570c463 100644 --- a/p2p/client_test.go +++ b/p2p/client_test.go @@ -35,7 +35,7 @@ func TestClientStartup(t *testing.T) { assert.NoError(err) assert.NotNil(client) - err = client.Start(context.Background()) + err = client.Start(context.Background(), false) defer func() { _ = client.Close() }() diff --git a/testutil/block.go b/testutil/block.go index 9f326dd7d..a86fa7cb0 100644 --- a/testutil/block.go +++ b/testutil/block.go @@ -101,7 +101,7 @@ func GetManagerWithProposerKey(conf config.BlockManagerConfig, proposerKey crypt p2pClient.SetTxValidator(p2pValidator.TxValidator(mp, mpIDs)) p2pClient.SetBlockValidator(p2pValidator.BlockValidator()) - if err = p2pClient.Start(context.Background()); err != nil { + if err = p2pClient.Start(context.Background(), false); err != nil { return nil, err } diff --git a/testutil/p2p.go b/testutil/p2p.go index 713a7aada..2997aad28 100644 --- a/testutil/p2p.go +++ b/testutil/p2p.go @@ -125,7 +125,7 @@ func StartTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]Hos } for i, c := range clients { - err := c.StartWithHost(ctx, mnet.Hosts()[i]) + err := c.StartWithHost(ctx, mnet.Hosts()[i], false) require.NoError(err) }