diff --git a/cmd/arc/services/blocktx.go b/cmd/arc/services/blocktx.go index 6b1c578a1..b7d4d7730 100644 --- a/cmd/arc/services/blocktx.go +++ b/cmd/arc/services/blocktx.go @@ -142,11 +142,11 @@ func StartBlockTx(logger *slog.Logger, arcConfig *config.ArcConfig) (func(), err } pm = p2p.NewPeerManager(logger.With(slog.String("module", "peer-mng")), network, pmOpts...) - peers := make([]p2p.PeerI, len(arcConfig.Peers)) + peers := make([]p2p.PeerI, len(arcConfig.Broadcasting.Unicast.Peers)) peerHandler := blocktx.NewPeerHandler(logger, blockRequestCh, blockProcessCh) - for i, peerSetting := range arcConfig.Peers { + for i, peerSetting := range arcConfig.Broadcasting.Unicast.Peers { peerURL, err := peerSetting.GetP2PUrl() if err != nil { stopFn() diff --git a/cmd/arc/services/metamorph.go b/cmd/arc/services/metamorph.go index fb60bd134..1f999d318 100644 --- a/cmd/arc/services/metamorph.go +++ b/cmd/arc/services/metamorph.go @@ -191,7 +191,7 @@ func StartMetamorph(logger *slog.Logger, arcConfig *config.ArcConfig, cacheStore return nil, fmt.Errorf("serve GRPC server failed: %v", err) } - for i, peerSetting := range arcConfig.Peers { + for i, peerSetting := range arcConfig.Broadcasting.Unicast.Peers { zmqURL, err := peerSetting.GetZMQUrl() if err != nil { logger.Warn("failed to get zmq URL for peer", slog.Int("index", i), slog.String("err", err.Error())) @@ -287,7 +287,7 @@ func initPeerManager(logger *slog.Logger, s store.MetamorphStore, arcConfig *con peerOpts = append(peerOpts, p2p.WithUserAgent("ARC", version.Version)) } - for _, peerSetting := range arcConfig.Peers { + for _, peerSetting := range arcConfig.Broadcasting.Unicast.Peers { peerURL, err := peerSetting.GetP2PUrl() if err != nil { return nil, nil, nil, fmt.Errorf("error getting peer url: %v", err) diff --git a/config/config.go b/config/config.go index db0bf1f55..0a68014b2 100644 --- a/config/config.go +++ b/config/config.go @@ -22,7 +22,7 @@ type ArcConfig struct { MessageQueue *MessageQueueConfig `mapstructure:"messageQueue"` Tracing *TracingConfig `mapstructure:"tracing"` PeerRPC *PeerRPCConfig `mapstructure:"peerRpc"` - Peers []*PeerConfig `mapstructure:"peers"` + Broadcasting *BroadcastingConfig `mapstructure:"broadcasting"` Metamorph *MetamorphConfig `mapstructure:"metamorph"` Blocktx *BlocktxConfig `mapstructure:"blocktx"` API *APIConfig `mapstructure:"api"` @@ -31,6 +31,26 @@ type ArcConfig struct { Cache *CacheConfig `mapstructure:"cache"` } +type BroadcastingConfig struct { + Mode string `mapstructure:"mode"` + Multicast *Mulsticast `mapstructure:"multicast"` + Unicast *Unicast `mapstructure:"unicast"` +} + +type Unicast struct { + Peers []*PeerConfig `mapstructure:"peers"` +} +type Mulsticast struct { + Ipv6Enabled bool `mapstructure:"ipv6Enabled"` + MulticastGroups []*string `mapstructure:"multicastGroups"` + Interfaces []*string `mapstructure:"interfaces"` +} + +type PeerConfig struct { + Host string `mapstructure:"host"` + Port *PeerPortConfig `mapstructure:"port"` +} + type MessageQueueConfig struct { URL string `mapstructure:"url"` Streaming MessageQueueStreaming `mapstructure:"streaming"` @@ -52,11 +72,6 @@ type PeerRPCConfig struct { Port int `mapstructure:"port"` } -type PeerConfig struct { - Host string `mapstructure:"host"` - Port *PeerPortConfig `mapstructure:"port"` -} - type PeerPortConfig struct { P2P int `mapstructure:"p2p"` ZMQ int `mapstructure:"zmq"` diff --git a/config/defaults.go b/config/defaults.go index 354622ed1..e3a3b8f99 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -18,7 +18,7 @@ func getDefaultArcConfig() *ArcConfig { MessageQueue: getDefaultMessageQueueConfig(), Tracing: getDefaultTracingConfig(), PeerRPC: getDefaultPeerRPCConfig(), - Peers: getPeersConfig(), + Broadcasting: getBroadcastingConfig(), Metamorph: getMetamorphConfig(), Blocktx: getBlocktxConfig(), API: getAPIConfig(), @@ -47,26 +47,36 @@ func getDefaultPeerRPCConfig() *PeerRPCConfig { } } -func getPeersConfig() []*PeerConfig { - return []*PeerConfig{ - { - Host: "localhost", - Port: &PeerPortConfig{ - P2P: 18333, - ZMQ: 28332, +func getBroadcastingConfig() *BroadcastingConfig { + return &BroadcastingConfig{ + Mode: "unicast", + Unicast: &Unicast{ + Peers: []*PeerConfig{ + { + Host: "localhost", + Port: &PeerPortConfig{ + P2P: 18333, + ZMQ: 28332, + }, + }, + { + Host: "localhost", + Port: &PeerPortConfig{ + P2P: 18334, + }, + }, + { + Host: "localhost", + Port: &PeerPortConfig{ + P2P: 18335, + }, + }, }, }, - { - Host: "localhost", - Port: &PeerPortConfig{ - P2P: 18334, - }, - }, - { - Host: "localhost", - Port: &PeerPortConfig{ - P2P: 18335, - }, + Multicast: &Mulsticast{ + Ipv6Enabled: false, + MulticastGroups: nil, + Interfaces: nil, }, } } diff --git a/config/example_config.yaml b/config/example_config.yaml index 2decb40f3..123f0a14c 100644 --- a/config/example_config.yaml +++ b/config/example_config.yaml @@ -20,17 +20,27 @@ peerRpc: # rpc configuration for bitcoin node host: localhost port: 18332 -peers: # list of bitcoin node peers to connect to - - host: localhost - port: - p2p: 18333 # port for p2p connection - zmq: 28332 # port for zmq connection - - host: localhost - port: - p2p: 18334 - - host: localhost - port: - p2p: 18335 +broadcasting: # settings for connection to nodes + mode: unicast # one of unicast | multicast + multicast: + ipv6Enabled: true # indicates whether ipv6 is enabled for multicasting + multicastGroups: # must be specified if mode = multicast + - "172.28.56.77" # address of multicast group, needs to be ipv6 address if ipv6 is enabled + interfaces: + - "eth0" + - "eth1" + unicast: + peers: # list of bitcoin node peers to connect to + - host: localhost + port: + p2p: 18333 # port for p2p connection + zmq: 28332 # port for zmq connection + - host: localhost + port: + p2p: 18334 + - host: localhost + port: + p2p: 18335 cache: engine: freecache # cache engine - freecache/redis diff --git a/config/load_test.go b/config/load_test.go index 2f4558806..71638409a 100644 --- a/config/load_test.go +++ b/config/load_test.go @@ -36,6 +36,12 @@ func Test_Load(t *testing.T) { assert.Equal(t, "INFO", actualConfig.LogLevel) assert.Equal(t, "text", actualConfig.LogFormat) assert.Equal(t, "mainnet", actualConfig.Network) + assert.Equal(t, 18335, actualConfig.Broadcasting.Unicast.Peers[2].Port.P2P) + assert.Equal(t, "172.28.56.77", *actualConfig.Broadcasting.Multicast.MulticastGroups[0]) + assert.Equal(t, true, actualConfig.Broadcasting.Multicast.Ipv6Enabled) + assert.Equal(t, "unicast", actualConfig.Broadcasting.Mode) + assert.Equal(t, "eth1", *actualConfig.Broadcasting.Multicast.Interfaces[1]) + assert.Equal(t, 18335, actualConfig.Broadcasting.Unicast.Peers[2].Port.P2P) assert.NotNil(t, actualConfig.Tracing) assert.Equal(t, "http://tracing:1234", actualConfig.Tracing.DialAddr) }) diff --git a/config/test_files/config.yaml b/config/test_files/config.yaml index fa694e719..ebce29987 100644 --- a/config/test_files/config.yaml +++ b/config/test_files/config.yaml @@ -4,3 +4,24 @@ logFormat: text network: mainnet tracing: dialAddr: http://tracing:1234 +broadcasting: # settings for connection to nodes + mode: unicast # one of unicast | multicast + multicast: + ipv6Enabled: true # indicates whether ipv6 is enabled for multicasting + multicastGroups: # must be specified if mode = multicast + - "172.28.56.77" # address of multicast group, needs to be ipv6 address if ipv6 is enabled + interfaces: + - "eth0" + - "eth1" + unicast: + peers: # list of bitcoin node peers to connect to + - host: localhost + port: + p2p: 18333 # port for p2p connection + zmq: 28332 # port for zmq connection + - host: localhost + port: + p2p: 18334 + - host: localhost + port: + p2p: 18335 \ No newline at end of file diff --git a/test/config/config.yaml b/test/config/config.yaml index 5e27ed0f6..f71ba620b 100644 --- a/test/config/config.yaml +++ b/test/config/config.yaml @@ -17,19 +17,22 @@ peerRpc: host: node1 port: 18332 -peers: - - host: node1 - port: - p2p: 18333 - zmq: 28332 - - host: node2 - port: - p2p: 18333 - zmq: 28332 - - host: node3 - port: - p2p: 18333 - zmq: 28332 +broadcasting: # settings for connection to nodes + mode: unicast # one of unicast | multicast + unicast: + peers: # list of bitcoin node peers to connect to + - host: node1 + port: + p2p: 18333 + zmq: 28332 + - host: node2 + port: + p2p: 18333 + zmq: 28332 + - host: node3 + port: + p2p: 18333 + zmq: 28332 cache: engine: redis