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

With fault refactor #873

Merged
merged 9 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
61 changes: 1 addition & 60 deletions mock/context/runtimeContextWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,30 +260,6 @@ func NewRuntimeContextWrapper(inputRuntimeContext *vmhost.RuntimeContext) *Runti
runtimeWrapper.runtimeContext.SetPointsUsed(gasPoints)
}

runtimeWrapper.BaseOpsErrorShouldFailExecutionFunc = func() bool {
return runtimeWrapper.runtimeContext.BaseOpsErrorShouldFailExecution()
}

runtimeWrapper.SyncExecAPIErrorShouldFailExecutionFunc = func() bool {
return runtimeWrapper.runtimeContext.SyncExecAPIErrorShouldFailExecution()
}

runtimeWrapper.CryptoAPIErrorShouldFailExecutionFunc = func() bool {
return runtimeWrapper.runtimeContext.CryptoAPIErrorShouldFailExecution()
}

runtimeWrapper.BigIntAPIErrorShouldFailExecutionFunc = func() bool {
return runtimeWrapper.runtimeContext.BigIntAPIErrorShouldFailExecution()
}

runtimeWrapper.BigFloatAPIErrorShouldFailExecutionFunc = func() bool {
return runtimeWrapper.runtimeContext.BigFloatAPIErrorShouldFailExecution()
}

runtimeWrapper.ManagedBufferAPIErrorShouldFailExecutionFunc = func() bool {
return runtimeWrapper.runtimeContext.ManagedBufferAPIErrorShouldFailExecution()
}

runtimeWrapper.AddErrorFunc = func(err error, otherInfo ...string) {
runtimeWrapper.runtimeContext.AddError(err, otherInfo...)
}
Expand Down Expand Up @@ -498,41 +474,6 @@ func (contextWrapper *RuntimeContextWrapper) SetPointsUsed(gasPoints uint64) {
contextWrapper.SetPointsUsedFunc(gasPoints)
}

// BaseOpsErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) BaseOpsErrorShouldFailExecution() bool {
return contextWrapper.BaseOpsErrorShouldFailExecutionFunc()
}

// SyncExecAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) SyncExecAPIErrorShouldFailExecution() bool {
return contextWrapper.SyncExecAPIErrorShouldFailExecutionFunc()
}

// CryptoAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) CryptoAPIErrorShouldFailExecution() bool {
return contextWrapper.CryptoAPIErrorShouldFailExecutionFunc()
}

// BigIntAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) BigIntAPIErrorShouldFailExecution() bool {
return contextWrapper.BigIntAPIErrorShouldFailExecutionFunc()
}

// BigFloatAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) BigFloatAPIErrorShouldFailExecution() bool {
return contextWrapper.BigFloatAPIErrorShouldFailExecutionFunc()
}

// ManagedBufferAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) ManagedBufferAPIErrorShouldFailExecution() bool {
return contextWrapper.runtimeContext.ManagedBufferAPIErrorShouldFailExecution()
}

// ManagedMapAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) ManagedMapAPIErrorShouldFailExecution() bool {
return contextWrapper.runtimeContext.ManagedMapAPIErrorShouldFailExecution()
}

// UseGasBoundedShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) UseGasBoundedShouldFailExecution() bool {
return contextWrapper.runtimeContext.UseGasBoundedShouldFailExecution()
Expand All @@ -544,7 +485,7 @@ func (contextWrapper *RuntimeContextWrapper) GetVMExecutor() executor.Executor {
}

// ReplaceVMExecutor mocked method
func (contextWrapper *RuntimeContextWrapper) ReplaceVMExecutor(vmExecutor executor.Executor) {
func (contextWrapper *RuntimeContextWrapper) ReplaceVMExecutor(_ executor.Executor) {
}

// AddError calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
Expand Down
5 changes: 3 additions & 2 deletions vmhost/contexts/blockchain.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package contexts

import (
"github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks"
"math/big"

"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data/esdt"
logger "github.com/multiversx/mx-chain-logger-go"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/multiversx/mx-chain-vm-go/vmhost"
"github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks"
)

var logBlockchain = logger.GetOrCreate("vm/blockchainContext")
Expand Down Expand Up @@ -317,7 +317,8 @@ func (context *blockchainContext) PopSetActiveState() {

prevSnapshot := context.stateStack[stateStackLen-1]
err := context.blockChainHook.RevertToSnapshot(prevSnapshot)
if vmhooks.WithFaultAndHost(context.host, err, true) {
if err != nil {
vmhooks.FailExecution(context.host, err)
context.host.Runtime().AddError(err, "RevertToSnapshot")
logBlockchain.Error("PopSetActiveState RevertToSnapshot", "error", err)
return
Expand Down
38 changes: 0 additions & 38 deletions vmhost/contexts/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,44 +702,6 @@ func (context *runtimeContext) checkIfContainsNewCryptoApi() error {
return nil
}

// BaseOpsErrorShouldFailExecution returns true
func (context *runtimeContext) BaseOpsErrorShouldFailExecution() bool {
return true
}

// SyncExecAPIErrorShouldFailExecution specifies whether an error in the
// EEI functions for synchronous execution should abort contract execution.
func (context *runtimeContext) SyncExecAPIErrorShouldFailExecution() bool {
return true
}

// BigIntAPIErrorShouldFailExecution specifies whether an error in the EEI
// functions for BigInt operations should abort contract execution.
func (context *runtimeContext) BigIntAPIErrorShouldFailExecution() bool {
return true
}

// BigFloatAPIErrorShouldFailExecution returns true
func (context *runtimeContext) BigFloatAPIErrorShouldFailExecution() bool {
return true
}

// CryptoAPIErrorShouldFailExecution specifies whether an error in the EEI
// functions for crypto operations should abort contract execution.
func (context *runtimeContext) CryptoAPIErrorShouldFailExecution() bool {
return true
}

// ManagedBufferAPIErrorShouldFailExecution returns true
func (context *runtimeContext) ManagedBufferAPIErrorShouldFailExecution() bool {
return true
}

// ManagedMapAPIErrorShouldFailExecution returns true
func (context *runtimeContext) ManagedMapAPIErrorShouldFailExecution() bool {
return true
}

// UseGasBoundedShouldFailExecution returns true when flag activated
func (context *runtimeContext) UseGasBoundedShouldFailExecution() bool {
return context.host.EnableEpochsHandler().IsFlagEnabled(vmhost.UseGasBoundedShouldFailExecutionFlag)
Expand Down
Loading
Loading