diff --git a/arwen/common.go b/arwen/common.go index f2479708e..e77376c9f 100644 --- a/arwen/common.go +++ b/arwen/common.go @@ -123,7 +123,7 @@ type VMHostParameters struct { RemoveNonUpdatedStorageEnableEpoch uint32 CreateNFTThroughExecByCallerEnableEpoch uint32 UseDifferentGasCostForReadingCachedStorageEpoch uint32 - CheckValueOnExecByCallerEnableEpoch uint32 + EnableRoundsHandler EnableRoundsHandler } // AsyncCallInfo contains the information required to handle the asynchronous call of another SmartContract diff --git a/arwen/errors.go b/arwen/errors.go index d43e5a561..546466841 100644 --- a/arwen/errors.go +++ b/arwen/errors.go @@ -186,8 +186,11 @@ var ErrNilEpochNotifier = errors.New("nil epoch notifier") // ErrNotBuiltInNFTCreate signals that function is not of built in NFT create var ErrNotBuiltInNFTCreate = errors.New("not built in NFT create") -// ErrCallNotAllowedOnCallback signals that call is not allowed on callback +// ErrCallNotAllowedOnCallback signals that call is not allowed on callback var ErrCallNotAllowedOnCallback = errors.New("call not allowed on callback") // ErrCallerIsSC signals that caller is a smart contract var ErrCallerIsSC = errors.New("caller is a smart contract") + +// ErrNilEnableRoundsHandler signals that a nil enable round handler has been provided +var ErrNilEnableRoundsHandler = errors.New("nil enable rounds handler") diff --git a/arwen/host/arwen.go b/arwen/host/arwen.go index 5e71bac0a..5d2def75f 100644 --- a/arwen/host/arwen.go +++ b/arwen/host/arwen.go @@ -51,6 +51,7 @@ type vmHost struct { scAPIMethods *wasmer.Imports builtInFuncContainer vmcommon.BuiltInFunctionContainer esdtTransferParser vmcommon.ESDTTransferParser + enableRoundsHandler arwen.EnableRoundsHandler multiESDTTransferAsyncCallBackEnableEpoch uint32 flagMultiESDTTransferAsyncCallBack atomic.Flag @@ -66,9 +67,6 @@ type vmHost struct { useDifferentGasCostForReadingCachedStorageEpoch uint32 flagUseDifferentGasCostForCachedStorage atomic.Flag - - checkValueOnExecByCallerEnableEpoch uint32 - flagCheckValueOnExecByCaller atomic.Flag } // NewArwenVM creates a new Arwen vmHost @@ -92,6 +90,9 @@ func NewArwenVM( if check.IfNil(hostParameters.EpochNotifier) { return nil, arwen.ErrNilEpochNotifier } + if check.IfNil(hostParameters.EnableRoundsHandler) { + return nil, arwen.ErrNilEnableRoundsHandler + } cryptoHook := factory.NewVMCrypto() host := &vmHost{ @@ -105,12 +106,12 @@ func NewArwenVM( scAPIMethods: nil, builtInFuncContainer: hostParameters.BuiltInFuncContainer, esdtTransferParser: hostParameters.ESDTTransferParser, + enableRoundsHandler: hostParameters.EnableRoundsHandler, multiESDTTransferAsyncCallBackEnableEpoch: hostParameters.MultiESDTTransferAsyncCallBackEnableEpoch, fixOOGReturnCodeEnableEpoch: hostParameters.FixOOGReturnCodeEnableEpoch, removeNonUpdatedStorageEnableEpoch: hostParameters.RemoveNonUpdatedStorageEnableEpoch, createNFTThroughExecByCallerEnableEpoch: hostParameters.CreateNFTThroughExecByCallerEnableEpoch, useDifferentGasCostForReadingCachedStorageEpoch: hostParameters.UseDifferentGasCostForReadingCachedStorageEpoch, - checkValueOnExecByCallerEnableEpoch: hostParameters.CheckValueOnExecByCallerEnableEpoch, } var err error @@ -245,7 +246,7 @@ func (host *vmHost) Storage() arwen.StorageContext { return host.storageContext } -// BigInt returns the BigIntContext instance of the host +// ManagedTypes returns the ManagedTypesContext instance of the host func (host *vmHost) ManagedTypes() arwen.ManagedTypesContext { return host.managedTypesContext } @@ -455,9 +456,6 @@ func (host *vmHost) EpochConfirmed(epoch uint32, _ uint64) { host.flagUseDifferentGasCostForCachedStorage.SetValue(epoch >= host.useDifferentGasCostForReadingCachedStorageEpoch) log.Debug("Arwen VM: use different gas costs when reading cached storage", "enabled", host.flagUseDifferentGasCostForCachedStorage.IsSet()) - - host.flagCheckValueOnExecByCaller.SetValue(epoch >= host.checkValueOnExecByCallerEnableEpoch) - log.Debug("Arwen VM: check value on exec by caller", "enabled", host.flagCheckValueOnExecByCaller.IsSet()) } // FixOOGReturnCodeEnabled returns true if the corresponding flag is set @@ -472,7 +470,7 @@ func (host *vmHost) CreateNFTOnExecByCallerEnabled() bool { // CheckValueOnExecByCaller returns true if the corresponding flag is set func (host *vmHost) CheckValueOnExecByCaller() bool { - return host.flagCheckValueOnExecByCaller.IsSet() + return host.enableRoundsHandler.IsCheckValueOnExecByCallerEnabled() } func (host *vmHost) createLogEntryFromErrors(sndAddress, rcvAddress []byte, function string) *vmcommon.LogEntry { diff --git a/arwen/hosttest/execution_benchmark_test.go b/arwen/hosttest/execution_benchmark_test.go index bc6a4f0ff..29275270a 100644 --- a/arwen/hosttest/execution_benchmark_test.go +++ b/arwen/hosttest/execution_benchmark_test.go @@ -101,6 +101,7 @@ func deploy(tb testing.TB, totalTokenSupply *big.Int) (arwen.VMHost, *worldmock. ElrondProtectedKeyPrefix: []byte("ELROND"), ESDTTransferParser: esdtTransferParser, EpochNotifier: &mock.EpochNotifierStub{}, + EnableRoundsHandler: &worldmock.EnableRoundsHandlerMock{}, }) require.Nil(tb, err) diff --git a/arwen/interface.go b/arwen/interface.go index 7b0e7e85a..9fef23c9a 100644 --- a/arwen/interface.go +++ b/arwen/interface.go @@ -315,3 +315,9 @@ type GasTracing interface { GetGasTrace() map[string]map[string][]uint64 IsInterfaceNil() bool } + +// EnableRoundsHandler defines the functionality of a component able to tell if certain flags are activated or not +type EnableRoundsHandler interface { + IsCheckValueOnExecByCallerEnabled() bool + IsInterfaceNil() bool +} diff --git a/arwendebug/world.go b/arwendebug/world.go index 0ad55f649..9fa0ab054 100644 --- a/arwendebug/world.go +++ b/arwendebug/world.go @@ -60,6 +60,7 @@ func getHostParameters() *arwen.VMHostParameters { BuiltInFuncContainer: builtInFunctions.NewBuiltInFunctionContainer(), ESDTTransferParser: esdtTransferParser, EpochNotifier: &worldmock.EpochNotifierStub{}, + EnableRoundsHandler: &worldmock.EnableRoundsHandlerMock{}, } } diff --git a/arwenmandos/exec.go b/arwenmandos/exec.go index c559e20b0..022788cf1 100644 --- a/arwenmandos/exec.go +++ b/arwenmandos/exec.go @@ -77,6 +77,7 @@ func (ae *ArwenTestExecutor) InitVM(mandosGasSchedule mj.GasSchedule) error { ElrondProtectedKeyPrefix: []byte(ElrondProtectedKeyPrefix), ESDTTransferParser: esdtTransferParser, EpochNotifier: &worldhook.EpochNotifierStub{}, + EnableRoundsHandler: &worldhook.EnableRoundsHandlerMock{}, }) if err != nil { return err diff --git a/integrationTests/features/pureFunctionUtil.go b/integrationTests/features/pureFunctionUtil.go index 35d6747e0..b5b409484 100644 --- a/integrationTests/features/pureFunctionUtil.go +++ b/integrationTests/features/pureFunctionUtil.go @@ -52,6 +52,7 @@ func newPureFunctionExecutor() (*pureFunctionExecutor, error) { ElrondProtectedKeyPrefix: []byte("ELROND"), ESDTTransferParser: esdtTransferParser, EpochNotifier: &worldhook.EpochNotifierStub{}, + EnableRoundsHandler: &worldhook.EnableRoundsHandlerMock{}, }) if err != nil { return nil, err diff --git a/mock/world/enableRoundsHandlerMock.go b/mock/world/enableRoundsHandlerMock.go new file mode 100644 index 000000000..b7d1b03e0 --- /dev/null +++ b/mock/world/enableRoundsHandlerMock.go @@ -0,0 +1,16 @@ +package worldmock + +// EnableRoundsHandlerMock - +type EnableRoundsHandlerMock struct { + IsCheckValueOnExecByCallerEnabledValue bool +} + +// IsCheckValueOnExecByCallerEnabled - +func (mock *EnableRoundsHandlerMock) IsCheckValueOnExecByCallerEnabled() bool { + return mock.IsCheckValueOnExecByCallerEnabledValue +} + +// IsInterfaceNil - +func (mock *EnableRoundsHandlerMock) IsInterfaceNil() bool { + return mock == nil +} diff --git a/testcommon/testInitializer_inputs.go b/testcommon/testInitializer_inputs.go index 6d024136e..c3c52a56e 100644 --- a/testcommon/testInitializer_inputs.go +++ b/testcommon/testInitializer_inputs.go @@ -290,6 +290,7 @@ func DefaultTestArwenWithWorldMock(tb testing.TB) (arwen.VMHost, *worldmock.Mock ElrondProtectedKeyPrefix: []byte("ELROND"), ESDTTransferParser: esdtTransferParser, EpochNotifier: &worldmock.EpochNotifierStub{}, + EnableRoundsHandler: &worldmock.EnableRoundsHandlerMock{}, }) require.Nil(tb, err) require.NotNil(tb, host) @@ -314,6 +315,7 @@ func DefaultTestArwen(tb testing.TB, blockchain vmcommon.BlockchainHook) arwen.V ESDTTransferParser: esdtTransferParser, EpochNotifier: &worldmock.EpochNotifierStub{}, UseDifferentGasCostForReadingCachedStorageEpoch: 0, + EnableRoundsHandler: &worldmock.EnableRoundsHandlerMock{}, }) require.Nil(tb, err) require.NotNil(tb, host)