Skip to content

Commit

Permalink
Merge pull request #29 from multiversx/update-main-rc-v1.7.0-2024.04.18
Browse files Browse the repository at this point in the history
Update main rc v1.7.0 2024.04.18
  • Loading branch information
iulianpascalau authored Apr 18, 2024
2 parents 719b658 + 3e60c3f commit 381847e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.54.2
version: v1.57.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ run-examples:
cd scripts/run-examples && /bin/bash script.sh
docker stop "${IMAGE_NAME}"
docker rm ${IMAGE_NAME}

lint-install:
ifeq (,$(wildcard test -f bin/golangci-lint))
@echo "Installing golint"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s
endif

run-lint:
@echo "Running golint"
bin/golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 --timeout=2m

lint: lint-install run-lint
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ The **_[config.toml](./cmd/chainsimulator/config/config.toml)_** file:
```toml
[config]
[config.simulator]
# server-port paramter specifies the port of the http server
# server-port paramter specifies the port of the http server that the proxy component will respond on
server-port = 8085
# num-of-shards parameter specifies the number of shard that chain simulator will simulate
num-of-shards = 3
Expand Down Expand Up @@ -348,6 +348,12 @@ The **_[nodeOverride.toml](./cmd/chainsimulator/config/config.toml)_** file:
#]
```

**Note:** If the port for the proxy server is set to 0, a random free port will be selected.
The URL for the proxy is printed in the logs in a line that looks like:
```
INFO [2024-04-18 10:48:47.231] chain simulator's is accessible through the URL localhost:38099
```


### Build docker image
```
Expand Down
2 changes: 1 addition & 1 deletion cmd/chainsimulator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var (
}
serverPort = cli.IntFlag{
Name: "server-port",
Usage: "The port of the http server",
Usage: "The port of the http server that the proxy component will respond on. If this is set to 0, a random free port will be selected.",
Value: 8085,
}
roundDurationInMs = cli.IntFlag{
Expand Down
23 changes: 21 additions & 2 deletions cmd/chainsimulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/signal"
"runtime/debug"
"strconv"
"syscall"
"time"

Expand All @@ -28,6 +29,8 @@ import (
"github.com/urfave/cli"
)

const timeToAllowProxyToStart = time.Millisecond * 10

var (
log = logger.GetOrCreate("chainsimulator")
helpTemplate = `NAME:
Expand Down Expand Up @@ -160,8 +163,21 @@ func startChainSimulator(ctx *cli.Context) error {
return errors.New("invalid value for the number of waiting validators for metachain")
}

localRestApiInterface := "localhost"
apiConfigurator := api.NewFreePortAPIConfigurator(localRestApiInterface)
proxyPort := cfg.Config.Simulator.ServerPort
proxyURL := fmt.Sprintf("%s:%d", localRestApiInterface, proxyPort)
if proxyPort == 0 {
proxyURL = apiConfigurator.RestApiInterface(0)
portString := proxyURL[len(localRestApiInterface)+1:]
port, errConvert := strconv.Atoi(portString)
if errConvert != nil {
return fmt.Errorf("internal error while searching a free port for the proxy component: %w", errConvert)
}
proxyPort = port
}

startTimeUnix := ctx.GlobalInt64(startTime.Name)
apiConfigurator := api.NewFreePortAPIConfigurator("localhost")

tempDir, err := os.MkdirTemp(os.TempDir(), "")
if err != nil {
Expand Down Expand Up @@ -215,7 +231,7 @@ func startChainSimulator(ctx *cli.Context) error {
outputProxyConfigs, err := configs.CreateProxyConfigs(configs.ArgsProxyConfigs{
TemDir: tempDir,
PathToProxyConfig: proxyConfigs,
ServerPort: cfg.Config.Simulator.ServerPort,
ServerPort: proxyPort,
RestApiInterfaces: restApiInterfaces,
InitialWallets: simulator.GetInitialWalletKeys().BalanceWallets,
})
Expand Down Expand Up @@ -252,6 +268,9 @@ func startChainSimulator(ctx *cli.Context) error {

proxyInstance.Start()

time.Sleep(timeToAllowProxyToStart)
log.Info(fmt.Sprintf("chain simulator's is accessible through the URL %s", proxyURL))

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
<-interrupt
Expand Down

0 comments on commit 381847e

Please sign in to comment.