Skip to content

Commit

Permalink
Clear dex memstate cache (#788)
Browse files Browse the repository at this point in the history
* Clear cache

* Update app.go

* sd
  • Loading branch information
BrandonWeng authored May 20, 2023
1 parent 08fc854 commit 98c60f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
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)
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{})
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

0 comments on commit 98c60f0

Please sign in to comment.