From 579dad071ae6fcd62fa342d7d6235974bd6e4347 Mon Sep 17 00:00:00 2001 From: William Law Date: Sun, 21 Apr 2024 15:33:59 -0400 Subject: [PATCH] add Action limit to Rules and lint --- chain/dependencies.go | 2 ++ chain/transaction.go | 13 ++++++++----- examples/morpheusvm/genesis/genesis.go | 6 ++++++ examples/morpheusvm/genesis/rules.go | 4 ++++ examples/tokenvm/genesis/genesis.go | 6 ++++++ examples/tokenvm/genesis/rules.go | 4 ++++ 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/chain/dependencies.go b/chain/dependencies.go index 6ceddda353..902cff7fae 100644 --- a/chain/dependencies.go +++ b/chain/dependencies.go @@ -158,6 +158,8 @@ type Rules interface { GetWarpConfig(sourceChainID ids.ID) (bool, uint64, uint64) FetchCustom(string) (any, bool) + + GetMaxActionsPerTx() uint8 } type MetadataManager interface { diff --git a/chain/transaction.go b/chain/transaction.go index c88ad44004..118f687262 100644 --- a/chain/transaction.go +++ b/chain/transaction.go @@ -141,11 +141,13 @@ func (t *Transaction) StateKeys(sm StateManager) (state.Keys, error) { stateKeys := make(state.Keys) 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 @@ -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 diff --git a/examples/morpheusvm/genesis/genesis.go b/examples/morpheusvm/genesis/genesis.go index 74962b5c96..d6460f180c 100644 --- a/examples/morpheusvm/genesis/genesis.go +++ b/examples/morpheusvm/genesis/genesis.go @@ -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"` } @@ -94,6 +97,9 @@ func Default() *Genesis { StorageValueAllocateUnits: 5, StorageKeyWriteUnits: 10, StorageValueWriteUnits: 3, + + // Action Per Tx + MaxActionsPerTx: 1, } } diff --git a/examples/morpheusvm/genesis/rules.go b/examples/morpheusvm/genesis/rules.go index 0a37046203..4c91dd9f6a 100644 --- a/examples/morpheusvm/genesis/rules.go +++ b/examples/morpheusvm/genesis/rules.go @@ -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 +} diff --git a/examples/tokenvm/genesis/genesis.go b/examples/tokenvm/genesis/genesis.go index 23f45e91c8..393172861c 100644 --- a/examples/tokenvm/genesis/genesis.go +++ b/examples/tokenvm/genesis/genesis.go @@ -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"` } @@ -95,6 +98,9 @@ func Default() *Genesis { StorageValueAllocateUnits: 5, StorageKeyWriteUnits: 10, StorageValueWriteUnits: 3, + + // Action Per Tx + MaxActionsPerTx: 1, } } diff --git a/examples/tokenvm/genesis/rules.go b/examples/tokenvm/genesis/rules.go index b2fac9c3f5..553fab462f 100644 --- a/examples/tokenvm/genesis/rules.go +++ b/examples/tokenvm/genesis/rules.go @@ -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 +}