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

fix(ProtoRev): Parameterizing Pool Type Information #5948

Merged
merged 27 commits into from
Aug 7, 2023

Conversation

davidterpay
Copy link
Contributor

@davidterpay davidterpay commented Aug 1, 2023

What is the purpose of the change

In this PR, I refactor the way we track information about different pool types in ProtoRev. In particular, currently each pool type has an associated pool weight (estimated amount of time in ms it takes to make a swap on that pool). However, with the addition of Cosmwasm and CL pools, we will likely need to make more assumptions based on pool type. The most basic one is MaxTicksCrossed which denotes the number of ticks we are willing to cross in our binary search.

This update will allow us to have more control over how ProtoRev responds to different pool types.

Testing and Verifying

  • Refactored all of the previous unit tests to use the new pool info type
  • Added tests for basic validation on the different pool types

Documentation and Release Note

  • Changelog entry added to Unreleased section of CHANGELOG.md?

This is related to the over-arching issue tracking protorev V17 updates. #5858

@github-actions github-actions bot added C:CLI C:app-wiring Changes to the app folder labels Aug 1, 2023
@davidterpay davidterpay mentioned this pull request Aug 2, 2023
10 tasks
// CosmwasmPoolInfo contains meta data pertaining to a cosmwasm pool type.
message CosmwasmPoolInfo {
// The weight of a cosmwasm pool (by contract address)
map<string, uint64> weight_map = 1 [
Copy link
Contributor Author

@davidterpay davidterpay Aug 2, 2023

Choose a reason for hiding this comment

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

I'm not sure if using a map is problematic for app hashing. We do no iterations on the map itself in the module. The primary use case is determining the number of pool weight of a given cosmwasm pool (which may vary across applications which is why its mapped to contract addresses).

Copy link
Member

Choose a reason for hiding this comment

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

@ValarDragon can you verify the safety of this?

Copy link
Member

Choose a reason for hiding this comment

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

We had instances where we tried to use maps quite a while ago, I think the decision back then was to try avoid using maps for extra safety, would it be possible to change it so tht we use repeated structs instead here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it. ty for confirming

@davidterpay davidterpay added protorev All things related to x/protorev V:state/breaking State machine breaking PR labels Aug 2, 2023
},
"cosmwasm" : {
"weight_map" : {
"ibc/123..." : 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"ibc/123..." : 1,
"osmo123..." : 1,

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: cosmwasm weight map represents address to weight, so use an address placeholder instead of an asset placeholder

Copy link
Contributor

@NotJeremyLiu NotJeremyLiu left a comment

Choose a reason for hiding this comment

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

lgtm, left comments on the benchmark decisions

@davidterpay
Copy link
Contributor Author

Screenshot 2023-08-04 at 2 14 15 PM

Execution time of a swap on a three pool route with a CW pool. Total execution time was ~8ms and balancer pools normally take around ~2ms to execute.

@davidterpay
Copy link
Contributor Author

davidterpay commented Aug 4, 2023

goos: darwin
goarch: arm64
pkg: github.com/osmosis-labs/osmosis/v17/x/protorev/keeper
BenchmarkFourHopHotRouteArb-10    	       175	               1402491 ns/op	       1132910 B/op	       20913 allocs/op

Base weight on CL pools should be around 7 (takes 7ms to execute a route with a CL pool).

@davidterpay davidterpay marked this pull request as ready for review August 4, 2023 20:57
@davidterpay davidterpay requested a review from p0mvn as a code owner August 4, 2023 20:57
Base automatically changed from terpay/search-range-update to main August 4, 2023 23:11
Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

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

Everything except for the map in the proto and the changed proto field looks good to me. Will need a second ack before merge. Thank you!

Comment on lines 28 to 32
// Information that is used to estimate execution time / gas
// consumption of a swap on a given pool type.
InfoByPoolType info_by_pool_type = 4 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"pool_weights\""
(gogoproto.moretags) = "yaml:\"info_by_pool_type\""
Copy link
Member

Choose a reason for hiding this comment

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

If we are renaming the proto field, we should depreciate this field and add a new one

Copy link
Member

Choose a reason for hiding this comment

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

(Or reserve!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to clarify, add a note that this is deprecated and adding a new field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added back the previous field with a note that it is being deprecated.

// CosmwasmPoolInfo contains meta data pertaining to a cosmwasm pool type.
message CosmwasmPoolInfo {
// The weight of a cosmwasm pool (by contract address)
map<string, uint64> weight_map = 1 [
Copy link
Member

Choose a reason for hiding this comment

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

@ValarDragon can you verify the safety of this?

Comment on lines +147 to +148
Use: "info-by-pool-type",
Short: "Query the pool info used to determine how computationally expensive a route is",
Copy link
Member

Choose a reason for hiding this comment

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

I assume there is an input right? I think this should be "info-by-pool-type [pool-type]"

Copy link
Contributor Author

@davidterpay davidterpay Aug 7, 2023

Choose a reason for hiding this comment

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

yea the input is the json file with all of the correct pool info. This isnt used to update by a single pool type (although once the dependencies on a given pool type grow it might be worth migrating to separate message handlers).

I'll update the PR with the json example I used in testing.

Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

LGTM, except for using repeated structs as an alternative for maps

@davidterpay
Copy link
Contributor Author

@czarcas7ic @mattverse PR is updated with the removal of the map struct! Please lmk if there are any other blocks on your end (since I know the code freeze should be happening soon).

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

LGTM!

@ValarDragon ValarDragon merged commit 6240cab into main Aug 7, 2023
@ValarDragon ValarDragon deleted the terpay/pool-point-update branch August 7, 2023 18:16
Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

Did not review details of calculation going on for CL pools, otherwise LGTM

p0mvn pushed a commit that referenced this pull request Aug 29, 2023
* init

* testing update

* changelog

* comments

* nit

* refactor

* clean up

* nit

* comment

* cr

* cl are not symetric

* init

* smh more symetric changes

* simpler safe swap

* map update

* more stuff

* testing fixes

* more testing

* nits

* benchmark + CLI clean up

* test fix

* no map no problems

* update with merge

* better docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:app-wiring Changes to the app folder C:CLI protorev All things related to x/protorev V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants