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

new config for ipv6 related changes #624

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions cmd/arc/services/blocktx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions cmd/arc/services/metamorph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 21 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand Down
48 changes: 29 additions & 19 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func getDefaultArcConfig() *ArcConfig {
MessageQueue: getDefaultMessageQueueConfig(),
Tracing: getDefaultTracingConfig(),
PeerRPC: getDefaultPeerRPCConfig(),
Peers: getPeersConfig(),
Broadcasting: getBroadcastingConfig(),
Metamorph: getMetamorphConfig(),
Blocktx: getBlocktxConfig(),
API: getAPIConfig(),
Expand Down Expand Up @@ -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,
},
}
}
Expand Down
32 changes: 21 additions & 11 deletions config/example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
21 changes: 21 additions & 0 deletions config/test_files/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 16 additions & 13 deletions test/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading