-
Notifications
You must be signed in to change notification settings - Fork 608
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
feat(x/protorev): Use Transient store to store swap backruns #7665
Changes from 2 commits
c29573f
fdf53a9
1e4e42b
4690908
4aec2f8
90c3156
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ func (protoRevDec ProtoRevDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simu | |
// 1. If there is an error, then the cache context is discarded | ||
// 2. If there is no error, then the cache context is written to the main context with no gas consumed | ||
cacheCtx, write := ctx.CacheContext() | ||
|
||
// CacheCtx's by default _share_ their gas meter with the parent. | ||
// In our case, the cache ctx is given a new gas meter instance entirely, | ||
// so gas usage is not counted towards tx gas usage. | ||
|
@@ -47,12 +48,12 @@ func (protoRevDec ProtoRevDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simu | |
cacheCtx = cacheCtx.WithGasMeter(upperGasLimitMeter) | ||
|
||
// Check if the protorev posthandler can be executed | ||
if err := protoRevDec.ProtoRevKeeper.AnteHandleCheck(cacheCtx); err != nil { | ||
if err := protoRevDec.ProtoRevKeeper.AnteHandleCheck(ctx); err != nil { | ||
return next(ctx, tx, success, simulate) | ||
} | ||
|
||
// Extract all of the pools that were swapped in the tx | ||
swappedPools := protoRevDec.ProtoRevKeeper.ExtractSwappedPools(cacheCtx) | ||
swappedPools := protoRevDec.ProtoRevKeeper.ExtractSwappedPools(ctx) | ||
mattverse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(swappedPools) == 0 { | ||
return next(ctx, tx, success, simulate) | ||
} | ||
|
@@ -64,10 +65,10 @@ func (protoRevDec ProtoRevDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simu | |
ctx.Logger().Error("ProtoRevTrade failed with error: " + err.Error()) | ||
} | ||
|
||
// Delete swaps to backrun for next transaction without consuming gas | ||
// from the current transaction's gas meter, but instead from a new gas meter with 50mil gas. | ||
// 50 mil gas was chosen as an arbitrary large number to ensure deletion does not run out of gas. | ||
protoRevDec.ProtoRevKeeper.DeleteSwapsToBackrun(ctx.WithGasMeter(sdk.NewGasMeter(sdk.Gas(50_000_000)))) | ||
// // Delete swaps to backrun for next transaction without consuming gas | ||
// // from the current transaction's gas meter, but instead from a new gas meter with 50mil gas. | ||
// // 50 mil gas was chosen as an arbitrary large number to ensure deletion does not run out of gas. | ||
// protoRevDec.ProtoRevKeeper.DeleteSwapsToBackrun(ctx.WithGasMeter(sdk.NewGasMeter(sdk.Gas(50_000_000)))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we still need this? Just on the transient store? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we? I thought the purpose of Transient stores was that it drops all states anyways so thought we wouldn't need to delete them 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does drop all state, but at the end of the block not the end of each tx There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (notably these need to get deleted end of each tx, in order to not cause excess backruns next block) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh gotcha, confused myself with this logic being in endblocker. Fixed in 4690908 this commit! |
||
|
||
return next(ctx, tx, success, simulate) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive by change, true has been deprecated and has been replaced to explicit