-
Notifications
You must be signed in to change notification settings - Fork 609
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
Protorev: Backrun event emission #4878
Conversation
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.
Update LGTM, but would move the creation and event emission into the same place.
We discussed on call that we are concerned that the keeper call here may change gas. Resolution on call I believe was to:
|
I'm going to spend a bit of time today refactoring to not include an extra kvstore read, but to see if we can still output the block pool points. Tbh, this is the main reason why we want this event as it will allow us to know how much room we still have to per block to backrun more or less. |
Need to add tests to verify, but this commit intends to allow us to emit blockPoolPointsRemaining without doing an extra kvstore read: 482cbf6 |
Test added, ready for review |
x/protorev/keeper/emit.go
Outdated
// EmitBackrunEvent updates and emits a backrunEvent | ||
func EmitBackrunEvent(ctx sdk.Context, pool SwapToBackrun, inputCoin sdk.Coin, profit, tokenOutAmount sdk.Int, remainingTxPoolPoints, remainingBlockPoolPoints uint64) error { | ||
// Get tx hash | ||
txHash := strings.ToUpper(hex.EncodeToString(tmhash.Sum(ctx.TxBytes()))) | ||
// Update the backrun event and add it to the context | ||
backrunEvent := sdk.NewEvent( | ||
types.TypeEvtBackrun, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
sdk.NewAttribute(types.AttributeKeyTxHash, txHash), | ||
sdk.NewAttribute(types.AttributeKeyUserPoolId, strconv.FormatUint(pool.PoolId, 10)), | ||
sdk.NewAttribute(types.AttributeKeyUserDenomIn, pool.TokenInDenom), | ||
sdk.NewAttribute(types.AttributeKeyUserDenomOut, pool.TokenOutDenom), | ||
sdk.NewAttribute(types.AttributeKeyTxPoolPointsRemaining, strconv.FormatUint(remainingTxPoolPoints, 10)), | ||
sdk.NewAttribute(types.AttributeKeyBlockPoolPointsRemaining, strconv.FormatUint(remainingBlockPoolPoints, 10)), | ||
sdk.NewAttribute(types.AttributeKeyProtorevProfit, profit.String()), | ||
sdk.NewAttribute(types.AttributeKeyProtorevAmountIn, inputCoin.Amount.String()), | ||
sdk.NewAttribute(types.AttributeKeyProtorevAmountOut, tokenOutAmount.String()), | ||
sdk.NewAttribute(types.AttributeKeyProtorevArbDenom, inputCoin.Denom), | ||
) | ||
ctx.EventManager().EmitEvent(backrunEvent) | ||
|
||
return nil | ||
} |
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.
There does not seem to be an error returned, can we remove error
return?
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.
Resolved in: f632b42
x/protorev/keeper/rebalance.go
Outdated
if err != nil { | ||
return err | ||
} |
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.
Note that adding error checks can be state-breaking. However, it does not seem that EmitBackrunEvent
actually ever returns an error so we can probably remove it
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.
Noted, resolved in f632b42 by removing the unused error return
x/protorev/keeper/rebalance.go
Outdated
if numberOfAvailablePoolPoints > maxPoolPointsPerTx { | ||
return maxPoolPointsPerTx, numberOfAvailablePoolPoints, nil | ||
} | ||
|
||
return numberOfIterableRoutes, nil | ||
return numberOfAvailablePoolPoints, numberOfAvailablePoolPoints, nil |
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.
Could you please update godoc indicating what the return values are and when max vs available are returned?
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.
Updated in: 03f8e98
@p0mvn All requested changes have been done, re-review ready |
…r event - Instead of reading from store to create the event (previously read to determine remaining block-level pool points remaining), use a previously read variable and passes it through the necessary functions to be able to emit it at the end
03f8e98
to
337269e
Compare
Rebased and added change log entry, should be ready to merge |
* Add protorev backrun_event emission * add empty backrun event to pass in as param to make rebalance tests pass * Add basic validity test for protorev_backrun event * Add pool id to event, add documentation * Add tx_hash to backrun event * change pool point var naming * Consolidate create and emit backrun event functions into one * Update logic to not require an additional kvstore read to get data for event - Instead of reading from store to create the event (previously read to determine remaining block-level pool points remaining), use a previously read variable and passes it through the necessary functions to be able to emit it at the end * Rename pool points fn to be more general * Add test to verify proper event emission * add tx_hash to event documentation * Remove unused error return * Update godoc and naming for more clarity * add changelog entry (cherry picked from commit 62968cc)
* Add protorev backrun_event emission * add empty backrun event to pass in as param to make rebalance tests pass * Add basic validity test for protorev_backrun event * Add pool id to event, add documentation * Add tx_hash to backrun event * change pool point var naming * Consolidate create and emit backrun event functions into one * Update logic to not require an additional kvstore read to get data for event - Instead of reading from store to create the event (previously read to determine remaining block-level pool points remaining), use a previously read variable and passes it through the necessary functions to be able to emit it at the end * Rename pool points fn to be more general * Add test to verify proper event emission * add tx_hash to event documentation * Remove unused error return * Update godoc and naming for more clarity * add changelog entry (cherry picked from commit 62968cc) Co-authored-by: Jeremy Liu <31809888+NotJeremyLiu@users.noreply.github.com>
What is the purpose of the change
Brief Changelog
Testing and Verifying
(Please pick one of the following options)
Documentation and Release Note