Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable round handler #572

Draft
wants to merge 4 commits into
base: try-test-11
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arwen/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion arwen/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
16 changes: 7 additions & 9 deletions arwen/host/arwen.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type vmHost struct {
scAPIMethods *wasmer.Imports
builtInFuncContainer vmcommon.BuiltInFunctionContainer
esdtTransferParser vmcommon.ESDTTransferParser
enableRoundsHandler arwen.EnableRoundsHandler

multiESDTTransferAsyncCallBackEnableEpoch uint32
flagMultiESDTTransferAsyncCallBack atomic.Flag
Expand All @@ -66,9 +67,6 @@ type vmHost struct {

useDifferentGasCostForReadingCachedStorageEpoch uint32
flagUseDifferentGasCostForCachedStorage atomic.Flag

checkValueOnExecByCallerEnableEpoch uint32
flagCheckValueOnExecByCaller atomic.Flag
}

// NewArwenVM creates a new Arwen vmHost
Expand All @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions arwen/hosttest/execution_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions arwen/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions arwendebug/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func getHostParameters() *arwen.VMHostParameters {
BuiltInFuncContainer: builtInFunctions.NewBuiltInFunctionContainer(),
ESDTTransferParser: esdtTransferParser,
EpochNotifier: &worldmock.EpochNotifierStub{},
EnableRoundsHandler: &worldmock.EnableRoundsHandlerMock{},
}
}

Expand Down
1 change: 1 addition & 0 deletions arwenmandos/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions integrationTests/features/pureFunctionUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions mock/world/enableRoundsHandlerMock.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions testcommon/testInitializer_inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down