From 6bc6c90f638a7c05c466756329532e3c9bf74ded Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Wed, 13 Sep 2023 10:04:45 -0500 Subject: [PATCH] Add occ todos / comments (#317) ## Describe your changes and provide context This adds some comments with some useful code pointers for existing logic and discussing future OCC work ## Testing performed to validate your change NA --- baseapp/abci.go | 2 ++ baseapp/baseapp.go | 4 ++++ store/cachekv/store.go | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/baseapp/abci.go b/baseapp/abci.go index 80d0c1db6..7328f7195 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -239,6 +239,8 @@ func (app *BaseApp) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*abc // Otherwise, the ResponseDeliverTx will contain releveant error information. // Regardless of tx execution outcome, the ResponseDeliverTx will contain relevant // gas execution context. +// TODO: (occ) this is the function called from sei-chain to perform execution of a transaction. +// We'd likely replace this with an execution task that is scheduled by the OCC scheduler func (app *BaseApp) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) { defer telemetry.MeasureSince(time.Now(), "abci", "deliver_tx") defer func() { diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 174924baf..57b60a289 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -821,6 +821,7 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context // cacheTxContext returns a new context based off of the provided context with // a branched multi-store. +// TODO: (occ) This is an example of where we wrap the multistore with a cache multistore, and then return a modified context using that multistore func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context, sdk.CacheMultiStore) { ms := ctx.MultiStore() // TODO: https://github.com/cosmos/cosmos-sdk/issues/2824 @@ -974,6 +975,7 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf storeAccessOpEvents := msCache.GetEvents() accessOps := ctx.TxMsgAccessOps()[acltypes.ANTE_MSG_INDEX] + // TODO: (occ) This is an example of where we do our current validation. Note that this validation operates on the declared dependencies for a TX / antehandler + the utilized dependencies, whereas the validation missingAccessOps := ctx.MsgValidator().ValidateAccessOperations(accessOps, storeAccessOpEvents) if len(missingAccessOps) != 0 { for op := range missingAccessOps { @@ -1118,6 +1120,8 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s storeAccessOpEvents := msgMsCache.GetEvents() accessOps := ctx.TxMsgAccessOps()[i] missingAccessOps := ctx.MsgValidator().ValidateAccessOperations(accessOps, storeAccessOpEvents) + // TODO: (occ) This is where we are currently validating our per message dependencies, + // whereas validation will be done holistically based on the mvkv for OCC approach if len(missingAccessOps) != 0 { for op := range missingAccessOps { ctx.Logger().Info((fmt.Sprintf("eventMsgName=%s Missing Access Operation:%s ", eventMsgName, op.String()))) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 59cb434b4..f03ee517e 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -113,11 +113,13 @@ func (store *Store) Get(key []byte) (value []byte) { cacheValue, ok := store.cache.Get(conv.UnsafeBytesToStr(key)) if !ok { + // TODO: (occ) This is an example of when we fall through when we dont have a cache hit. Similarly, for mvkv, we'll try to serve reads from a local cache thats transient to the TX, and if its NOT present, then we read through AND mark the access (along with the value that was read) for validation value = store.parent.Get(key) store.setCacheValue(key, value, false, false) } else { value = cacheValue.Value() } + // TODO: (occ) This is an example of how we currently track accesses store.eventManager.EmitResourceAccessReadEvent("get", store.storeKey, key, value) return value @@ -239,6 +241,8 @@ func (store *Store) iterator(start, end []byte, ascending bool) types.Iterator { store.mtx.Lock() defer store.mtx.Unlock() + // TODO: (occ) Note that for iterators, we'll need to have special handling (discussed in RFC) to ensure proper validation + var parent, cache types.Iterator if ascending {