-
Notifications
You must be signed in to change notification settings - Fork 231
Introduce semantic wrappers around Execute #3595
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -45,6 +45,32 @@ type CallResult struct { | |
| ExecutionFailed bool | ||
| } | ||
|
|
||
| // SimulateOptions carries the per-request flags relevant to RPC simulate / | ||
| // estimateFee. errStack and allowBinarySearch are constants for this path | ||
| // and are set internally. | ||
| type SimulateOptions struct { | ||
| SkipChargeFee bool | ||
| SkipValidate bool | ||
| ErrOnRevert bool | ||
| IsEstimateFee bool | ||
| ReturnInitialReads bool | ||
| } | ||
|
|
||
| // TraceOptions carries the per-request flags relevant to replaying an | ||
| // existing block. All execution flags are off; only errStack is on. | ||
| type TraceOptions struct { | ||
| ReturnInitialReads bool | ||
| } | ||
|
Comment on lines
+59
to
+63
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it could be a single bollean, but I decided to keep this as a struct, for 2 reasons:
|
||
|
|
||
| // BuildBlockOptions carries flags used when producing a block (builder or | ||
| // genesis bootstrap). errStack is hardcoded true; the trace/estimate flags | ||
| // don't apply here. | ||
| type BuildBlockOptions struct { | ||
| SkipChargeFee bool | ||
| SkipValidate bool | ||
| ErrOnRevert bool | ||
| } | ||
|
|
||
| //go:generate mockgen -destination=../mocks/mock_vm.go -package=mocks github.com/NethermindEth/juno/vm VM | ||
| type VM interface { | ||
| Call( | ||
|
|
@@ -70,6 +96,30 @@ type VM interface { | |
| isEstimateFee bool, | ||
| returnInitialReads bool, | ||
| ) (ExecutionResults, error) | ||
| Simulate( | ||
| txns []core.Transaction, | ||
| declaredClasses []core.ClassDefinition, | ||
| paidFeesOnL1 []*felt.Felt, | ||
| blockInfo *BlockInfo, | ||
| state core.StateReader, | ||
| opts SimulateOptions, | ||
| ) (ExecutionResults, error) | ||
| Trace( | ||
| txns []core.Transaction, | ||
| declaredClasses []core.ClassDefinition, | ||
| paidFeesOnL1 []*felt.Felt, | ||
| blockInfo *BlockInfo, | ||
| state core.StateReader, | ||
| opts TraceOptions, | ||
| ) (ExecutionResults, error) | ||
| BuildBlock( | ||
| txns []core.Transaction, | ||
| declaredClasses []core.ClassDefinition, | ||
| paidFeesOnL1 []*felt.Felt, | ||
| blockInfo *BlockInfo, | ||
| state core.StateReader, | ||
| opts BuildBlockOptions, | ||
| ) (ExecutionResults, error) | ||
| } | ||
|
|
||
| type vm struct { | ||
|
|
@@ -444,6 +494,72 @@ func (v *vm) Execute( | |
| }, nil | ||
| } | ||
|
|
||
| // Simulate runs the txn set under RPC simulate / estimateFee semantics: | ||
| // errStack and allowBinarySearch are always on. | ||
| func (v *vm) Simulate( | ||
| txns []core.Transaction, | ||
| declaredClasses []core.ClassDefinition, | ||
| paidFeesOnL1 []*felt.Felt, | ||
| blockInfo *BlockInfo, | ||
| state core.StateReader, | ||
| opts SimulateOptions, | ||
| ) (ExecutionResults, error) { | ||
| return v.Execute( | ||
| txns, declaredClasses, paidFeesOnL1, blockInfo, state, | ||
| opts.SkipChargeFee, | ||
| opts.SkipValidate, | ||
| opts.ErrOnRevert, | ||
| true, // errStack | ||
| true, // allowBinarySearch | ||
| opts.IsEstimateFee, | ||
| opts.ReturnInitialReads, | ||
| ) | ||
| } | ||
|
|
||
| // Trace replays an existing block. All exec flags are off; only errStack | ||
| // is on so we get structured error frames if anything goes wrong. | ||
| func (v *vm) Trace( | ||
| txns []core.Transaction, | ||
| declaredClasses []core.ClassDefinition, | ||
| paidFeesOnL1 []*felt.Felt, | ||
| blockInfo *BlockInfo, | ||
| state core.StateReader, | ||
| opts TraceOptions, | ||
| ) (ExecutionResults, error) { | ||
| return v.Execute( | ||
| txns, declaredClasses, paidFeesOnL1, blockInfo, state, | ||
| false, // skipChargeFee | ||
| false, // skipValidate | ||
| false, // errOnRevert | ||
| true, // errStack | ||
| false, // allowBinarySearch | ||
| false, // isEstimateFee | ||
| opts.ReturnInitialReads, | ||
| ) | ||
| } | ||
|
|
||
| // BuildBlock executes txns in block-production mode (builder or genesis). | ||
| // errStack is on; trace/estimate flags don't apply. | ||
| func (v *vm) BuildBlock( | ||
| txns []core.Transaction, | ||
| declaredClasses []core.ClassDefinition, | ||
| paidFeesOnL1 []*felt.Felt, | ||
| blockInfo *BlockInfo, | ||
| state core.StateReader, | ||
| opts BuildBlockOptions, | ||
| ) (ExecutionResults, error) { | ||
| return v.Execute( | ||
| txns, declaredClasses, paidFeesOnL1, blockInfo, state, | ||
| opts.SkipChargeFee, | ||
| opts.SkipValidate, | ||
| opts.ErrOnRevert, | ||
| true, // errStack | ||
| false, // allowBinarySearch | ||
| false, // isEstimateFee | ||
| false, // returnInitialReads | ||
| ) | ||
| } | ||
|
|
||
| func marshalTxnsAndDeclaredClasses( | ||
| txns []core.Transaction, | ||
| declaredClasses []core.ClassDefinition, | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
The documentation talking about flags that are constants or pre-defined will be removed after these methods stop depending on
Execute