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

Clear dex memstate cache #788

Merged
merged 3 commits into from
May 20, 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
8 changes: 8 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ func (app *App) ProcessTxs(
dependencyDag.BlockingSignalsMap,
dependencyDag.TxMsgAccessOpMapping,
)
oldDexMemState := dexutils.GetMemState(ctx.Context()).DeepCopy()
if ok {
// Write the results back to the concurrent contexts - if concurrent execution fails,
// this should not be called and the state is rolled back and retried with synchronous execution
Expand All @@ -1207,6 +1208,13 @@ func (app *App) ProcessTxs(
// Clear the memcache context from the previous state as it failed, we no longer need to commit the data
ctx.ContextMemCache().Clear()

oldDexMemStateCtx := context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, oldDexMemState)
Copy link
Collaborator

Choose a reason for hiding this comment

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

memstate has deep pointers so we need to explicitly clear it like

dexMemState := dexutils.GetMemState(ctx.Context())
dexMemState.Clear(ctx)
dexMemState.ClearContractToDependencies()

ctx = ctx.WithContext(oldDexMemStateCtx)

dexMemState := dexutils.GetMemState(ctx.Context())
dexMemState.Clear(ctx)
dexMemState.ClearContractToDependencies()

txResults := app.ProcessBlockSynchronous(ctx, txs)
processBlockCache.Write()
return txResults, ctx
Expand Down
2 changes: 1 addition & 1 deletion x/dex/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type MemState struct {
}

func NewMemState(storeKey sdk.StoreKey) *MemState {
contractsToProcess := datastructures.NewSyncSet[string]([]string{})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed

contractsToProcess := datastructures.NewSyncSet([]string{})
return &MemState{
storeKey: storeKey,
contractsToProcess: &contractsToProcess,
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func WeightedOperations(
}

// SimulateMsgAggregateExchangeRateVote generates a MsgAggregateExchangeRateVote with random values.
// nolint: funlen
//nolint: funlen
func SimulateMsgAggregateExchangeRateVote(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand Down Expand Up @@ -122,7 +122,7 @@ func SimulateMsgAggregateExchangeRateVote(ak types.AccountKeeper, bk types.BankK
}

// SimulateMsgDelegateFeedConsent generates a MsgDelegateFeedConsent with random values.
// nolint: funlen
//nolint: funlen
func SimulateMsgDelegateFeedConsent(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand Down