Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(p2p): disable peer discovery for the sequencer #923

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
25 changes: 12 additions & 13 deletions p2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion p2p/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
Expand Down
2 changes: 1 addition & 1 deletion testutil/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion testutil/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Loading