-
Notifications
You must be signed in to change notification settings - Fork 106
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
Use CreateActionID to give simulated actions unique actionID #1644
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aa2ad21
use createActionID in simulated actions and pre-allocate
aaronbuchwald 4580a0d
Merge branch 'main' into upgrade-actions-sim-nits
aaronbuchwald 811ea2e
fix lint
aaronbuchwald 310db99
Merge branch 'main' into upgrade-actions-sim-nits
aaronbuchwald 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ const ( | |
Endpoint = "/coreapi" | ||
) | ||
|
||
var errNoActionsToExecute = errors.New("no actions to execute") | ||
|
||
var _ api.HandlerFactory[api.VM] = (*JSONRPCServerFactory)(nil) | ||
|
||
var ( | ||
|
@@ -171,7 +173,7 @@ type ExecuteActionReply struct { | |
Error string `json:"error"` | ||
} | ||
|
||
func (j *JSONRPCServer) Execute( | ||
func (j *JSONRPCServer) ExecuteActions( | ||
req *http.Request, | ||
args *ExecuteActionArgs, | ||
reply *ExecuteActionReply, | ||
|
@@ -180,7 +182,13 @@ func (j *JSONRPCServer) Execute( | |
defer span.End() | ||
|
||
actionCodec := j.vm.ActionCodec() | ||
actions := make([]chain.Action, 0) | ||
if len(args.Actions) == 0 { | ||
return errNoActionsToExecute | ||
} | ||
if maxActionsPerTx := int(j.vm.Rules(time.Now().Unix()).GetMaxActionsPerTx()); len(args.Actions) > maxActionsPerTx { | ||
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. Good catch! |
||
return fmt.Errorf("exceeded max actions per simulation: %d", maxActionsPerTx) | ||
} | ||
actions := make([]chain.Action, 0, len(args.Actions)) | ||
for _, action := range args.Actions { | ||
action, err := actionCodec.Unmarshal(codec.NewReader(action, len(action))) | ||
if err != nil { | ||
|
@@ -194,12 +202,12 @@ func (j *JSONRPCServer) Execute( | |
storage := make(map[string][]byte) | ||
ts := tstate.New(1) | ||
|
||
for _, action := range actions { | ||
for actionIndex, action := range actions { | ||
// Get expected state keys | ||
stateKeysWithPermissions := action.StateKeys(args.Actor) | ||
|
||
// flatten the map to a slice of keys | ||
storageKeysToRead := make([][]byte, 0) | ||
storageKeysToRead := make([][]byte, 0, len(stateKeysWithPermissions)) | ||
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. TIL |
||
for key := range stateKeysWithPermissions { | ||
storageKeysToRead = append(storageKeysToRead, []byte(key)) | ||
} | ||
|
@@ -225,7 +233,7 @@ func (j *JSONRPCServer) Execute( | |
tsv, | ||
now, | ||
args.Actor, | ||
ids.Empty, | ||
chain.CreateActionID(ids.Empty, uint8(actionIndex)), | ||
) | ||
if err != nil { | ||
reply.Error = fmt.Sprintf("failed to execute action: %s", err) | ||
|
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.
I'm happy it's been renamed back.