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

Merged
merged 6 commits into from
Feb 10, 2025
Merged
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
1 change: 1 addition & 0 deletions block/manager_test.go
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ func TestInitialState(t *testing.T) {
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
BlockSyncEnabled: true,
DiscoveryEnabled: true,
}, privKey, "TestChain", emptyStore, pubsubServer, datastore.NewMapDatastore(), logger)
assert.NoError(err)
assert.NotNil(p2pClient)
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -222,6 +222,7 @@ func fullNodeConfig() config.NodeConfig {
BlockSyncRequestIntervalTime: 30 * time.Second,
ListenAddress: config.DefaultListenAddress,
BootstrapNodes: "",
DiscoveryEnabled: true,
},
}
}
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ func DefaultConfig(home string) *NodeConfig {
BlockSyncRequestIntervalTime: 30 * time.Second,
ListenAddress: DefaultListenAddress,
BootstrapNodes: "",
AdvertisingEnabled: true,
DiscoveryEnabled: true,
BlockSyncEnabled: true,
},
DBConfig: DBConfig{
4 changes: 2 additions & 2 deletions config/p2p.go
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ type P2PConfig struct {
BlockSyncEnabled bool `mapstructure:"p2p_blocksync_enabled"`
// Time interval used by a node to request missing blocks (gap between cached blocks and local height) on demand from other peers using blocksync
BlockSyncRequestIntervalTime time.Duration `mapstructure:"p2p_blocksync_block_request_interval"`
// Param used to enable the advertisement of the node to be part of the P2P network in the DHT
AdvertisingEnabled bool `mapstructure:"p2p_advertising_enabled"`
// Param used to enable the advertisement and discovery of other nodes for automatic connection to other peers in the P2P network
DiscoveryEnabled bool `mapstructure:"p2p_discovery_enabled"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to validate with roller

}

// Validate P2PConfig
4 changes: 2 additions & 2 deletions config/toml.go
Original file line number Diff line number Diff line change
@@ -112,8 +112,8 @@ p2p_gossip_cache_size = {{ .P2PConfig.GossipSubCacheSize }}
# time interval to check if no p2p nodes are connected to bootstrap again
p2p_bootstrap_retry_time = "{{ .P2PConfig.BootstrapRetryTime }}"

# set to false to disable advertising the node to the P2P network
p2p_advertising_enabled= "{{ .P2PConfig.AdvertisingEnabled }}"
# set to false to disable P2P nodes discovery used to auto-connect to other peers in the P2P network
p2p_discovery_enabled= "{{ .P2PConfig.DiscoveryEnabled }}"

# set to false to disable block syncing from p2p
p2p_blocksync_enabled= "{{ .P2PConfig.BlockSyncEnabled }}"
2 changes: 1 addition & 1 deletion da/weavevm/wvm.go
Original file line number Diff line number Diff line change
@@ -553,7 +553,7 @@ func (c *DataAvailabilityLayerClient) waitForTxReceipt(ctx context.Context, txHa
return nil
},
retry.Context(ctx),
retry.Attempts(uint(*c.config.RetryAttempts)),
retry.Attempts(uint(*c.config.RetryAttempts)), //nolint:gosec // RetryAttempts should be always positive
retry.Delay(c.config.RetryDelay),
retry.DelayType(retry.FixedDelay), // Force fixed delay between attempts
retry.LastErrorOnly(true), // Only log the last error
1 change: 1 addition & 0 deletions node/node_test.go
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ func TestMempoolDirectly(t *testing.T) {
BootstrapRetryTime: 30 * time.Second,
BootstrapNodes: "",
BlockSyncRequestIntervalTime: 30 * time.Second,
DiscoveryEnabled: true,
},
RPC: config.RPCConfig{},
MempoolConfig: *tmcfg.DefaultMempoolConfig(),
16 changes: 11 additions & 5 deletions p2p/client.go
Original file line number Diff line number Diff line change
@@ -145,6 +145,14 @@ func (c *Client) StartWithHost(ctx context.Context, h host.Host) error {
return err
}

// to avoid any automatic p2p connectivity via dht, dht needs to be disabled
if !c.conf.DiscoveryEnabled {
c.logger.Debug("P2P discovery disabled. Blocksync disabled.")
// blocksync cannot be used if no dht is set
c.conf.BlockSyncEnabled = false
return nil
}

c.logger.Debug("Setting up DHT.")
err = c.setupDHT(ctx)
if err != nil {
@@ -391,11 +399,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)
2 changes: 2 additions & 0 deletions p2p/client_test.go
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ func TestClientStartup(t *testing.T) {
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
DiscoveryEnabled: true,
}, privKey, "TestChain", store, pubsubServer, datastore.NewMapDatastore(), log.TestingLogger())
assert := assert.New(t)
assert.NoError(err)
@@ -276,6 +277,7 @@ func TestSeedStringParsing(t *testing.T) {
client, err := p2p.NewClient(config.P2PConfig{
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
DiscoveryEnabled: true,
}, privKey, "TestNetwork", store, pubsubServer, datastore.NewMapDatastore(), logger)
require.NoError(err)
require.NotNil(client)
5 changes: 5 additions & 0 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
@@ -105,6 +105,7 @@ func TestGenesisChunked(t *testing.T) {
BootstrapNodes: "",
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
DiscoveryEnabled: true,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
RPC: config.RPCConfig{},
@@ -864,6 +865,7 @@ func TestValidatorSetHandling(t *testing.T) {
BootstrapNodes: "",
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
DiscoveryEnabled: true,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
BlockManagerConfig: config.BlockManagerConfig{
@@ -1022,6 +1024,7 @@ func getRPCInternal(t *testing.T, sequencer bool) (*tmmocks.MockApplication, *cl
BootstrapNodes: "",
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
DiscoveryEnabled: true,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
RPC: config.RPCConfig{},
@@ -1133,6 +1136,7 @@ func TestMempool2Nodes(t *testing.T) {
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
DiscoveryEnabled: true,
},
BlockManagerConfig: config.BlockManagerConfig{
BlockTime: 100 * time.Millisecond,
@@ -1163,6 +1167,7 @@ func TestMempool2Nodes(t *testing.T) {
BootstrapNodes: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.String(),
BootstrapRetryTime: 30 * time.Second,
GossipSubCacheSize: 50,
DiscoveryEnabled: true,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
MempoolConfig: *tmcfg.DefaultMempoolConfig(),
1 change: 1 addition & 0 deletions rpc/json/service_test.go
Original file line number Diff line number Diff line change
@@ -331,6 +331,7 @@ func getRPC(t *testing.T) (*tmmocks.MockApplication, *client.Client) {
ListenAddress: config.DefaultListenAddress,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
DiscoveryEnabled: true,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
}
1 change: 1 addition & 0 deletions testutil/block.go
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@ func GetManagerWithProposerKey(conf config.BlockManagerConfig, proposerKey crypt
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
DiscoveryEnabled: true,
BlockSyncEnabled: true,
}, p2pKey, "TestChain", managerStore, pubsubServer, datastore.NewMapDatastore(), logger)
if err != nil {
1 change: 1 addition & 0 deletions testutil/p2p.go
Original file line number Diff line number Diff line change
@@ -116,6 +116,7 @@ func StartTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]Hos
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
ListenAddress: config.DefaultListenAddress,
DiscoveryEnabled: true,
BlockSyncEnabled: true,
},
mnet.Hosts()[i].Peerstore().PrivKey(mnet.Hosts()[i].ID()),