diff --git a/README.md b/README.md index 5d5eb73d..ef5b1217 100644 --- a/README.md +++ b/README.md @@ -455,8 +455,12 @@ The **_[config.toml](./cmd/chainsimulator/config/config.toml)_** file: num-of-shards = 3 # round-duration-in-milliseconds parameter specifies the duration of a simulated round. The timestamp between two headers will correspond to the round duration but will not reflect real-time round-duration-in-milliseconds = 6000 + # supernova-round-duration-in-milliseconds parameter specifies the duration of a simulated round after supernova. The timestamp between two headers will correspond to the round duration but will not reflect real-time + supernova-round-duration-in-milliseconds = 600 # rounds-per-epoch specifies the number of rounds per epoch rounds-per-epoch = 20 + # supernova-rounds-per-epoch specifies the number of rounds per epoch after supernova + supernova-rounds-per-epoch = 200 # initial-round specifies with what round the chain simulator will start initial-round = 0 # initial-nonce specifies with what nonce the chain simulator will start diff --git a/cmd/chainsimulator/config/config.toml b/cmd/chainsimulator/config/config.toml index edf3f80e..03526b7c 100644 --- a/cmd/chainsimulator/config/config.toml +++ b/cmd/chainsimulator/config/config.toml @@ -6,8 +6,12 @@ num-of-shards = 3 # round-duration-in-milliseconds parameter specifies the duration of a simulated round. The timestamp between two headers will correspond to the round duration but will not reflect real-time round-duration-in-milliseconds = 6000 + # supernova-round-duration-in-milliseconds parameter specifies the duration of a simulated round after supernova. The timestamp between two headers will correspond to the round duration but will not reflect real-time + supernova-round-duration-in-milliseconds = 600 # rounds-per-epoch specifies the number of rounds per epoch rounds-per-epoch = 20 + # supernova-rounds-per-epoch specifies the number of rounds per epoch after supernova + supernova-rounds-per-epoch = 200 # initial-round when the chain simulator will start initial-round = 0 # initial-epoch when the chain simulator will start diff --git a/cmd/chainsimulator/flags.go b/cmd/chainsimulator/flags.go index 4177d1e2..f38f2dfa 100644 --- a/cmd/chainsimulator/flags.go +++ b/cmd/chainsimulator/flags.go @@ -4,8 +4,9 @@ import ( "time" logger "github.com/multiversx/mx-chain-logger-go" - "github.com/multiversx/mx-chain-simulator-go/config" "github.com/urfave/cli" + + "github.com/multiversx/mx-chain-simulator-go/config" ) const nodeOverrideDefaultFilename = "nodeOverrideDefault.toml" @@ -66,6 +67,11 @@ var ( Usage: "The number of rounds per epoch", Value: 20, } + supernovaRoundsPerEpoch = cli.IntFlag{ + Name: "supernova-rounds-per-epoch", + Usage: "The number of rounds per epoch after supernova", + Value: 200, + } numOfShards = cli.IntFlag{ Name: "num-of-shards", Usage: "The number of shards", @@ -81,10 +87,28 @@ var ( Usage: "The round duration in milliseconds", Value: 6000, } + supernovaRoundDurationInMs = cli.IntFlag{ + Name: "supernova-round-duration", + Usage: "The round duration in milliseconds after supernova", + Value: 600, + } bypassTransactionsSignature = cli.BoolTFlag{ Name: "bypass-txs-signature", Usage: "This flag is used to bypass the transactions signature verification (by default true)", } + bypassBlocksSignature = cli.BoolTFlag{ + Name: "bypass-blocks-signature", + Usage: "This flag is used to bypass the blocks signature verification (by default true)", + } + bypassCreateBlockTimeCheck = cli.BoolTFlag{ + Name: "bypass-create-block-time-check", + Usage: "This flag is used to bypass the create block time check (by default true)", + } + createBlockMaxTimePercent = cli.Float64Flag{ + Name: "create-block-max-time-percent", + Usage: "The max time percent of round duration to create block (by default 25%)", + Value: 0.25, + } numValidatorsPerShard = cli.IntFlag{ Name: "num-validators-per-shard", Usage: "This flag is used to specify the number of validators per shard", @@ -137,6 +161,10 @@ var ( Name: "fetch-configs-and-close", Usage: "This flag is used to specify to fetch all configs and close the chain simulator after", } + enableProfiling = cli.BoolFlag{ + Name: "enable-profiling", + Usage: "Boolean option for enabling CPU profiling. If set, CPU profile will be saved to a file.", + } ) func applyFlags(ctx *cli.Context, cfg *config.Config) { @@ -144,6 +172,10 @@ func applyFlags(ctx *cli.Context, cfg *config.Config) { cfg.Config.Simulator.RoundsPerEpoch = ctx.GlobalInt(roundsPerEpoch.Name) } + if ctx.IsSet(supernovaRoundsPerEpoch.Name) { + cfg.Config.Simulator.SupernovaRoundsPerEpoch = ctx.GlobalInt(supernovaRoundsPerEpoch.Name) + } + if ctx.IsSet(numOfShards.Name) { cfg.Config.Simulator.NumOfShards = ctx.GlobalInt(numOfShards.Name) } @@ -156,6 +188,10 @@ func applyFlags(ctx *cli.Context, cfg *config.Config) { cfg.Config.Simulator.RoundDurationInMs = ctx.GlobalInt(roundDurationInMs.Name) } + if ctx.IsSet(supernovaRoundDurationInMs.Name) { + cfg.Config.Simulator.SupernovaRoundDurationInMs = ctx.GlobalInt(supernovaRoundDurationInMs.Name) + } + if ctx.IsSet(initialRound.Name) { cfg.Config.Simulator.InitialRound = ctx.GlobalInt64(initialRound.Name) } diff --git a/cmd/chainsimulator/main.go b/cmd/chainsimulator/main.go index 7aeac5ee..96482c12 100644 --- a/cmd/chainsimulator/main.go +++ b/cmd/chainsimulator/main.go @@ -3,14 +3,17 @@ package main import ( "errors" "fmt" + "net/http" "os" "os/signal" "runtime/debug" + "runtime/pprof" "strconv" "strings" "syscall" "time" + "github.com/gin-gonic/gin" "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/core/closing" @@ -20,6 +23,8 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" logger "github.com/multiversx/mx-chain-logger-go" "github.com/multiversx/mx-chain-logger-go/file" + "github.com/urfave/cli" + "github.com/multiversx/mx-chain-simulator-go/config" "github.com/multiversx/mx-chain-simulator-go/pkg/facade" "github.com/multiversx/mx-chain-simulator-go/pkg/factory" @@ -27,7 +32,6 @@ import ( "github.com/multiversx/mx-chain-simulator-go/pkg/proxy/configs" "github.com/multiversx/mx-chain-simulator-go/pkg/proxy/configs/git" "github.com/multiversx/mx-chain-simulator-go/pkg/proxy/creator" - "github.com/urfave/cli" ) const timeToAllowProxyToStart = time.Millisecond * 10 @@ -68,10 +72,15 @@ func main() { pathToProxyConfigs, startTime, roundsPerEpoch, + supernovaRoundsPerEpoch, numOfShards, serverPort, roundDurationInMs, + supernovaRoundDurationInMs, bypassTransactionsSignature, + bypassBlocksSignature, + createBlockMaxTimePercent, + bypassCreateBlockTimeCheck, numValidatorsPerShard, numWaitingValidatorsPerShard, numValidatorsMeta, @@ -84,6 +93,7 @@ func main() { skipConfigsDownload, fetchConfigsAndClose, pathWhereToSaveLogs, + enableProfiling, } app.Authors = []cli.Author{ @@ -136,12 +146,21 @@ func startChainSimulator(ctx *cli.Context) error { } bypassTxsSignature := ctx.GlobalBool(bypassTransactionsSignature.Name) - log.Warn("signature", "bypass", bypassTxsSignature) + log.Debug("signature", "bypass", bypassTxsSignature) + bypassBlocksSignature := ctx.GlobalBool(bypassBlocksSignature.Name) + log.Debug("blocks", "bypass", bypassBlocksSignature) roundDurationInMillis := uint64(cfg.Config.Simulator.RoundDurationInMs) + supernovaRoundDurationInMillis := uint64(cfg.Config.Simulator.SupernovaRoundDurationInMs) rounds := core.OptionalUint64{ HasValue: true, Value: uint64(cfg.Config.Simulator.RoundsPerEpoch), } + supernovaRounds := core.OptionalUint64{ + HasValue: true, + Value: uint64(cfg.Config.Simulator.SupernovaRoundsPerEpoch), + } + createBlockMaxTimePercent := ctx.GlobalFloat64(createBlockMaxTimePercent.Name) + bypassCreateBlockTimeCheck := ctx.GlobalBool(bypassCreateBlockTimeCheck.Name) numValidatorsShard := ctx.GlobalInt(numValidatorsPerShard.Name) if numValidatorsShard < 1 { @@ -170,23 +189,45 @@ func startChainSimulator(ctx *cli.Context) error { return err } + // CPU profiling setup - only if enable-profiling flag is set + var profileFile *os.File + profilingEnabled := ctx.GlobalBool(enableProfiling.Name) + if profilingEnabled { + pathLogsSave := ctx.GlobalString(pathWhereToSaveLogs.Name) + profileFile, err = startCPUProfiling(pathLogsSave, startTimeUnix) + if err != nil { + return fmt.Errorf("%w while starting CPU profiling", err) + } + + // Ensure pprof is stopped and file is synced/closed even on early exits + defer func() { + log.Info("stopping CPU profile (defer)") + stopCPUProfiling(profileFile) + }() + } + var alterConfigsError error argsChainSimulator := chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: bypassTxsSignature, - TempDir: tempDir, - PathToInitialConfig: nodeConfigs, - NumOfShards: uint32(cfg.Config.Simulator.NumOfShards), - GenesisTimestamp: startTimeUnix, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: rounds, - ApiInterface: apiConfigurator, - MinNodesPerShard: uint32(numValidatorsShard), - NumNodesWaitingListShard: uint32(numWaitingValidatorsShard), - MetaChainMinNodes: uint32(numValidatorsMetaShard), - NumNodesWaitingListMeta: uint32(numWaitingValidatorsMetaShard), - InitialRound: cfg.Config.Simulator.InitialRound, - InitialNonce: cfg.Config.Simulator.InitialNonce, - InitialEpoch: cfg.Config.Simulator.InitialEpoch, + BypassTxSignatureCheck: bypassTxsSignature, + BypassBlockSignatureCheck: bypassBlocksSignature, + BypassCreateBlockTimeCheck: bypassCreateBlockTimeCheck, + CreateBlockMaxTimePercent: createBlockMaxTimePercent, + TempDir: tempDir, + PathToInitialConfig: nodeConfigs, + NumOfShards: uint32(cfg.Config.Simulator.NumOfShards), + GenesisTimestamp: startTimeUnix, + RoundDurationInMillis: roundDurationInMillis, + SupernovaRoundDurationInMillis: supernovaRoundDurationInMillis, + RoundsPerEpoch: rounds, + SupernovaRoundsPerEpoch: supernovaRounds, + ApiInterface: apiConfigurator, + MinNodesPerShard: uint32(numValidatorsShard), + NumNodesWaitingListShard: uint32(numWaitingValidatorsShard), + MetaChainMinNodes: uint32(numValidatorsMetaShard), + NumNodesWaitingListMeta: uint32(numWaitingValidatorsMetaShard), + InitialRound: cfg.Config.Simulator.InitialRound, + InitialNonce: cfg.Config.Simulator.InitialNonce, + InitialEpoch: cfg.Config.Simulator.InitialEpoch, AlterConfigsFunction: func(cfg *nodeConfig.Configs) { alterConfigsError = overridableConfig.OverrideConfigValues(overrideCfg.OverridableConfigTomlValues, cfg) }, @@ -268,7 +309,28 @@ func startChainSimulator(ctx *cli.Context) error { return err } - err = endpointsProc.ExtendProxyServer(proxyInstance.GetHttpServer()) + // Create a channel for programmatic shutdown + shutdownChan := make(chan struct{}) + + // Add a shutdown endpoint before extending the proxy server + httpServer := proxyInstance.GetHttpServer() + ginEngine, ok := httpServer.Handler.(*gin.Engine) + if !ok { + return fmt.Errorf("cannot cast httpServer.Handler to gin.Engine") + } + + ginEngine.POST("/simulator/shutdown", func(c *gin.Context) { + log.Info("shutdown requested via HTTP endpoint") + c.JSON(http.StatusOK, gin.H{"message": "shutdown initiated"}) + + // Trigger shutdown in a goroutine to allow the response to be sent + go func() { + time.Sleep(100 * time.Millisecond) + close(shutdownChan) + }() + }) + + err = endpointsProc.ExtendProxyServer(httpServer) if err != nil { return err } @@ -280,9 +342,19 @@ func startChainSimulator(ctx *cli.Context) error { interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) - <-interrupt - log.Info("close") + // Wait for either signal or programmatic shutdown + select { + case sig := <-interrupt: + log.Info("close", "signal", sig) + case <-shutdownChan: + log.Info("close", "trigger", "HTTP shutdown endpoint") + } + + // Stop CPU profiling FIRST and flush to disk (only if profiling is enabled) + if profilingEnabled { + stopCPUProfiling(profileFile) + } generator.Close() @@ -297,6 +369,43 @@ func startChainSimulator(ctx *cli.Context) error { return nil } +func startCPUProfiling(pathLogsSave string, startTimeUnix int64) (*os.File, error) { + timestampMilisecond := time.Unix(startTimeUnix, 0).UnixNano() / 1000000 + cpuProfilePath := fmt.Sprintf("%s/cpu-%d.pprof", pathLogsSave, timestampMilisecond) + + profileFile, err := os.Create(cpuProfilePath) + if err != nil { + return nil, fmt.Errorf("could not create CPU profile: %w", err) + } + + if err := pprof.StartCPUProfile(profileFile); err != nil { + _ = profileFile.Close() + return nil, fmt.Errorf("could not start CPU profile: %w", err) + } + + log.Info("CPU profiling started", "path", cpuProfilePath) + return profileFile, nil +} + +func stopCPUProfiling(profileFile *os.File) { + if profileFile == nil { + return + } + + log.Info("stopping CPU profile") + pprof.StopCPUProfile() + + if err := profileFile.Sync(); err != nil { + log.Error("error syncing CPU profile file", "err", err) + } + + if err := profileFile.Close(); err != nil { + log.Error("error closing CPU profile file", "err", err) + } else { + log.Info("CPU profile file closed successfully") + } +} + func initializeLogger(ctx *cli.Context, cfg config.Config) (closing.Closer, error) { logLevelFlagValue := ctx.GlobalString(logLevel.Name) err := logger.SetLogLevel(logLevelFlagValue) @@ -313,7 +422,7 @@ func initializeLogger(ctx *cli.Context, cfg config.Config) (closing.Closer, erro fileLogging, err := file.NewFileLogging(file.ArgsFileLogging{ WorkingDir: pathLogsSave, DefaultLogsPath: cfg.Config.Logs.LogsPath, - LogFilePrefix: cfg.Config.Logs.LogFilePrefix, + LogFilePrefix: cfg.Config.Logs.LogFilePrefix + "-" + strconv.Itoa(cfg.Config.Simulator.ServerPort), }) if err != nil { return nil, fmt.Errorf("%w creating a log file", err) diff --git a/config/config.go b/config/config.go index a60a43da..49775cfd 100644 --- a/config/config.go +++ b/config/config.go @@ -6,15 +6,17 @@ import "github.com/multiversx/mx-chain-go/config" type Config struct { Config struct { Simulator struct { - ServerPort int `toml:"server-port"` - NumOfShards int `toml:"num-of-shards"` - RoundsPerEpoch int `toml:"rounds-per-epoch"` - RoundDurationInMs int `toml:"round-duration-in-milliseconds"` - InitialRound int64 `toml:"initial-round"` - InitialNonce uint64 `toml:"initial-nonce"` - InitialEpoch uint32 `toml:"initial-epoch"` - MxChainRepo string `toml:"mx-chain-go-repo"` - MxProxyRepo string `toml:"mx-chain-proxy-go-repo"` + ServerPort int `toml:"server-port"` + NumOfShards int `toml:"num-of-shards"` + RoundsPerEpoch int `toml:"rounds-per-epoch"` + SupernovaRoundsPerEpoch int `toml:"supernova-rounds-per-epoch"` + RoundDurationInMs int `toml:"round-duration-in-milliseconds"` + SupernovaRoundDurationInMs int `toml:"supernova-round-duration-in-milliseconds"` + InitialRound int64 `toml:"initial-round"` + InitialNonce uint64 `toml:"initial-nonce"` + InitialEpoch uint32 `toml:"initial-epoch"` + MxChainRepo string `toml:"mx-chain-go-repo"` + MxProxyRepo string `toml:"mx-chain-proxy-go-repo"` } `toml:"simulator"` Logs struct { LogFileLifeSpanInMB int `toml:"log-file-life-span-in-mb"` diff --git a/examples/contracts/issue-esdt-with-contract/issue-with-contract.py b/examples/contracts/issue-esdt-with-contract/issue-with-contract.py index cd994360..9dfa9b31 100644 --- a/examples/contracts/issue-esdt-with-contract/issue-with-contract.py +++ b/examples/contracts/issue-esdt-with-contract/issue-with-contract.py @@ -93,8 +93,8 @@ def main(): if status.status != "pending": sys.exit(f"incorrect status of transaction: expected->pending, received->{status}") - provider.do_post_generic(f"{GENERATE_BLOCKS_URL}/3", {}) - status = status = provider.get_transaction_status(tx_hash) + provider.do_post_generic(f"{GENERATE_BLOCKS_URL}/6", {}) + status = provider.get_transaction_status(tx_hash) if status.status != "fail": sys.exit(f"incorrect status of transaction: expected->fail, received->{status}") diff --git a/examples/generateBlocks/epoch-reached.py b/examples/generateBlocks/epoch-reached.py index f098932b..3341b2e3 100644 --- a/examples/generateBlocks/epoch-reached.py +++ b/examples/generateBlocks/epoch-reached.py @@ -9,7 +9,7 @@ def main(): # create a network provider config to increase timeout - config = NetworkProviderConfig(requests_options={"timeout": 10}) + config = NetworkProviderConfig(requests_options={"timeout": 200}) # create a network provider provider = ProxyNetworkProvider(url=SIMULATOR_URL, config=config) diff --git a/examples/staking/staking.py b/examples/staking/staking.py index fdadcca7..0cb1f486 100644 --- a/examples/staking/staking.py +++ b/examples/staking/staking.py @@ -138,11 +138,11 @@ def main(): # check if the owner receive more than 5 egld in rewards claim_reward_tx = get_tx_and_verify_status(provider, tx_hash.hex()) - one_egld = 1000000000000000000 + min_rewards = 400000000000000000 rewards_value = claim_reward_tx.smart_contract_results[0].raw.get("value", 0) - if rewards_value < one_egld: + if rewards_value < min_rewards: sys.exit(f"owner of the delegation contract didn't receive the expected amount of rewards: expected more than " - f"1 EGLD, received: {rewards_value}") + f"0.4 EGLD, received: {rewards_value}") print(f"owner has received rewards, received rewards: {rewards_value}") diff --git a/go.mod b/go.mod index 002a1375..a7de7e59 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,15 @@ module github.com/multiversx/mx-chain-simulator-go -go 1.23 +go 1.23.0 require ( github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 github.com/gin-gonic/gin v1.10.0 - github.com/multiversx/mx-chain-core-go v1.4.1 - github.com/multiversx/mx-chain-go v1.11.1 + github.com/multiversx/mx-chain-core-go v1.5.0 + github.com/multiversx/mx-chain-go v1.11.3-0.20260403083117-9d144153e53b github.com/multiversx/mx-chain-logger-go v1.1.0 - github.com/multiversx/mx-chain-proxy-go v1.3.1 + github.com/multiversx/mx-chain-proxy-go v1.4.0 + github.com/multiversx/mx-chain-storage-go v1.1.0 github.com/pelletier/go-toml v1.9.3 github.com/stretchr/testify v1.10.0 github.com/urfave/cli v1.22.16 @@ -118,12 +119,11 @@ require ( github.com/multiformats/go-multistream v0.6.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect github.com/multiversx/concurrent-map v0.1.4 // indirect - github.com/multiversx/mx-chain-communication-go v1.3.0 // indirect - github.com/multiversx/mx-chain-crypto-go v1.3.0 // indirect - github.com/multiversx/mx-chain-es-indexer-go v1.9.2 // indirect + github.com/multiversx/mx-chain-communication-go v1.3.1 // indirect + github.com/multiversx/mx-chain-crypto-go v1.3.1 // indirect + github.com/multiversx/mx-chain-es-indexer-go v1.10.2 // indirect github.com/multiversx/mx-chain-scenario-go v1.6.0 // indirect - github.com/multiversx/mx-chain-storage-go v1.1.0 // indirect - github.com/multiversx/mx-chain-vm-common-go v1.6.0 // indirect + github.com/multiversx/mx-chain-vm-common-go v1.6.1 // indirect github.com/multiversx/mx-chain-vm-go v1.6.1-0.20250707105646-d7048a2657c2 // indirect github.com/multiversx/mx-chain-vm-v1_2-go v1.2.69 // indirect github.com/multiversx/mx-chain-vm-v1_3-go v1.3.70 // indirect @@ -189,13 +189,13 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect golang.org/x/arch v0.8.0 // indirect - golang.org/x/crypto v0.32.0 // indirect + golang.org/x/crypto v0.35.0 // indirect golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect golang.org/x/mod v0.22.0 // indirect golang.org/x/net v0.34.0 // indirect - golang.org/x/sync v0.10.0 // indirect + golang.org/x/sync v0.11.0 // indirect golang.org/x/sys v0.30.0 // indirect - golang.org/x/text v0.21.0 // indirect + golang.org/x/text v0.22.0 // indirect golang.org/x/tools v0.29.0 // indirect gonum.org/v1/gonum v0.15.1 // indirect google.golang.org/protobuf v1.36.4 // indirect diff --git a/go.sum b/go.sum index bf9d6f7d..0dc2fb36 100644 --- a/go.sum +++ b/go.sum @@ -408,26 +408,26 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= -github.com/multiversx/mx-chain-communication-go v1.3.0 h1:ziNM1dRuiR/7al2L/jGEA/a/hjurtJ/HEqgazHNt9P8= -github.com/multiversx/mx-chain-communication-go v1.3.0/go.mod h1:gDVWn6zUW6aCN1YOm/FbbT5MUmhgn/L1Rmpl8EoH3Yg= -github.com/multiversx/mx-chain-core-go v1.4.1 h1:ljs53jpdjtCohpaqm2n/dvTGrFlSgIpoZYH8RVt5cWo= -github.com/multiversx/mx-chain-core-go v1.4.1/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g= -github.com/multiversx/mx-chain-crypto-go v1.3.0 h1:0eK2bkDOMi8VbSPrB1/vGJSYT81IBtfL4zw+C4sWe/k= -github.com/multiversx/mx-chain-crypto-go v1.3.0/go.mod h1:nPIkxxzyTP8IquWKds+22Q2OJ9W7LtusC7cAosz7ojM= -github.com/multiversx/mx-chain-es-indexer-go v1.9.2 h1:/K/cpTkwlFJ7zOD8VRhgc6ixi1t/3ua8CLl63LWHjvE= -github.com/multiversx/mx-chain-es-indexer-go v1.9.2/go.mod h1:t1rkD2vHXSI4EClig0h7+kRCSUCRrMF+emr4DHxFtfA= -github.com/multiversx/mx-chain-go v1.11.1 h1:PC2cP10LEmfL18yMyfsMu0usTxa/ttXNQyi3BIVsuwM= -github.com/multiversx/mx-chain-go v1.11.1/go.mod h1:7c9Qvi3lvE0wuHP/xTxbjs1GvTO/7W4NGmzT9IDsJCM= +github.com/multiversx/mx-chain-communication-go v1.3.1 h1:rJj4FOTqacD+yaAfz61FoEtwpAYmOQFyLEHdy1YZya4= +github.com/multiversx/mx-chain-communication-go v1.3.1/go.mod h1:gDVWn6zUW6aCN1YOm/FbbT5MUmhgn/L1Rmpl8EoH3Yg= +github.com/multiversx/mx-chain-core-go v1.5.0 h1:YBxTsxBGd4hy9A3plcILu+jDy4BcQaD8oyVRDC1tz8A= +github.com/multiversx/mx-chain-core-go v1.5.0/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g= +github.com/multiversx/mx-chain-crypto-go v1.3.1 h1:tCoGkfiv0wz97kuW6AZPW4RVL0Yp7PBo8NKQj9f2oh4= +github.com/multiversx/mx-chain-crypto-go v1.3.1/go.mod h1:nPIkxxzyTP8IquWKds+22Q2OJ9W7LtusC7cAosz7ojM= +github.com/multiversx/mx-chain-es-indexer-go v1.10.2 h1:mLFRUpZ2bWeYplU1e0kb318kk1x7AV9owq5B4XRdOqE= +github.com/multiversx/mx-chain-es-indexer-go v1.10.2/go.mod h1:HtHJx2XGnFTZE2GBcWxDiBr/DIuDsmb5R38+P3Jp87c= +github.com/multiversx/mx-chain-go v1.11.3-0.20260403083117-9d144153e53b h1:4KM1tyuluw5j2lf4g6KfUtyGP/KGsfOAwj8wG2ZxFjU= +github.com/multiversx/mx-chain-go v1.11.3-0.20260403083117-9d144153e53b/go.mod h1:FN73akcualo0cbyu60i5gr3UIAZBEN3YHhXrnkznQ8c= github.com/multiversx/mx-chain-logger-go v1.1.0 h1:97x84A6L4RfCa6YOx1HpAFxZp1cf/WI0Qh112whgZNM= github.com/multiversx/mx-chain-logger-go v1.1.0/go.mod h1:K9XgiohLwOsNACETMNL0LItJMREuEvTH6NsoXWXWg7g= -github.com/multiversx/mx-chain-proxy-go v1.3.1 h1:tjbTm3FpR0bjDvWAMK0zwRxRbbjGszSWltng7jv6CIg= -github.com/multiversx/mx-chain-proxy-go v1.3.1/go.mod h1:cHuW0HW8ygFhnXENyBYHiVSWmK17uheAUjglNNgTTpc= +github.com/multiversx/mx-chain-proxy-go v1.4.0 h1:fwGWr3q2j3oMqYSfupVuAIPyuOgGSDP/aAA2Q8MU4T0= +github.com/multiversx/mx-chain-proxy-go v1.4.0/go.mod h1:kizqVThJggPV0cD29qeOCFhLwnrbuYQ7saGg+GzEOog= github.com/multiversx/mx-chain-scenario-go v1.6.0 h1:cwDFuS1pSc4YXnfiKKDTEb+QDY4fulPQaiRgIebnKxI= github.com/multiversx/mx-chain-scenario-go v1.6.0/go.mod h1:GrSYu1SnMvsIm9djUz1X13224HcvdY6Nb5KHNT3xZPA= github.com/multiversx/mx-chain-storage-go v1.1.0 h1:M1Y9DqMrJ62s7Zw31+cyuqsnPIvlG4jLBJl5WzeZLe8= github.com/multiversx/mx-chain-storage-go v1.1.0/go.mod h1:o6Jm7cjfPmcc6XpyihYWrd6sx3sgqwurrunw3ZrfyxI= -github.com/multiversx/mx-chain-vm-common-go v1.6.0 h1:M2zmf/ptEINciWxYCPLIkwOMTvvzWjELYYB+0MMQ5Gw= -github.com/multiversx/mx-chain-vm-common-go v1.6.0/go.mod h1:Lc7r4VDPYRDS0CVIaWAoLtf3YQn6PZEYHv4QtaOE2Z0= +github.com/multiversx/mx-chain-vm-common-go v1.6.1 h1:8IVeETTRntms8D7ZHqN/C+WOFgJriMRxmekq+1mzXos= +github.com/multiversx/mx-chain-vm-common-go v1.6.1/go.mod h1:Lc7r4VDPYRDS0CVIaWAoLtf3YQn6PZEYHv4QtaOE2Z0= github.com/multiversx/mx-chain-vm-go v1.6.1-0.20250707105646-d7048a2657c2 h1:mWerES8Wk3a9NJVgsjG7d39o3IHtT5AX4uR3Znbzd8k= github.com/multiversx/mx-chain-vm-go v1.6.1-0.20250707105646-d7048a2657c2/go.mod h1:Qc2Sckw+EfQwnapkzghFfhuUAOGv29oSZgvj8LJ+xWQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.69 h1:5gSR3IMw1mcp/v5oO+vZ5YOyWO8w7O2qKhCKNPwsWNE= @@ -709,8 +709,8 @@ golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= -golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= +golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs= +golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c h1:KL/ZBHXgKGVmuZBZ01Lt57yE5ws8ZPSkkihmEyq7FXc= golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU= @@ -776,8 +776,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= -golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -840,8 +840,8 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= diff --git a/pkg/facade/simulatorFacade.go b/pkg/facade/simulatorFacade.go index a6e210e8..e402458e 100644 --- a/pkg/facade/simulatorFacade.go +++ b/pkg/facade/simulatorFacade.go @@ -17,8 +17,10 @@ import ( ) const ( - errMsgTargetEpochLowerThanCurrentEpoch = "target epoch must be greater than current epoch" - errMsgAccountNotFound = "account was not found") + errMsgTargetEpochLowerThanCurrentEpoch = "target epoch must be greater than current epoch" + errMsgAccountNotFound = "account was not found" + numBlocksToGenerate = 2 +) var log = logger.GetOrCreate("simulator/facade") @@ -73,7 +75,7 @@ func (sf *simulatorFacade) SetStateMultiple(stateSlice []*dtos.AddressState, noG return nil } - return sf.simulator.GenerateBlocks(1) + return sf.simulator.GenerateBlocks(numBlocksToGenerate) } // SetStateMultipleOverwrite will set the entire state for the provided address and cleanup the old state of the provided addresses @@ -96,7 +98,7 @@ func (sf *simulatorFacade) SetStateMultipleOverwrite(stateSlice []*dtos.AddressS return nil } - return sf.simulator.GenerateBlocks(1) + return sf.simulator.GenerateBlocks(numBlocksToGenerate) } // AddValidatorKeys will add the validator keys in the multi key handler diff --git a/pkg/proxy/creator/creator.go b/pkg/proxy/creator/creator.go index fbfc2e1d..dd27ac6a 100644 --- a/pkg/proxy/creator/creator.go +++ b/pkg/proxy/creator/creator.go @@ -21,6 +21,7 @@ import ( processFactory "github.com/multiversx/mx-chain-proxy-go/process/factory" versionsFactory "github.com/multiversx/mx-chain-proxy-go/versions/factory" proxy2 "github.com/multiversx/mx-chain-simulator-go/pkg/proxy" + "github.com/multiversx/mx-chain-storage-go/timecache" ) var log = logger.GetOrCreate("proxy") @@ -138,7 +139,15 @@ func CreateProxy(args ArgsProxy) (*ArgsOutputProxy, error) { valStatsProc.StartCacheUpdate() nodeStatusProc.StartCacheUpdate() - blockProc, err := processProxy.NewBlockProcessor(bp) + blockCacher, err := timecache.NewTimeCacher(timecache.ArgTimeCacher{ + DefaultSpan: time.Second, + CacheExpiry: time.Duration(args.Config.GeneralSettings.BlockCacheDurationSec) * time.Second, + }) + if err != nil { + return nil, err + } + + blockProc, err := processProxy.NewBlockProcessor(bp, blockCacher) if err != nil { return nil, err }