From e07fee5cc1c9c23dc2a25c2468bafe75d1a06242 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 10 Dec 2024 16:11:55 +0800 Subject: [PATCH] fix(systemtests): avoid HTTP server on port 8080 conflict when AddFullnode (#22810) --- systemtests/CHANGELOG.md | 4 ++++ systemtests/system.go | 21 ++++++++++++++++----- systemtests/testnet_init.go | 17 +++++------------ 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/systemtests/CHANGELOG.md b/systemtests/CHANGELOG.md index 2a27c4162cf2..e4ccd09d739c 100644 --- a/systemtests/CHANGELOG.md +++ b/systemtests/CHANGELOG.md @@ -36,6 +36,10 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j ## [Unreleased] +## [v1.0.0-rc.4] - 2024-12-10 + +* [#22810](https://github.com/cosmos/cosmos-sdk/pull/22810) Avoid HTTP server conflicts on port 8080 + ## [v1.0.0-rc.3] - 2024-12-05 * [#22774](https://github.com/cosmos/cosmos-sdk/pull/22774) Add greater than or equal support in Rest test suite diff --git a/systemtests/system.go b/systemtests/system.go index cb1adb13040e..5b964ee03327 100644 --- a/systemtests/system.go +++ b/systemtests/system.go @@ -22,6 +22,7 @@ import ( client "github.com/cometbft/cometbft/rpc/client/http" ctypes "github.com/cometbft/cometbft/rpc/core/types" tmtypes "github.com/cometbft/cometbft/types" + "github.com/creachadair/tomledit" "github.com/stretchr/testify/require" "github.com/tidwall/sjson" @@ -38,7 +39,11 @@ var ( MaxGas = 10_000_000 // DefaultApiPort is the port for the node to interact with - DefaultApiPort = 1317 + DefaultApiPort = 1317 + DefaultRpcPort = 26657 + DefaultRestPort = 8080 + DefaultGrpcPort = 9090 + DefaultP2PPort = 16656 ) type TestnetInitializer interface { @@ -719,15 +724,21 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, beforeStart ...func(nodeNumb configPath := filepath.Join(WorkDir, nodePath, "config") + // start node + allNodes := s.AllNodes(t) + node := allNodes[len(allNodes)-1] // quick hack: copy config and overwrite by start params for _, tomlFile := range []string{"config.toml", "app.toml"} { configFile := filepath.Join(configPath, tomlFile) _ = os.Remove(configFile) _ = MustCopyFile(filepath.Join(WorkDir, s.nodePath(0), "config", tomlFile), configFile) + if tomlFile == "app.toml" && IsV2() { + file := filepath.Join(WorkDir, s.nodePath(nodeNumber), "config", tomlFile) + EditToml(file, func(doc *tomledit.Document) { + SetValue(doc, fmt.Sprintf("%s:%d", node.IP, DefaultRestPort+nodeNumber), "rest", "address") + }) + } } - // start node - allNodes := s.AllNodes(t) - node := allNodes[len(allNodes)-1] peers := make([]string, len(allNodes)-1) for i, n := range allNodes[0 : len(allNodes)-1] { peers[i] = n.PeerAddr() @@ -740,7 +751,7 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, beforeStart ...func(nodeNumb "--p2p.persistent_peers=" + strings.Join(peers, ","), fmt.Sprintf("--p2p.laddr=tcp://localhost:%d", node.P2PPort), fmt.Sprintf("--rpc.laddr=tcp://localhost:%d", node.RPCPort), - fmt.Sprintf("--grpc.address=localhost:%d", 9090+nodeNumber), + fmt.Sprintf("--grpc.address=localhost:%d", DefaultGrpcPort+nodeNumber), "--p2p.pex=false", "--moniker=" + moniker, "--log_level=info", diff --git a/systemtests/testnet_init.go b/systemtests/testnet_init.go index 4f872019f889..e5518cf1265e 100644 --- a/systemtests/testnet_init.go +++ b/systemtests/testnet_init.go @@ -118,13 +118,6 @@ func NewModifyConfigYamlInitializer(exec string, s *SystemUnderTest) *ModifyConf } } -const ( - rpcPortStart = 26657 - apiPortStart = 1317 - grpcPortStart = 9090 - p2pPortStart = 16656 -) - func (s ModifyConfigYamlInitializer) Initialize() { // init with legacy testnet command args := []string{ @@ -154,7 +147,7 @@ func (s ModifyConfigYamlInitializer) Initialize() { for i := 0; i < s.initialNodesCount; i++ { nodeDir := filepath.Join(WorkDir, NodePath(i, s.outputDir, s.projectName), "config") id := string(mustV(p2p.LoadNodeKey(filepath.Join(nodeDir, "node_key.json"))).ID()) - nodeAddresses[i] = fmt.Sprintf("%s@127.0.0.1:%d", id, p2pPortStart+i) + nodeAddresses[i] = fmt.Sprintf("%s@127.0.0.1:%d", id, DefaultP2PPort+i) } // then update configs @@ -162,8 +155,8 @@ func (s ModifyConfigYamlInitializer) Initialize() { nodeDir := filepath.Join(WorkDir, NodePath(i, s.outputDir, s.projectName), "config") nodeNumber := i EditToml(filepath.Join(nodeDir, "config.toml"), func(doc *tomledit.Document) { - UpdatePort(doc, rpcPortStart+i, "rpc", "laddr") - UpdatePort(doc, p2pPortStart+i, "p2p", "laddr") + UpdatePort(doc, DefaultRpcPort+i, "rpc", "laddr") + UpdatePort(doc, DefaultP2PPort+i, "p2p", "laddr") SetBool(doc, false, "p2p", "addr_book_strict") SetBool(doc, false, "p2p", "pex") SetBool(doc, true, "p2p", "allow_duplicate_ip") @@ -174,8 +167,8 @@ func (s ModifyConfigYamlInitializer) Initialize() { SetValue(doc, s.commitTimeout.String(), "consensus", "timeout_commit") }) EditToml(filepath.Join(nodeDir, "app.toml"), func(doc *tomledit.Document) { - UpdatePort(doc, apiPortStart+i, "api", "address") - UpdatePort(doc, grpcPortStart+i, "grpc", "address") + UpdatePort(doc, DefaultApiPort+i, "api", "address") + UpdatePort(doc, DefaultGrpcPort+i, "grpc", "address") }) } }