From ff5db8e5a6b52473bd6d6055c471495b5307187e Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 2 Dec 2024 18:32:49 +0800 Subject: [PATCH] fix(simapp/v2): failed to start HTTP server on port 8080 conflict (#22687) (cherry picked from commit e7fe651b4900bdf768accab87f354c6272f9357c) --- simapp/v2/simdv2/cmd/testnet.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/simapp/v2/simdv2/cmd/testnet.go b/simapp/v2/simdv2/cmd/testnet.go index c56e9d07166e..3886b90add4e 100644 --- a/simapp/v2/simdv2/cmd/testnet.go +++ b/simapp/v2/simdv2/cmd/testnet.go @@ -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" @@ -183,6 +184,7 @@ func initTestnetFiles[T transaction.Tx]( rpcPort = 26657 apiPort = 1317 grpcPort = 9090 + restPort = 8080 ) p2pPortStart := 26656 @@ -191,6 +193,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 @@ -204,6 +207,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) @@ -337,7 +345,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