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

Use CreateActionID to give simulated actions unique actionID #1644

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions api/jsonrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func (cli *JSONRPCClient) GetABI(ctx context.Context) (abi.ABI, error) {
return resp.ABI, err
}

func (cli *JSONRPCClient) Execute(ctx context.Context, actor codec.Address, actions []chain.Action) ([][]byte, error) {
actionsMarshaled := make([][]byte, 0)
func (cli *JSONRPCClient) ExecuteActions(ctx context.Context, actor codec.Address, actions []chain.Action) ([][]byte, error) {
Copy link
Contributor

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.

actionsMarshaled := make([][]byte, 0, len(actions))
for _, action := range actions {
actionBytes, err := chain.MarshalTyped(action)
if err != nil {
Expand All @@ -212,7 +212,7 @@ func (cli *JSONRPCClient) Execute(ctx context.Context, actor codec.Address, acti
resp := new(ExecuteActionReply)
err := cli.requester.SendRequest(
ctx,
"execute",
"executeActions",
args,
resp,
)
Expand All @@ -238,4 +238,4 @@ func Wait(ctx context.Context, interval time.Duration, check func(ctx context.Co
time.Sleep(interval)
}
return ctx.Err()
}
}
18 changes: 13 additions & 5 deletions api/jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
Endpoint = "/coreapi"
)

var errNoActionsToExecute = errors.New("no actions to execute")

var _ api.HandlerFactory[api.VM] = (*JSONRPCServerFactory)(nil)

type JSONRPCServerFactory struct{}
Expand Down Expand Up @@ -166,7 +168,7 @@ type ExecuteActionReply struct {
Error string `json:"error"`
}

func (j *JSONRPCServer) Execute(
func (j *JSONRPCServer) ExecuteActions(
req *http.Request,
args *ExecuteActionArgs,
reply *ExecuteActionReply,
Expand All @@ -175,7 +177,13 @@ func (j *JSONRPCServer) Execute(
defer span.End()

actionRegistry := j.vm.ActionRegistry()
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 := (*actionRegistry).Unmarshal(codec.NewReader(action, len(action)))
if err != nil {
Expand All @@ -189,12 +197,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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

for key := range stateKeysWithPermissions {
storageKeysToRead = append(storageKeysToRead, []byte(key))
}
Expand All @@ -220,7 +228,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)
Expand Down
Loading