Skip to content

Commit

Permalink
ci(e2e): populate p2p with advertised addrs (#1576)
Browse files Browse the repository at this point in the history
Cherry picks #1560 from `main` to `release/v0.2`. This is required to
improve joining omega.

issue: none
  • Loading branch information
corverroos authored Jul 24, 2024
1 parent fc9a39b commit 9357614
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 32 deletions.
6 changes: 4 additions & 2 deletions e2e/app/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ func TestnetFromManifest(ctx context.Context, manifest types.Manifest, infd type
return types.Testnet{}, err
}

en := enode.NewV4(&nodeKey.PublicKey, inst.IPAddress, 30303, 30303)
ip := advertisedIP(manifest.Network, mode, inst.IPAddress, inst.ExtIPAddress)

en := enode.NewV4(&nodeKey.PublicKey, ip, 30303, 30303)

internalIP := inst.IPAddress.String()
if infd.Provider == docker.ProviderName {
Expand All @@ -352,7 +354,7 @@ func TestnetFromManifest(ctx context.Context, manifest types.Manifest, infd type
omniEVMS = append(omniEVMS, types.OmniEVM{
Chain: types.OmniEVMByNetwork(manifest.Network),
InstanceName: name,
AdvertisedIP: advertisedIP(manifest.Network, mode, inst.IPAddress, inst.ExtIPAddress),
AdvertisedIP: ip,
ProxyPort: inst.Port,
InternalRPC: fmt.Sprintf("http://%s:8545", internalIP),
ExternalRPC: fmt.Sprintf("http://%s:%d", inst.ExtIPAddress.String(), inst.Port),
Expand Down
36 changes: 14 additions & 22 deletions e2e/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,36 +231,20 @@ func writeAnvilState(testnet types.Testnet) error {
}

// MakeConfig generates a CometBFT config for a node.
//
//nolint:lll // CometBFT super long names :(
func MakeConfig(network netconf.ID, node *e2e.Node, nodeDir string) (*config.Config, error) {
if node.ABCIProtocol != e2e.ProtocolBuiltin {
return nil, errors.New("only Builtin ABCI is supported")
}

cfg := halocmd.DefaultCometConfig(nodeDir)
cfg.Moniker = node.Name
cfg.ProxyApp = AppAddressTCP
cfg.RPC.ListenAddress = "tcp://0.0.0.0:26657"
cfg.RPC.PprofListenAddress = ":6060"
cfg.P2P.ExternalAddress = fmt.Sprintf("tcp://%v:26656", advertisedIP(network, node.Mode, node.InternalIP, node.ExternalIP))
cfg.P2P.AddrBookStrict = false
cfg.DBBackend = node.Database
cfg.StateSync.DiscoveryTime = 5 * time.Second
cfg.BlockSync.Version = node.BlockSyncVersion
cfg.Mempool.ExperimentalMaxGossipConnectionsToNonPersistentPeers = int(node.Testnet.ExperimentalMaxGossipConnectionsToNonPersistentPeers)
cfg.Mempool.ExperimentalMaxGossipConnectionsToPersistentPeers = int(node.Testnet.ExperimentalMaxGossipConnectionsToPersistentPeers)

switch node.ABCIProtocol {
case e2e.ProtocolUNIX:
cfg.ProxyApp = AppAddressUNIX
case e2e.ProtocolTCP:
cfg.ProxyApp = AppAddressTCP
case e2e.ProtocolGRPC:
cfg.ProxyApp = AppAddressTCP
cfg.ABCI = "grpc"
case e2e.ProtocolBuiltin, e2e.ProtocolBuiltinConnSync:
cfg.ProxyApp = ""
cfg.ABCI = ""
default:
return nil, errors.New("unexpected ABCI protocol")
}

// CometBFT errors if it does not have a privval key set up, regardless of whether
// it's actually needed (e.g. for remote KMS or non-validators). We set up a dummy
Expand Down Expand Up @@ -298,14 +282,14 @@ func MakeConfig(network netconf.ID, node *e2e.Node, nodeDir string) (*config.Con
if len(cfg.P2P.Seeds) > 0 {
cfg.P2P.Seeds += ","
}
cfg.P2P.Seeds += seed.AddressP2P(true)
cfg.P2P.Seeds += advertisedP2PAddr(network, seed)
}
cfg.P2P.PersistentPeers = ""
for _, peer := range node.PersistentPeers {
if len(cfg.P2P.PersistentPeers) > 0 {
cfg.P2P.PersistentPeers += ","
}
cfg.P2P.PersistentPeers += peer.AddressP2P(true)
cfg.P2P.PersistentPeers += advertisedP2PAddr(network, peer)
}

if node.Prometheus {
Expand All @@ -315,6 +299,14 @@ func MakeConfig(network netconf.ID, node *e2e.Node, nodeDir string) (*config.Con
return &cfg, nil
}

// advertisedP2PAddr returns the cometBFT network address <ID@IP:port> to advertise for a node.
func advertisedP2PAddr(network netconf.ID, node *e2e.Node) string {
id := node.NodeKey.PubKey().Address().Bytes()
ip := advertisedIP(network, node.Mode, node.InternalIP, node.ExternalIP)

return fmt.Sprintf("%x@%s:26656", id, ip)
}

// advertisedIP returns the IP address to advertise for a node on a network.
func advertisedIP(network netconf.ID, mode types.Mode, internal, external net.IP) net.IP {
if network.IsEphemeral() {
Expand Down
2 changes: 2 additions & 0 deletions halo/cmd/cometconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func DefaultCometConfig(homeDir string) cfg.Config {
conf.StateSync.DiscoveryTime = time.Second * 10 // Increase discovery time
conf.StateSync.ChunkRequestTimeout = time.Minute // Increase timeout
conf.Mempool.Type = cfg.MempoolTypeNop // Disable cometBFT mempool
conf.ProxyApp = "" // Only support built-in ABCI app supported.
conf.ABCI = "" // Only support built-in ABCI app supported.

return *conf
}
Expand Down
4 changes: 2 additions & 2 deletions halo/cmd/testdata/TestRunCmd_defaults.golden
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"Comet": {
"Version": "0.38.10",
"RootDir": "./halo",
"ProxyApp": "tcp://127.0.0.1:26658",
"ProxyApp": "",
"Moniker": "testmoniker",
"DBBackend": "goleveldb",
"DBPath": "data",
Expand All @@ -29,7 +29,7 @@
"PrivValidatorState": "data/priv_validator_state.json",
"PrivValidatorListenAddr": "",
"NodeKey": "config/node_key.json",
"ABCI": "socket",
"ABCI": "",
"FilterPeers": false,
"RPC": {
"RootDir": "./halo",
Expand Down
4 changes: 2 additions & 2 deletions halo/cmd/testdata/TestRunCmd_flags.golden
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"Comet": {
"Version": "0.38.10",
"RootDir": "foo",
"ProxyApp": "tcp://127.0.0.1:26658",
"ProxyApp": "",
"Moniker": "testmoniker",
"DBBackend": "goleveldb",
"DBPath": "data",
Expand All @@ -29,7 +29,7 @@
"PrivValidatorState": "data/priv_validator_state.json",
"PrivValidatorListenAddr": "",
"NodeKey": "config/node_key.json",
"ABCI": "socket",
"ABCI": "",
"FilterPeers": false,
"RPC": {
"RootDir": "foo",
Expand Down
4 changes: 2 additions & 2 deletions halo/cmd/testdata/TestRunCmd_json_files.golden
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"Comet": {
"Version": "0.38.10",
"RootDir": "testinput/input2",
"ProxyApp": "tcp://127.0.0.1:26658",
"ProxyApp": "",
"Moniker": "testmoniker",
"DBBackend": "goleveldb",
"DBPath": "data",
Expand All @@ -29,7 +29,7 @@
"PrivValidatorState": "data/priv_validator_state.json",
"PrivValidatorListenAddr": "",
"NodeKey": "config/node_key.json",
"ABCI": "socket",
"ABCI": "",
"FilterPeers": false,
"RPC": {
"RootDir": "testinput/input2",
Expand Down
4 changes: 2 additions & 2 deletions halo/cmd/testdata/TestRunCmd_toml_files.golden
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Comet": {
"Version": "0.38.10",
"RootDir": "testinput/input1",
"ProxyApp": "tcp://127.0.0.1:26658",
"ProxyApp": "",
"Moniker": "config.toml",
"DBBackend": "goleveldb",
"DBPath": "data",
Expand All @@ -32,7 +32,7 @@
"PrivValidatorState": "data/priv_validator_state.json",
"PrivValidatorListenAddr": "",
"NodeKey": "config/node_key.json",
"ABCI": "socket",
"ABCI": "",
"FilterPeers": false,
"RPC": {
"RootDir": "testinput/input1",
Expand Down

0 comments on commit 9357614

Please sign in to comment.