Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions proto/cosmos/accesscontrol/constants.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ enum ResourceType {
KV_ORACLE = 7; // child of KV
KV_DEX = 8; // child of KV
KV_EPOCH = 9; // child of KV
KV_TOKENFACTORY = 11; // child of KV
}

106 changes: 55 additions & 51 deletions types/accesscontrol/constants.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions types/accesscontrol/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ var ResourceTree = map[ResourceType]TreeNode{
ResourceType_KV_STAKING,
ResourceType_KV_WASM,
}},
ResourceType_Mem: {ResourceType_ANY, []ResourceType{ResourceType_DexMem}},
ResourceType_DexMem: {ResourceType_Mem, []ResourceType{}},
ResourceType_KV_BANK: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_STAKING: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_WASM: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_EPOCH: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_ORACLE: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_DEX: {ResourceType_KV, []ResourceType{}},
ResourceType_Mem: {ResourceType_ANY, []ResourceType{ResourceType_DexMem}},
ResourceType_DexMem: {ResourceType_Mem, []ResourceType{}},
ResourceType_KV_BANK: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_STAKING: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_WASM: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_EPOCH: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_ORACLE: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_DEX: {ResourceType_KV, []ResourceType{}},
ResourceType_KV_TOKENFACTORY: {ResourceType_KV, []ResourceType{}},
}

// This returns a slice of all resource types that are dependent to a specific resource type
Expand Down
28 changes: 24 additions & 4 deletions types/context_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package types

import (
"sync"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)


Expand All @@ -20,34 +22,52 @@ func NewContextMemCache() *ContextMemCache {
}
}

func (c *ContextMemCache) UpsertDeferredSends(moduleAccount string, amount Coins) {
// Separate locks needed for all mappings - atomic transaction needed
func (c *ContextMemCache) UpsertDeferredSends(moduleAccount string, amount Coins) error {
// Separate locks needed for all mappings - atmoic transaction needed
c.deferredBankOpsLock.Lock()
defer c.deferredBankOpsLock.Unlock()

if !amount.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amount.String())
}

// If there's already a pending withdrawal then subtract it from that amount first
// or else add it to the deferredSends mapping
ok := c.deferredWithdrawals.SafeSub(moduleAccount, amount)
if !ok {
c.deferredSends.UpsertMapping(moduleAccount, amount)
}
return nil
}

func (c *ContextMemCache) SafeSubDeferredSends(moduleAccount string, amount Coins) bool {
if !amount.IsValid() {
panic(sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amount.String()))
}

return c.deferredSends.SafeSub(moduleAccount, amount)
}

func (c *ContextMemCache) RangeOnDeferredSendsAndDelete(apply func (recipient string, amount Coins)) {
c.deferredSends.RangeOnMapping(apply)
}

func (c *ContextMemCache) UpsertDeferredWithdrawals(moduleAccount string, amount Coins) {
// Separate locks needed for all mappings - atomic transaction needed
func (c *ContextMemCache) UpsertDeferredWithdrawals(moduleAccount string, amount Coins) error {
// Separate locks needed for all mappings - atmoic transaction needed
c.deferredBankOpsLock.Lock()
defer c.deferredBankOpsLock.Unlock()

if !amount.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amount.String())
}

// If there's already a pending deposit then subtract it from that amount first
// or else add it to the deferredWithdrawals mapping
ok := c.deferredSends.SafeSub(moduleAccount, amount)
if !ok {
c.deferredWithdrawals.UpsertMapping(moduleAccount, amount)
}
return nil
}

func (c *ContextMemCache) RangeOnDeferredWithdrawalsAndDelete(apply func (recipient string, amount Coins)) {
Expand Down
15 changes: 2 additions & 13 deletions types/deferred_bank_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,16 @@ func NewDeferredBankOperationMap() *DeferredBankOperationMapping {
}
}

func (m *DeferredBankOperationMapping) get(moduleAccount string) (Coins, bool) {
if v, ok := m.deferredOperations[moduleAccount]; ok {
return v, true
}
return nil, false
}

func (m *DeferredBankOperationMapping) set(moduleAccount string, amount Coins) {
m.deferredOperations[moduleAccount] = amount
}

// If there's already a pending opposite operation then subtract it from that amount first
// returns true if amount was subtracted
func (m *DeferredBankOperationMapping) SafeSub(moduleAccount string, amount Coins) bool {
m.mappingLock.Lock()
defer m.mappingLock.Unlock()

if deferredAmount, ok := m.get(moduleAccount); ok {
if deferredAmount, ok := m.deferredOperations[moduleAccount]; ok {
newAmount, isNegative := deferredAmount.SafeSub(amount)
if !isNegative {
m.set(moduleAccount, newAmount)
m.deferredOperations[moduleAccount] = newAmount
return true
}
}
Expand Down
3 changes: 3 additions & 0 deletions x/auth/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ import (
type BankKeeper interface {
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
DeferredSendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
DeferredSendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amount sdk.Coins) error
DeferredMintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
DeferredBurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
}
Loading