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

Add back actionID to StateKeys() #1683

Merged
merged 4 commits into from
Oct 24, 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
2 changes: 1 addition & 1 deletion api/jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (j *JSONRPCServer) ExecuteActions(

for actionIndex, action := range actions {
// Get expected state keys
stateKeysWithPermissions := action.StateKeys(args.Actor)
stateKeysWithPermissions := action.StateKeys(args.Actor, ids.Empty)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use CreateActionID(ids.Empty, actionIndex) here? This ensures that each simulated action gets a unique actionID during the simulation and that it will never overlap with an actual actionID that was already used onchain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


// flatten the map to a slice of keys
storageKeysToRead := make([][]byte, 0, len(stateKeysWithPermissions))
Expand Down
2 changes: 1 addition & 1 deletion chain/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ type Action interface {
// key (formatted as a big-endian uint16). This is used to automatically calculate storage usage.
//
// If any key is removed and then re-created, this will count as a creation instead of a modification.
StateKeys(actor codec.Address) state.Keys
StateKeys(actor codec.Address, actionID ids.ID) state.Keys

// Execute actually runs the [Action]. Any state changes that the [Action] performs should
// be done here.
Expand Down
6 changes: 3 additions & 3 deletions chain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ func (t *Transaction) StateKeys(bh BalanceHandler) (state.Keys, error) {
stateKeys := make(state.Keys)

// Verify the formatting of state keys passed by the controller
for _, action := range t.Actions {
for k, v := range action.StateKeys(t.Auth.Actor()) {
for i, action := range t.Actions {
for k, v := range action.StateKeys(t.Auth.Actor(), CreateActionID(t.ID(), uint8(i))) {
if !stateKeys.Add(k, v) {
return nil, ErrInvalidKeyValue
}
Expand Down Expand Up @@ -524,7 +524,7 @@ func EstimateUnits(r Rules, actions Actions, authFactory AuthFactory) (fees.Dime
}

actor := authFactory.Address()
stateKeys := action.StateKeys(actor)
stateKeys := action.StateKeys(actor, ids.Empty)
actionStateKeysMaxChunks, ok := stateKeys.ChunkSizes()
if !ok {
return fees.Dimensions{}, ErrInvalidKeyValue
Expand Down
2 changes: 1 addition & 1 deletion chain/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (*abstractMockAction) Execute(_ context.Context, _ chain.Rules, _ state.Mut
panic("unimplemented")
}

func (*abstractMockAction) StateKeys(_ codec.Address) state.Keys {
func (*abstractMockAction) StateKeys(_ codec.Address, _ ids.ID) state.Keys {
panic("unimplemented")
}

Expand Down
2 changes: 1 addition & 1 deletion examples/morpheusvm/actions/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (*Transfer) GetTypeID() uint8 {
return mconsts.TransferID
}

func (t *Transfer) StateKeys(actor codec.Address) state.Keys {
func (t *Transfer) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
return state.Keys{
string(storage.BalanceKey(actor)): state.Read | state.Write,
string(storage.BalanceKey(t.To)): state.All,
Expand Down
2 changes: 1 addition & 1 deletion examples/vmwithcontracts/actions/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (*Call) GetTypeID() uint8 {
return mconsts.CallContractID
}

func (t *Call) StateKeys(_ codec.Address) state.Keys {
func (t *Call) StateKeys(_ codec.Address, _ ids.ID) state.Keys {
result := state.Keys{}
for _, stateKeyPermission := range t.SpecifiedStateKeys {
result.Add(stateKeyPermission.Key, stateKeyPermission.Permission)
Expand Down
2 changes: 1 addition & 1 deletion examples/vmwithcontracts/actions/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (*Deploy) GetTypeID() uint8 {
return mconsts.DeployID
}

func (d *Deploy) StateKeys(_ codec.Address) state.Keys {
func (d *Deploy) StateKeys(_ codec.Address, _ ids.ID) state.Keys {
if d.address == codec.EmptyAddress {
d.address = storage.GetAddressForDeploy(0, d.CreationInfo)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vmwithcontracts/actions/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (*Publish) GetTypeID() uint8 {
return mconsts.PublishID
}

func (t *Publish) StateKeys(_ codec.Address) state.Keys {
func (t *Publish) StateKeys(_ codec.Address, _ ids.ID) state.Keys {
if t.id == nil {
hashedID := sha256.Sum256(t.ContractBytes)
t.id, _ = keys.Encode(storage.ContractsKey(hashedID[:]), len(t.ContractBytes))
Expand Down
2 changes: 1 addition & 1 deletion examples/vmwithcontracts/actions/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (*Transfer) GetTypeID() uint8 {
return mconsts.TransferID
}

func (t *Transfer) StateKeys(actor codec.Address) state.Keys {
func (t *Transfer) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
return state.Keys{
string(storage.BalanceKey(actor)): state.Read | state.Write,
string(storage.BalanceKey(t.To)): state.All,
Expand Down
Loading