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

Manage multiple network messengers on network components #5330

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions cmd/node/config/fullArchiveP2P.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#FullArchiveP2P config file

#TODO[Sorin]: proper values on this config, it is just a copy of p2p.toml for the moment
iulianpascalau marked this conversation as resolved.
Show resolved Hide resolved

#NodeConfig holds the P2P settings
[Node]
#Port is the port that will be opened by the node on all interfaces so other peers can connect to it
#If the port = 0, the node will search for a free port on the machine and use it
Port = "37373-38383"

#ThresholdMinConnectedPeers represents the minimum number of connections a node should have before it can start
#the sync and consensus mechanisms
ThresholdMinConnectedPeers = 3

# MinNumPeersToWaitForOnBootstrap is the minimum number of peers to wait on bootstrap or the node will wait the default
# time which is now set to ~20 seconds (the const defined in the common package named TimeToWaitForP2PBootstrap)
ssd04 marked this conversation as resolved.
Show resolved Hide resolved
MinNumPeersToWaitForOnBootstrap = 10

# P2P peer discovery section

#The following sections correspond to the way new peers will be discovered
#If all config types are disabled then the peer will run in single mode (will not try to find other peers)
#If more than one peer discovery mechanism is enabled, the application will output an error and will not start

[KadDhtPeerDiscovery]
#Enabled: true/false to enable/disable this discovery mechanism
Enabled = true

#Type represents the kad-dht glue code implementation.
#"legacy" will define the first implementation.
#"optimized" represents the new variant able to connect to multiple seeders at once. This implementation also has
#a built-in timer that will try to automatically reconnect to the seeders (in case the seeders recover after a
#premature shutdown)
Type = "optimized"

#RefreshIntervalInSec represents the time in seconds between querying for new peers
RefreshIntervalInSec = 10

#ProtocolID represents the protocol that this node will advertize to other peers
#To connect to other nodes, those nodes should have the same ProtocolID string
ProtocolID = "/erd/kad/1.0.0"

#InitialPeerList represents the list of strings of some known nodes that will bootstrap this node
#The address will be in a self-describing addressing format.
#More can be found here: https://github.com/libp2p/specs/blob/master/3-requirements.md#34-transport-agnostic
#Example:
# /ip6/fe80::8823:6dff:fee7:f172/tcp/4001/p2p/QmYJyUMAcXEw1b5bFfbBbzYu5wyyjLMRHXGUkCXpag74Fu
# /ip4/162.246.145.218/udp/4001/utp/ipfs/QmYJyUMAcXEw1b5bFfbBbzYu5wyyjLMRHXGUkCXpag74Fu
#
#If the initial peers list is left empty, the node will not try to connect to other peers during initial bootstrap
#phase but will accept connections and will do the network discovery if another peer connects to it
InitialPeerList = ["/ip4/127.0.0.1/tcp/9999/p2p/16Uiu2HAkw5SNNtSvH1zJiQ6Gc3WoGNSxiyNueRKe6fuAuh57G3Bk"]

#kademlia's routing table bucket size
BucketSize = 100

#RoutingTableRefreshIntervalInSec defines how many seconds should pass between 2 kad routing table auto refresh calls
RoutingTableRefreshIntervalInSec = 300

[Sharding]
# The targeted number of peer connections
TargetPeerCount = 36
MaxIntraShardValidators = 7
MaxCrossShardValidators = 15
MaxIntraShardObservers = 2
MaxCrossShardObservers = 3
MaxSeeders = 2

#available options:
# `ListsSharder` will split the peers based on the shard membership (intra, cross or unknown)
# `OneListSharder` will do just the connection triming (upto TargetPeerCount value) not taking into account
# the shard membership of the connected peers
# `NilListSharder` will disable conection trimming (sharder is off)
Type = "ListsSharder"
4 changes: 0 additions & 4 deletions cmd/node/config/p2p.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,3 @@
# the shard membership of the connected peers
# `NilListSharder` will disable conection trimming (sharder is off)
Type = "ListsSharder"

[AdditionalConnections]
#this value will be added to the target peer count automatically when the node will be in full archive mode
MaxFullHistoryObservers = 10
24 changes: 22 additions & 2 deletions cmd/node/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ var (
"configurations such as port, target peer count or KadDHT settings",
Value: "./config/p2p.toml",
}
// fullArchiveP2PConfigurationFile defines a flag for the path to the toml file containing P2P configuration for the full archive network
fullArchiveP2PConfigurationFile = cli.StringFlag{
Name: "full-archive-p2p-config",
Usage: "The `" + filePathPlaceholder + "` for the p2p configuration file for the full archive network. This TOML file contains peer-to-peer " +
"configurations such as port, target peer count or KadDHT settings",
Value: "./config/fullArchiveP2P.toml",
}
// epochConfigurationFile defines a flag for the path to the toml file containing the epoch configuration
epochConfigurationFile = cli.StringFlag{
Name: "epoch-config",
Expand All @@ -111,13 +118,20 @@ var (
Usage: "The `" + filePathPlaceholder + "` for the gas costs configuration directory.",
Value: "./config/gasSchedules",
}
// port defines a flag for setting the port on which the node will listen for connections
// port defines a flag for setting the port on which the node will listen for connections on the main network
port = cli.StringFlag{
Name: "port",
Usage: "The `[p2p port]` number on which the application will start. Can use single values such as " +
"`0, 10230, 15670` or range of ports such as `5000-10000`",
Value: "0",
}
// fullArchivePort defines a flag for setting the port on which the node will listen for connections on the full archive network
fullArchivePort = cli.StringFlag{
Name: "full-archive-port",
Usage: "The `[p2p port]` number on which the application will start the second network when running in full archive mode. " +
"Can use single values such as `0, 10230, 15670` or range of ports such as `5000-10000`",
Value: "0",
}
// profileMode defines a flag for profiling the binary
// If enabled, it will open the pprof routes over the default gin rest webserver.
// There are several routes that will be available for profiling (profiling can be analyzed with: go tool pprof):
Expand Down Expand Up @@ -405,13 +419,15 @@ func getFlags() []cli.Flag {
configurationPreferencesFile,
externalConfigFile,
p2pConfigurationFile,
fullArchiveP2PConfigurationFile,
epochConfigurationFile,
roundConfigurationFile,
gasScheduleConfigurationDirectory,
validatorKeyIndex,
validatorKeyPemFile,
allValidatorKeysPemFile,
port,
fullArchivePort,
profileMode,
useHealthService,
storageCleanup,
Expand Down Expand Up @@ -670,7 +686,8 @@ func processLiteObserverMode(log logger.Logger, configs *config.Configs) {
func processConfigImportDBMode(log logger.Logger, configs *config.Configs) error {
importDbFlags := configs.ImportDbConfig
generalConfigs := configs.GeneralConfig
p2pConfigs := configs.P2pConfig
p2pConfigs := configs.MainP2pConfig
fullArchiveP2PConfigs := configs.FullArchiveP2pConfig
prefsConfig := configs.PreferencesConfig

var err error
Expand All @@ -690,6 +707,8 @@ func processConfigImportDBMode(log logger.Logger, configs *config.Configs) error
generalConfigs.StateTriesConfig.CheckpointRoundsModulus = 100000000
p2pConfigs.Node.ThresholdMinConnectedPeers = 0
p2pConfigs.KadDhtPeerDiscovery.Enabled = false
fullArchiveP2PConfigs.Node.ThresholdMinConnectedPeers = 0
fullArchiveP2PConfigs.KadDhtPeerDiscovery.Enabled = false

alterStorageConfigsForDBImport(generalConfigs)

Expand All @@ -700,6 +719,7 @@ func processConfigImportDBMode(log logger.Logger, configs *config.Configs) error
"StoragePruning.NumEpochsToKeep", generalConfigs.StoragePruning.NumEpochsToKeep,
"StoragePruning.NumActivePersisters", generalConfigs.StoragePruning.NumActivePersisters,
"p2p.ThresholdMinConnectedPeers", p2pConfigs.Node.ThresholdMinConnectedPeers,
"fullArchiveP2P.ThresholdMinConnectedPeers", fullArchiveP2PConfigs.Node.ThresholdMinConnectedPeers,
"no sig check", importDbFlags.ImportDbNoSigCheckFlag,
"import save trie epoch root hash", importDbFlags.ImportDbSaveTrieEpochRootHash,
"import DB start in epoch", importDbFlags.ImportDBStartInEpoch,
Expand Down
17 changes: 14 additions & 3 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,19 @@ func readConfigs(ctx *cli.Context, log logger.Logger) (*config.Configs, error) {
log.Debug("config", "file", configurationPaths.External)

configurationPaths.P2p = ctx.GlobalString(p2pConfigurationFile.Name)
p2pConfig, err := common.LoadP2PConfig(configurationPaths.P2p)
mainP2PConfig, err := common.LoadP2PConfig(configurationPaths.P2p)
if err != nil {
return nil, err
}
log.Debug("config", "file", configurationPaths.P2p)

configurationPaths.FullArchiveP2p = ctx.GlobalString(fullArchiveP2PConfigurationFile.Name)
fullArchiveP2PConfig, err := common.LoadP2PConfig(configurationPaths.FullArchiveP2p)
if err != nil {
return nil, err
}
log.Debug("config", "file", configurationPaths.FullArchiveP2p)

configurationPaths.Epoch = ctx.GlobalString(epochConfigurationFile.Name)
epochConfig, err := common.LoadEpochConfig(configurationPaths.Epoch)
if err != nil {
Expand All @@ -223,7 +230,10 @@ func readConfigs(ctx *cli.Context, log logger.Logger) (*config.Configs, error) {
log.Debug("config", "file", configurationPaths.RoundActivation)

if ctx.IsSet(port.Name) {
p2pConfig.Node.Port = ctx.GlobalString(port.Name)
mainP2PConfig.Node.Port = ctx.GlobalString(port.Name)
}
if ctx.IsSet(fullArchivePort.Name) {
fullArchiveP2PConfig.Node.Port = ctx.GlobalString(fullArchivePort.Name)
}
if ctx.IsSet(destinationShardAsObserver.Name) {
preferencesConfig.Preferences.DestinationShardAsObserver = ctx.GlobalString(destinationShardAsObserver.Name)
Expand All @@ -243,7 +253,8 @@ func readConfigs(ctx *cli.Context, log logger.Logger) (*config.Configs, error) {
RatingsConfig: ratingsConfig,
PreferencesConfig: preferencesConfig,
ExternalConfig: externalConfig,
P2pConfig: p2pConfig,
MainP2pConfig: mainP2PConfig,
FullArchiveP2pConfig: fullArchiveP2PConfig,
ConfigurationPathsHolder: configurationPaths,
EpochConfig: epochConfig,
RoundConfig: roundConfig,
Expand Down
4 changes: 0 additions & 4 deletions cmd/seednode/config/p2p.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,3 @@
# the shard membership of the connected peers
# `NilListSharder` will disable conection trimming (sharder is off)
Type = "NilListSharder"

[AdditionalConnections]
#this value will be added to the target peer count automatically when the node will be in full archive mode
MaxFullHistoryObservers = 0
1 change: 1 addition & 0 deletions cmd/seednode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func createNode(
P2pPrivateKey: p2pKey,
P2pSingleSigner: p2pSingleSigner,
P2pKeyGenerator: p2pKeyGen,
Logger: logger.GetOrCreate("seed/p2p"),
}

return p2pFactory.NewNetworkMessenger(arg)
Expand Down
3 changes: 0 additions & 3 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,6 @@ const MetricP2PIntraShardObservers = "erd_p2p_intra_shard_observers"
// MetricP2PCrossShardObservers is the metric that outputs the cross-shard connected observers
const MetricP2PCrossShardObservers = "erd_p2p_cross_shard_observers"

// MetricP2PFullHistoryObservers is the metric that outputs the full-history connected observers
const MetricP2PFullHistoryObservers = "erd_p2p_full_history_observers"

// MetricP2PUnknownPeers is the metric that outputs the unknown-shard connected peers
const MetricP2PUnknownPeers = "erd_p2p_unknown_shard_peers"

Expand Down
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ type Configs struct {
RatingsConfig *RatingsConfig
PreferencesConfig *Preferences
ExternalConfig *ExternalConfig
P2pConfig *p2pConfig.P2PConfig
MainP2pConfig *p2pConfig.P2PConfig
FullArchiveP2pConfig *p2pConfig.P2PConfig
FlagsConfig *ContextFlagsConfig
ImportDbConfig *ImportDbConfig
ConfigurationPathsHolder *ConfigurationPathsHolder
Expand All @@ -587,6 +588,7 @@ type ConfigurationPathsHolder struct {
Preferences string
External string
P2p string
iulianpascalau marked this conversation as resolved.
Show resolved Hide resolved
FullArchiveP2p string
GasScheduleDirectoryName string
Nodes string
Genesis string
Expand Down
13 changes: 8 additions & 5 deletions config/overridableConfig/configOverriding.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
)

const (
configTomlFile = "config.toml"
enableEpochsTomlFile = "enableEpochs.toml"
p2pTomlFile = "p2p.toml"
externalTomlFile = "external.toml"
configTomlFile = "config.toml"
enableEpochsTomlFile = "enableEpochs.toml"
p2pTomlFile = "p2p.toml"
fullArchiveP2PTomlFile = "fullArchiveP2P.toml"
externalTomlFile = "external.toml"
)

var (
Expand All @@ -31,7 +32,9 @@ func OverrideConfigValues(newConfigs []config.OverridableConfig, configs *config
case enableEpochsTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.EpochConfig, newConfig.Path, newConfig.Value)
case p2pTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.P2pConfig, newConfig.Path, newConfig.Value)
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.MainP2pConfig, newConfig.Path, newConfig.Value)
case fullArchiveP2PTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.FullArchiveP2pConfig, newConfig.Path, newConfig.Value)
case externalTomlFile:
err = reflectcommon.AdaptStructureValueBasedOnPath(configs.ExternalConfig, newConfig.Path, newConfig.Value)
default:
Expand Down
14 changes: 12 additions & 2 deletions config/overridableConfig/configOverriding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@ func TestOverrideConfigValues(t *testing.T) {
t.Run("should work for p2p.toml", func(t *testing.T) {
t.Parallel()

configs := &config.Configs{P2pConfig: &p2pConfig.P2PConfig{Sharding: p2pConfig.ShardingConfig{TargetPeerCount: 5}}}
configs := &config.Configs{MainP2pConfig: &p2pConfig.P2PConfig{Sharding: p2pConfig.ShardingConfig{TargetPeerCount: 5}}}

err := OverrideConfigValues([]config.OverridableConfig{{Path: "Sharding.TargetPeerCount", Value: "37", File: "p2p.toml"}}, configs)
require.NoError(t, err)
require.Equal(t, uint32(37), configs.P2pConfig.Sharding.TargetPeerCount)
require.Equal(t, uint32(37), configs.MainP2pConfig.Sharding.TargetPeerCount)
})

t.Run("should work for fullArchiveP2P.toml", func(t *testing.T) {
t.Parallel()

configs := &config.Configs{FullArchiveP2pConfig: &p2pConfig.P2PConfig{Sharding: p2pConfig.ShardingConfig{TargetPeerCount: 5}}}

err := OverrideConfigValues([]config.OverridableConfig{{Path: "Sharding.TargetPeerCount", Value: "37", File: "fullArchiveP2P.toml"}}, configs)
require.NoError(t, err)
require.Equal(t, uint32(37), configs.FullArchiveP2pConfig.Sharding.TargetPeerCount)
})

t.Run("should work for external.toml", func(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,7 @@ func TestP2pConfig(t *testing.T) {
MaxIntraShardObservers = 0
MaxCrossShardObservers = 0
MaxSeeders = 0
Type = "` + shardingType + `"
[AdditionalConnections]
MaxFullHistoryObservers = 0`
Type = "` + shardingType + `"`

expectedCfg := p2pConfig.P2PConfig{
Node: p2pConfig.NodeConfig{
Expand Down
2 changes: 0 additions & 2 deletions dataRetriever/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ type ManualEpochStartNotifier interface {
// MessageHandler defines the functionality needed by structs to send data to other peers
type MessageHandler interface {
ConnectedPeersOnTopic(topic string) []core.PeerID
ConnectedFullHistoryPeersOnTopic(topic string) []core.PeerID
SendToConnectedPeer(topic string, buff []byte, peerID core.PeerID) error
ID() core.PeerID
IsInterfaceNil() bool
Expand Down Expand Up @@ -168,7 +167,6 @@ type StorageType uint8
type PeerListCreator interface {
CrossShardPeerList() []core.PeerID
IntraShardPeerList() []core.PeerID
FullHistoryList() []core.PeerID
IsInterfaceNil() bool
}

Expand Down
12 changes: 3 additions & 9 deletions dataRetriever/mock/messageHandlerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@ import (

// MessageHandlerStub -
type MessageHandlerStub struct {
ConnectedPeersOnTopicCalled func(topic string) []core.PeerID
ConnectedFullHistoryPeersOnTopicCalled func(topic string) []core.PeerID
SendToConnectedPeerCalled func(topic string, buff []byte, peerID core.PeerID) error
IDCalled func() core.PeerID
ConnectedPeersOnTopicCalled func(topic string) []core.PeerID
SendToConnectedPeerCalled func(topic string, buff []byte, peerID core.PeerID) error
IDCalled func() core.PeerID
}

// ConnectedPeersOnTopic -
func (mhs *MessageHandlerStub) ConnectedPeersOnTopic(topic string) []core.PeerID {
return mhs.ConnectedPeersOnTopicCalled(topic)
}

// ConnectedFullHistoryPeersOnTopic -
func (mhs *MessageHandlerStub) ConnectedFullHistoryPeersOnTopic(topic string) []core.PeerID {
return mhs.ConnectedFullHistoryPeersOnTopicCalled(topic)
}

// SendToConnectedPeer -
func (mhs *MessageHandlerStub) SendToConnectedPeer(topic string, buff []byte, peerID core.PeerID) error {
return mhs.SendToConnectedPeerCalled(topic, buff, peerID)
Expand Down
6 changes: 0 additions & 6 deletions dataRetriever/mock/peerListCreatorStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
type PeerListCreatorStub struct {
CrossShardPeerListCalled func() []core.PeerID
IntraShardPeerListCalled func() []core.PeerID
FullHistoryListCalled func() []core.PeerID
}

// CrossShardPeerList -
Expand All @@ -21,11 +20,6 @@ func (p *PeerListCreatorStub) IntraShardPeerList() []core.PeerID {
return p.IntraShardPeerListCalled()
}

// FullHistoryList -
func (p *PeerListCreatorStub) FullHistoryList() []core.PeerID {
return p.FullHistoryListCalled()
}

// IsInterfaceNil returns true if there is no value under the interface
func (p *PeerListCreatorStub) IsInterfaceNil() bool {
return p == nil
Expand Down
5 changes: 0 additions & 5 deletions dataRetriever/topicSender/diffPeerListCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ func (dplc *diffPeerListCreator) IntraShardPeerList() []core.PeerID {
return dplc.messenger.ConnectedPeersOnTopic(dplc.intraShardTopic)
}

// FullHistoryList returns the full history peers list
func (dplc *diffPeerListCreator) FullHistoryList() []core.PeerID {
return dplc.messenger.ConnectedFullHistoryPeersOnTopic(dplc.intraShardTopic)
}

// IsInterfaceNil returns true if there is no value under the interface
func (dplc *diffPeerListCreator) IsInterfaceNil() bool {
return dplc == nil
Expand Down