Skip to content

Commit e07fee5

Browse files
authored
fix(systemtests): avoid HTTP server on port 8080 conflict when AddFullnode (#22810)
1 parent 332d0b1 commit e07fee5

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

systemtests/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j
3636

3737
## [Unreleased]
3838

39+
## [v1.0.0-rc.4] - 2024-12-10
40+
41+
* [#22810](https://github.com/cosmos/cosmos-sdk/pull/22810) Avoid HTTP server conflicts on port 8080
42+
3943
## [v1.0.0-rc.3] - 2024-12-05
4044

4145
* [#22774](https://github.com/cosmos/cosmos-sdk/pull/22774) Add greater than or equal support in Rest test suite

systemtests/system.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
client "github.com/cometbft/cometbft/rpc/client/http"
2323
ctypes "github.com/cometbft/cometbft/rpc/core/types"
2424
tmtypes "github.com/cometbft/cometbft/types"
25+
"github.com/creachadair/tomledit"
2526
"github.com/stretchr/testify/require"
2627
"github.com/tidwall/sjson"
2728

@@ -38,7 +39,11 @@ var (
3839

3940
MaxGas = 10_000_000
4041
// DefaultApiPort is the port for the node to interact with
41-
DefaultApiPort = 1317
42+
DefaultApiPort = 1317
43+
DefaultRpcPort = 26657
44+
DefaultRestPort = 8080
45+
DefaultGrpcPort = 9090
46+
DefaultP2PPort = 16656
4247
)
4348

4449
type TestnetInitializer interface {
@@ -719,15 +724,21 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, beforeStart ...func(nodeNumb
719724

720725
configPath := filepath.Join(WorkDir, nodePath, "config")
721726

727+
// start node
728+
allNodes := s.AllNodes(t)
729+
node := allNodes[len(allNodes)-1]
722730
// quick hack: copy config and overwrite by start params
723731
for _, tomlFile := range []string{"config.toml", "app.toml"} {
724732
configFile := filepath.Join(configPath, tomlFile)
725733
_ = os.Remove(configFile)
726734
_ = MustCopyFile(filepath.Join(WorkDir, s.nodePath(0), "config", tomlFile), configFile)
735+
if tomlFile == "app.toml" && IsV2() {
736+
file := filepath.Join(WorkDir, s.nodePath(nodeNumber), "config", tomlFile)
737+
EditToml(file, func(doc *tomledit.Document) {
738+
SetValue(doc, fmt.Sprintf("%s:%d", node.IP, DefaultRestPort+nodeNumber), "rest", "address")
739+
})
740+
}
727741
}
728-
// start node
729-
allNodes := s.AllNodes(t)
730-
node := allNodes[len(allNodes)-1]
731742
peers := make([]string, len(allNodes)-1)
732743
for i, n := range allNodes[0 : len(allNodes)-1] {
733744
peers[i] = n.PeerAddr()
@@ -740,7 +751,7 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, beforeStart ...func(nodeNumb
740751
"--p2p.persistent_peers=" + strings.Join(peers, ","),
741752
fmt.Sprintf("--p2p.laddr=tcp://localhost:%d", node.P2PPort),
742753
fmt.Sprintf("--rpc.laddr=tcp://localhost:%d", node.RPCPort),
743-
fmt.Sprintf("--grpc.address=localhost:%d", 9090+nodeNumber),
754+
fmt.Sprintf("--grpc.address=localhost:%d", DefaultGrpcPort+nodeNumber),
744755
"--p2p.pex=false",
745756
"--moniker=" + moniker,
746757
"--log_level=info",

systemtests/testnet_init.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ func NewModifyConfigYamlInitializer(exec string, s *SystemUnderTest) *ModifyConf
118118
}
119119
}
120120

121-
const (
122-
rpcPortStart = 26657
123-
apiPortStart = 1317
124-
grpcPortStart = 9090
125-
p2pPortStart = 16656
126-
)
127-
128121
func (s ModifyConfigYamlInitializer) Initialize() {
129122
// init with legacy testnet command
130123
args := []string{
@@ -154,16 +147,16 @@ func (s ModifyConfigYamlInitializer) Initialize() {
154147
for i := 0; i < s.initialNodesCount; i++ {
155148
nodeDir := filepath.Join(WorkDir, NodePath(i, s.outputDir, s.projectName), "config")
156149
id := string(mustV(p2p.LoadNodeKey(filepath.Join(nodeDir, "node_key.json"))).ID())
157-
nodeAddresses[i] = fmt.Sprintf("%s@127.0.0.1:%d", id, p2pPortStart+i)
150+
nodeAddresses[i] = fmt.Sprintf("%s@127.0.0.1:%d", id, DefaultP2PPort+i)
158151
}
159152

160153
// then update configs
161154
for i := 0; i < s.initialNodesCount; i++ {
162155
nodeDir := filepath.Join(WorkDir, NodePath(i, s.outputDir, s.projectName), "config")
163156
nodeNumber := i
164157
EditToml(filepath.Join(nodeDir, "config.toml"), func(doc *tomledit.Document) {
165-
UpdatePort(doc, rpcPortStart+i, "rpc", "laddr")
166-
UpdatePort(doc, p2pPortStart+i, "p2p", "laddr")
158+
UpdatePort(doc, DefaultRpcPort+i, "rpc", "laddr")
159+
UpdatePort(doc, DefaultP2PPort+i, "p2p", "laddr")
167160
SetBool(doc, false, "p2p", "addr_book_strict")
168161
SetBool(doc, false, "p2p", "pex")
169162
SetBool(doc, true, "p2p", "allow_duplicate_ip")
@@ -174,8 +167,8 @@ func (s ModifyConfigYamlInitializer) Initialize() {
174167
SetValue(doc, s.commitTimeout.String(), "consensus", "timeout_commit")
175168
})
176169
EditToml(filepath.Join(nodeDir, "app.toml"), func(doc *tomledit.Document) {
177-
UpdatePort(doc, apiPortStart+i, "api", "address")
178-
UpdatePort(doc, grpcPortStart+i, "grpc", "address")
170+
UpdatePort(doc, DefaultApiPort+i, "api", "address")
171+
UpdatePort(doc, DefaultGrpcPort+i, "grpc", "address")
179172
})
180173
}
181174
}

0 commit comments

Comments
 (0)