Skip to content

Commit

Permalink
add Action limit to Rules and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wlawt committed Apr 21, 2024
1 parent 70905e2 commit 579dad0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions chain/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ type Rules interface {
GetWarpConfig(sourceChainID ids.ID) (bool, uint64, uint64)

FetchCustom(string) (any, bool)

GetMaxActionsPerTx() uint8
}

type MetadataManager interface {
Expand Down
13 changes: 8 additions & 5 deletions chain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ func (t *Transaction) StateKeys(sm StateManager) (state.Keys, error) {
stateKeys := make(state.Keys)

Check failure on line 141 in chain/transaction.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

no new variables on left side of :=

Check failure on line 141 in chain/transaction.go

View workflow job for this annotation

GitHub Actions / hypersdk-unit-tests

no new variables on left side of :=
for _, m := range []state.Keys{actionKeys, sponsorKeys} {
for k, v := range m {
// Handle incoming warp message keys
if t.WarpMessage != nil {
p := sm.IncomingWarpKeyPrefix(t.WarpMessage.SourceChainID, t.warpID)
k := keys.EncodeChunks(p, MaxIncomingWarpChunks)
stateKeys.Add(string(k))
// Handle incoming warp message keys
if t.WarpMessage != nil {
p := sm.IncomingWarpKeyPrefix(t.WarpMessage.SourceChainID, t.warpID)
k := keys.EncodeChunks(p, MaxIncomingWarpChunks)
stateKeys.Add(string(k))
}
}
}

// Handle action/auth keys
Expand Down Expand Up @@ -181,6 +183,7 @@ func (t *Transaction) StateKeys(sm StateManager) (state.Keys, error) {
p := sm.OutgoingWarpKeyPrefix(t.id)
k := keys.EncodeChunks(p, MaxOutgoingWarpChunks)
stateKeys.Add(string(k), state.Allocate|state.Write)
}
for _, k := range sm.SponsorStateKeys(t.Auth.Sponsor()) {
if !keys.Valid(k) {
return nil, ErrInvalidKeyValue
Expand Down
6 changes: 6 additions & 0 deletions examples/morpheusvm/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type Genesis struct {
StorageKeyWriteUnits uint64 `json:"storageKeyWriteUnits"`
StorageValueWriteUnits uint64 `json:"storageValueWriteUnits"` // per chunk

// Action Per Tx
MaxActionsPerTx uint8 `json:"maxActionsPerTx"`

// Allocates
CustomAllocation []*CustomAllocation `json:"customAllocation"`
}
Expand Down Expand Up @@ -94,6 +97,9 @@ func Default() *Genesis {
StorageValueAllocateUnits: 5,
StorageKeyWriteUnits: 10,
StorageValueWriteUnits: 3,

// Action Per Tx
MaxActionsPerTx: 1,
}
}

Expand Down
4 changes: 4 additions & 0 deletions examples/morpheusvm/genesis/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ func (r *Rules) GetWindowTargetUnits() fees.Dimensions {
func (*Rules) FetchCustom(string) (any, bool) {
return nil, false
}

func (*Rules) GetMaxActionsPerTx() uint8 {
return r.g.MaxActionsPerTx
}
6 changes: 6 additions & 0 deletions examples/tokenvm/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type Genesis struct {
StorageKeyWriteUnits uint64 `json:"storageKeyWriteUnits"`
StorageValueWriteUnits uint64 `json:"storageValueWriteUnits"` // per chunk

// Action Per Tx
MaxActionsPerTx uint8 `json:"maxActionsPerTx"`

// Allocates
CustomAllocation []*CustomAllocation `json:"customAllocation"`
}
Expand Down Expand Up @@ -95,6 +98,9 @@ func Default() *Genesis {
StorageValueAllocateUnits: 5,
StorageKeyWriteUnits: 10,
StorageValueWriteUnits: 3,

// Action Per Tx
MaxActionsPerTx: 1,
}
}

Expand Down
4 changes: 4 additions & 0 deletions examples/tokenvm/genesis/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ func (r *Rules) GetWindowTargetUnits() fees.Dimensions {
func (*Rules) FetchCustom(string) (any, bool) {
return nil, false
}

func (*Rules) GetMaxActionsPerTx() uint8 {
return r.g.MaxActionsPerTx
}

0 comments on commit 579dad0

Please sign in to comment.