-
Notifications
You must be signed in to change notification settings - Fork 180
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
[Flow EVM] update error handling #5357
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
194c9b9
refactor emulator errors
ramtinms 26f938a
update validation errors
ramtinms 36e64e2
prepare handler for try methods
ramtinms f38c939
error handling
ramtinms 9c032f5
add error codes
ramtinms 7da9249
renaming
ramtinms e320e7f
update error codes
ramtinms 43dd68a
update tests
ramtinms 60a3431
clean up
ramtinms b0e7691
.
ramtinms babd5d8
move to wrapped backend
ramtinms 8a215ec
Merge branch 'master' into ramtin/5225-returning-error
ramtinms 6ed9a45
refactor wrapped backend
ramtinms 45193eb
.
ramtinms 70c2211
fix tests
ramtinms 42418ed
error improvements
ramtinms 685dc44
add tests for try run
ramtinms 37d820f
clean up
ramtinms 47e978a
fix tests
ramtinms 9c5845b
remove print line
ramtinms 6a6d16b
lint fix
ramtinms d646067
Merge branch 'master' into ramtin/5225-returning-error
ramtinms 288b261
lint fix
ramtinms 53fa23c
Merge branch 'master' into ramtin/5225-returning-error
ramtinms 1bfaf08
Merge branch 'master' into ramtin/5225-returning-error
ramtinms d3f2568
fix test
ramtinms 6c00c5b
use validation error for balance checks
ramtinms 5b89a51
.
ramtinms b4f04af
.
ramtinms 32a6d24
fix test
ramtinms af7dcb5
reduce block store capacity to 16 for now
ramtinms 288a24d
Merge branch 'master' into ramtin/5225-returning-error
ramtinms cb54731
Merge branch 'master' into ramtin/5225-returning-error
ramtinms b3eef9e
Merge branch 'master' into ramtin/5225-returning-error
ramtinms 2159604
apply PR feedback
ramtinms ad735a5
Merge branch 'master' into ramtin/5225-returning-error
franklywatson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package backends | ||
|
||
import ( | ||
"github.com/onflow/atree" | ||
"github.com/onflow/cadence" | ||
"github.com/onflow/cadence/runtime" | ||
"github.com/onflow/cadence/runtime/common" | ||
|
||
"github.com/onflow/flow-go/fvm/environment" | ||
"github.com/onflow/flow-go/fvm/errors" | ||
"github.com/onflow/flow-go/fvm/evm/types" | ||
"github.com/onflow/flow-go/fvm/meter" | ||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
// WrappedEnvironment wraps an FVM environment | ||
type WrappedEnvironment struct { | ||
env environment.Environment | ||
} | ||
|
||
// NewWrappedEnvironment constructs a new wrapped environment | ||
func NewWrappedEnvironment(env environment.Environment) types.Backend { | ||
return &WrappedEnvironment{env} | ||
} | ||
|
||
var _ types.Backend = &WrappedEnvironment{} | ||
|
||
func (we *WrappedEnvironment) GetValue(owner, key []byte) ([]byte, error) { | ||
val, err := we.env.GetValue(owner, key) | ||
return val, handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) SetValue(owner, key, value []byte) error { | ||
err := we.env.SetValue(owner, key, value) | ||
return handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) ValueExists(owner, key []byte) (bool, error) { | ||
b, err := we.env.ValueExists(owner, key) | ||
return b, handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error) { | ||
index, err := we.env.AllocateStorageIndex(owner) | ||
return index, handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) MeterComputation(kind common.ComputationKind, intensity uint) error { | ||
err := we.env.MeterComputation(kind, intensity) | ||
return handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) ComputationUsed() (uint64, error) { | ||
val, err := we.env.ComputationUsed() | ||
return val, handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) ComputationIntensities() meter.MeteredComputationIntensities { | ||
return we.env.ComputationIntensities() | ||
} | ||
|
||
func (we *WrappedEnvironment) ComputationAvailable(kind common.ComputationKind, intensity uint) bool { | ||
return we.env.ComputationAvailable(kind, intensity) | ||
} | ||
|
||
func (we *WrappedEnvironment) MeterMemory(usage common.MemoryUsage) error { | ||
err := we.env.MeterMemory(usage) | ||
return handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) MemoryUsed() (uint64, error) { | ||
val, err := we.env.MemoryUsed() | ||
return val, handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) MeterEmittedEvent(byteSize uint64) error { | ||
err := we.env.MeterEmittedEvent(byteSize) | ||
return handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) TotalEmittedEventBytes() uint64 { | ||
return we.env.TotalEmittedEventBytes() | ||
} | ||
|
||
func (we *WrappedEnvironment) InteractionUsed() (uint64, error) { | ||
val, err := we.env.InteractionUsed() | ||
return val, handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) EmitEvent(event cadence.Event) error { | ||
err := we.env.EmitEvent(event) | ||
return handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) Events() flow.EventsList { | ||
return we.env.Events() | ||
|
||
} | ||
|
||
func (we *WrappedEnvironment) ServiceEvents() flow.EventsList { | ||
return we.env.ServiceEvents() | ||
} | ||
|
||
func (we *WrappedEnvironment) ConvertedServiceEvents() flow.ServiceEventList { | ||
return we.env.ConvertedServiceEvents() | ||
} | ||
|
||
func (we *WrappedEnvironment) Reset() { | ||
we.env.Reset() | ||
} | ||
|
||
func (we *WrappedEnvironment) GetCurrentBlockHeight() (uint64, error) { | ||
val, err := we.env.GetCurrentBlockHeight() | ||
return val, handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) GetBlockAtHeight(height uint64) ( | ||
runtime.Block, | ||
bool, | ||
error, | ||
) { | ||
val, found, err := we.env.GetBlockAtHeight(height) | ||
return val, found, handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) ReadRandom(buffer []byte) error { | ||
err := we.env.ReadRandom(buffer) | ||
return handleEnvironmentError(err) | ||
} | ||
|
||
func (we *WrappedEnvironment) Invoke( | ||
spec environment.ContractFunctionSpec, | ||
arguments []cadence.Value, | ||
) ( | ||
cadence.Value, | ||
error, | ||
) { | ||
val, err := we.env.Invoke(spec, arguments) | ||
return val, handleEnvironmentError(err) | ||
} | ||
|
||
func handleEnvironmentError(err error) error { | ||
if err == nil { | ||
return nil | ||
} | ||
|
||
// fvm fatal errors | ||
if errors.IsFailure(err) { | ||
return types.NewFatalError(err) | ||
} | ||
|
||
return types.NewBackendError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these don't need to be pointer receivers.