diff --git a/cmd/chainsimulator/flags.go b/cmd/chainsimulator/flags.go index 45d461b7..f38f2dfa 100644 --- a/cmd/chainsimulator/flags.go +++ b/cmd/chainsimulator/flags.go @@ -100,6 +100,15 @@ var ( 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", diff --git a/cmd/chainsimulator/main.go b/cmd/chainsimulator/main.go index 300016b8..96482c12 100644 --- a/cmd/chainsimulator/main.go +++ b/cmd/chainsimulator/main.go @@ -79,6 +79,8 @@ func main() { supernovaRoundDurationInMs, bypassTransactionsSignature, bypassBlocksSignature, + createBlockMaxTimePercent, + bypassCreateBlockTimeCheck, numValidatorsPerShard, numWaitingValidatorsPerShard, numValidatorsMeta, @@ -157,6 +159,8 @@ func startChainSimulator(ctx *cli.Context) error { 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 { @@ -206,6 +210,8 @@ func startChainSimulator(ctx *cli.Context) error { argsChainSimulator := chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: bypassTxsSignature, BypassBlockSignatureCheck: bypassBlocksSignature, + BypassCreateBlockTimeCheck: bypassCreateBlockTimeCheck, + CreateBlockMaxTimePercent: createBlockMaxTimePercent, TempDir: tempDir, PathToInitialConfig: nodeConfigs, NumOfShards: uint32(cfg.Config.Simulator.NumOfShards), @@ -416,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/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/go.mod b/go.mod index 5c348cc3..b3be2156 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.2-0.20251022090220-a99e14e45706 - github.com/multiversx/mx-chain-go v1.11.2-0.20251216115449-db8b601e9a5a + github.com/multiversx/mx-chain-core-go v1.4.2-0.20260219091525-015123fd1603 + github.com/multiversx/mx-chain-go v1.11.2-0.20260318142640-0dca50ae579d 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.3.5-0.20260217073158-6a6ed53a320e + 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.3-0.20251021150757-bd6aa66a0a90 // indirect + github.com/multiversx/mx-chain-communication-go v1.3.1 // indirect + github.com/multiversx/mx-chain-crypto-go v1.3.1-0.20260130144701-dfa5fd3ea5d7 // indirect + github.com/multiversx/mx-chain-es-indexer-go v1.9.4-0.20260219114236-37624897dc3a // 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-0.20251127112501-0b5f28e33b2e // 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 249a356e..c79383a9 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.2-0.20251022090220-a99e14e45706 h1:rs0XNP+cxwRWL5EnbfMecRHbXd5NzukImJnk58UNsiA= -github.com/multiversx/mx-chain-core-go v1.4.2-0.20251022090220-a99e14e45706/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.3-0.20251021150757-bd6aa66a0a90 h1:Hf6AqpCSHccBo5ZV5Bfaxz3UdPYhtYCynU+3CF4jAa8= -github.com/multiversx/mx-chain-es-indexer-go v1.9.3-0.20251021150757-bd6aa66a0a90/go.mod h1:t1rkD2vHXSI4EClig0h7+kRCSUCRrMF+emr4DHxFtfA= -github.com/multiversx/mx-chain-go v1.11.2-0.20251216115449-db8b601e9a5a h1:qQ13SNyzG5dBhgc9faA6HyFQX2l8v77r/GAtKyUaIjQ= -github.com/multiversx/mx-chain-go v1.11.2-0.20251216115449-db8b601e9a5a/go.mod h1:G2LX81y+A75W5EqJod9p4fRAdnp22vpQrB+374pAveQ= +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.4.2-0.20260219091525-015123fd1603 h1:PhvZUz2zHo3cjx/zySG02enKgvY4r0Vy39l0FKxc+D4= +github.com/multiversx/mx-chain-core-go v1.4.2-0.20260219091525-015123fd1603/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g= +github.com/multiversx/mx-chain-crypto-go v1.3.1-0.20260130144701-dfa5fd3ea5d7 h1:3cJf1poYPhurIenMd3GYCEh0npaEchodVzcdmHxJrY4= +github.com/multiversx/mx-chain-crypto-go v1.3.1-0.20260130144701-dfa5fd3ea5d7/go.mod h1:nPIkxxzyTP8IquWKds+22Q2OJ9W7LtusC7cAosz7ojM= +github.com/multiversx/mx-chain-es-indexer-go v1.9.4-0.20260219114236-37624897dc3a h1:4ExtYUKB8Hd+IlvxscVpAHjO6hMSYlL2yFfsKBUAzgY= +github.com/multiversx/mx-chain-es-indexer-go v1.9.4-0.20260219114236-37624897dc3a/go.mod h1:aPHgLkELJWxCDXBFF9+tbYaXJH2GIRk723YOaTejYWc= +github.com/multiversx/mx-chain-go v1.11.2-0.20260318142640-0dca50ae579d h1:jLSVxK01JA4+dY3sFzis/mueEpBIg1yvpiZ5JtTNI0Y= +github.com/multiversx/mx-chain-go v1.11.2-0.20260318142640-0dca50ae579d/go.mod h1:2rd07AciufLzuEYa31uOai7DyI6Fc0ntEtOA1+1JR18= 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.3.5-0.20260217073158-6a6ed53a320e h1:ykO1INcCgcPtz3He0gUpjK9Xisx+71HBMT3CdcmoALQ= +github.com/multiversx/mx-chain-proxy-go v1.3.5-0.20260217073158-6a6ed53a320e/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-0.20251127112501-0b5f28e33b2e h1:3gboKT4hPEb9ZkAYO2Z/y3sOaUBzxVMN4FhyLFcRSHI= +github.com/multiversx/mx-chain-vm-common-go v1.6.1-0.20251127112501-0b5f28e33b2e/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 }