Skip to content

Commit

Permalink
fix(simapp/v2): failed to start HTTP server on port 8080 conflict (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe authored Dec 2, 2024
1 parent c207a45 commit e7fe651
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion simapp/v2/simdv2/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
runtimev2 "cosmossdk.io/runtime/v2"
serverv2 "cosmossdk.io/server/v2"
"cosmossdk.io/server/v2/api/grpc"
"cosmossdk.io/server/v2/api/rest"
"cosmossdk.io/server/v2/cometbft"
"cosmossdk.io/server/v2/store"
banktypes "cosmossdk.io/x/bank/types"
Expand Down Expand Up @@ -184,6 +185,7 @@ func initTestnetFiles[T transaction.Tx](
rpcPort = 26657
apiPort = 1317
grpcPort = 9090
restPort = 8080
)
p2pPortStart := 26656

Expand All @@ -192,6 +194,7 @@ func initTestnetFiles[T transaction.Tx](
for i := 0; i < args.numValidators; i++ {
var portOffset int
grpcConfig := grpc.DefaultConfig()
restConfig := rest.DefaultConfig()
if args.singleMachine {
portOffset = i
p2pPortStart = 16656 // use different start point to not conflict with rpc port
Expand All @@ -205,6 +208,11 @@ func initTestnetFiles[T transaction.Tx](
MaxRecvMsgSize: grpc.DefaultConfig().MaxRecvMsgSize,
MaxSendMsgSize: grpc.DefaultConfig().MaxSendMsgSize,
}

restConfig = &rest.Config{
Enable: true,
Address: fmt.Sprintf("127.0.0.1:%d", restPort+portOffset),
}
}

nodeDirName := fmt.Sprintf("%s%d", args.nodeDirPrefix, i)
Expand Down Expand Up @@ -338,7 +346,8 @@ func initTestnetFiles[T transaction.Tx](
cometServer := cometbft.NewWithConfigOptions[T](cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig))
storeServer := &store.Server[T]{}
grpcServer := grpc.NewWithConfigOptions[T](grpc.OverwriteDefaultConfig(grpcConfig))
server := serverv2.NewServer[T](serverCfg, cometServer, storeServer, grpcServer)
restServer := rest.NewWithConfigOptions[T](rest.OverwriteDefaultConfig(restConfig))
server := serverv2.NewServer[T](serverCfg, cometServer, storeServer, grpcServer, restServer)
err = server.WriteConfig(filepath.Join(nodeDir, "config"))
if err != nil {
return err
Expand Down

0 comments on commit e7fe651

Please sign in to comment.