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

refactor deferred balance to use memkv #287

Merged
merged 5 commits into from
Jun 14, 2023
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
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
// Dont need to validate in checkTx mode
if ctx.MsgValidator() != nil && mode == runTxModeDeliver {
storeAccessOpEvents := msCache.GetEvents()
accessOps, _ := app.anteDepGenerator([]acltypes.AccessOperation{}, tx)
accessOps := ctx.TxMsgAccessOps()[acltypes.ANTE_MSG_INDEX]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @BrandonWeng is there a specific reason you have previously called the dependency generator here? I assume it was because you may not have been aware that the -1 key was reserved for the access ops generated for the ante handler ahead of time? but just want to make sure there wasnt some other reason

Copy link
Contributor

Choose a reason for hiding this comment

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

Teah that was most likely the case


missingAccessOps := ctx.MsgValidator().ValidateAccessOperations(accessOps, storeAccessOpEvents)
if len(missingAccessOps) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
}
// check block gas is always consumed - this value may change if we update the logic for
// how gas is consumed
baseGas := uint64(52585) // baseGas is the gas consumed before tx msg
baseGas := uint64(58406) // baseGas is the gas consumed before tx msg
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
if expGasConsumed > txtypes.MaxGasWanted {
// capped by gasLimit
Expand Down
3 changes: 3 additions & 0 deletions proto/cosmos/accesscontrol/constants.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ enum ResourceType {
KV_DEX_CONTRACT = 90; // child of KV_DEX
KV_DEX_LONG_ORDER_COUNT = 91; // child of KV_DEX
KV_DEX_SHORT_ORDER_COUNT = 92; // child of KV_DEX

KV_BANK_DEFERRED = 93; // child of KV
KV_BANK_DEFERRED_MODULE_TX_INDEX = 95; // child of KV_BANK_DEFERRED
}

enum WasmMessageSubtype {
Expand Down
6 changes: 3 additions & 3 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func NewSimApp(
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
// NOTE: The testingkey is just mounted for testing purposes. Actual applications should
// not include this key.
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, "testingkey")
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, "testingkey", banktypes.DeferredCacheStoreKey)

// configure state listening capabilities using AppOptions
// we are doing nothing with the returned streamingServices and waitGroup in this case
Expand Down Expand Up @@ -259,8 +259,8 @@ func NewSimApp(
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),
app.BankKeeper = bankkeeper.NewBaseKeeperWithDeferredCache(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(), memKeys[banktypes.DeferredCacheStoreKey],
)
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
Expand Down
3 changes: 3 additions & 0 deletions types/accesscontrol/comparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var (
}
)

// We generate dependencies on a per message basis for a trnasaction, but antehandlers also use resources. As a result we use -1 for the ante handler index (used as map key) to indicate that it is prior to msgs in the tx
const ANTE_MSG_INDEX = int(-1)

type Comparator struct {
AccessType AccessType
Identifier string
Expand Down
189 changes: 98 additions & 91 deletions types/accesscontrol/constants.pb.go

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions types/accesscontrol/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var ResourceTree = map[ResourceType]TreeNode{
ResourceType_KV_AUTHZ,
ResourceType_KV_FEEGRANT,
ResourceType_KV_SLASHING,
ResourceType_KV_BANK_DEFERRED,
}},
ResourceType_Mem: {ResourceType_ANY, []ResourceType{
ResourceType_DexMem,
Expand All @@ -31,9 +32,11 @@ var ResourceTree = map[ResourceType]TreeNode{
ResourceType_KV_BANK_DENOM,
ResourceType_KV_BANK_BALANCES,
}},
ResourceType_KV_BANK_SUPPLY: {ResourceType_KV_BANK, []ResourceType{}},
ResourceType_KV_BANK_DENOM: {ResourceType_KV_BANK, []ResourceType{}},
ResourceType_KV_BANK_BALANCES: {ResourceType_KV_BANK, []ResourceType{}},
ResourceType_KV_BANK_SUPPLY: {ResourceType_KV_BANK, []ResourceType{}},
ResourceType_KV_BANK_DENOM: {ResourceType_KV_BANK, []ResourceType{}},
ResourceType_KV_BANK_BALANCES: {ResourceType_KV_BANK, []ResourceType{}},
ResourceType_KV_BANK_DEFERRED: {ResourceType_KV, []ResourceType{ResourceType_KV_BANK_DEFERRED_MODULE_TX_INDEX}},
ResourceType_KV_BANK_DEFERRED_MODULE_TX_INDEX: {ResourceType_KV_BANK_DEFERRED, []ResourceType{}},
ResourceType_KV_STAKING: {ResourceType_KV, []ResourceType{
ResourceType_KV_STAKING_DELEGATION,
ResourceType_KV_STAKING_VALIDATOR,
Expand Down
40 changes: 19 additions & 21 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ type Context struct {

msgValidator *acltypes.MsgValidator
messageIndex int // Used to track current message being processed

contextMemCache *ContextMemCache
txIndex int

traceSpanContext context.Context
}
Expand Down Expand Up @@ -133,12 +132,12 @@ func (c Context) MessageIndex() int {
return c.messageIndex
}

func (c Context) MsgValidator() *acltypes.MsgValidator {
return c.msgValidator
func (c Context) TxIndex() int {
return c.txIndex
}

func (c Context) ContextMemCache() *ContextMemCache {
return c.contextMemCache
func (c Context) MsgValidator() *acltypes.MsgValidator {
return c.msgValidator
}

// clone the header before returning
Expand Down Expand Up @@ -173,16 +172,15 @@ func NewContext(ms MultiStore, header tmproto.Header, isCheckTx bool, logger log
// https://github.com/gogo/protobuf/issues/519
header.Time = header.Time.UTC()
return Context{
ctx: context.Background(),
ms: ms,
header: header,
chainID: header.ChainID,
checkTx: isCheckTx,
logger: logger,
gasMeter: stypes.NewInfiniteGasMeter(),
minGasPrice: DecCoins{},
eventManager: NewEventManager(),
contextMemCache: NewContextMemCache(),
ctx: context.Background(),
ms: ms,
header: header,
chainID: header.ChainID,
checkTx: isCheckTx,
logger: logger,
gasMeter: stypes.NewInfiniteGasMeter(),
minGasPrice: DecCoins{},
eventManager: NewEventManager(),

txBlockingChannels: make(acltypes.MessageAccessOpsChannelMapping),
txCompletionChannels: make(acltypes.MessageAccessOpsChannelMapping),
Expand Down Expand Up @@ -335,14 +333,14 @@ func (c Context) WithMessageIndex(messageIndex int) Context {
return c
}

func (c Context) WithMsgValidator(msgValidator *acltypes.MsgValidator) Context {
c.msgValidator = msgValidator
// WithTxIndex returns a Context with the current transaction index that's being processed
func (c Context) WithTxIndex(txIndex int) Context {
c.txIndex = txIndex
return c
}

// WithContextMemCache returns a Context with a new context mem cache
func (c Context) WithContextMemCache(contextMemCache *ContextMemCache) Context {
c.contextMemCache = contextMemCache
func (c Context) WithMsgValidator(msgValidator *acltypes.MsgValidator) Context {
c.msgValidator = msgValidator
return c
}

Expand Down
87 changes: 0 additions & 87 deletions types/context_cache.go

This file was deleted.

Loading