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

[feat] [ROUTE-9] v3 dynamo cache pool provider #201

Merged

Conversation

jsy1218
Copy link
Member

@jsy1218 jsy1218 commented May 25, 2023

What?

In routing-api, we create a CachingV3PoolProvider which is defined in SOR.

We can create a new DynamoDBCachingV3PoolProvider in the routing-api source code that implements IV3PoolProvider, and uses a DynamoDB Table for storing the Pools into cache.

It is important to use the block number as a sort key for the cache to make sure that we are storing the information of the pools at a given block height, and for consistency of quotes.

Why?

We see misquotes across v2 and v3. We think the existing in-memory cache is one source of the issue.

How?

We will begin replacing v3 in-memory cache with distributed cache.

Testing?

All unit tests and integ tests passed.

Screenshots (optional)

N/A

Anything Else?

BlockNumber are passed into V2Quoter and MixedQuoter, but not V3Quoter . I think we would want to remain as is for now, and test the MixedQuoter after dynamo caching V3.

@jsy1218 jsy1218 requested a review from mikeki May 25, 2023 03:25
import { FeeAmount, Pool } from '@uniswap/v3-sdk'
import { DynamoDB } from 'aws-sdk'

export class DynamoPoolProvider implements IV3PoolProvider {
Copy link
Member Author

Choose a reason for hiding this comment

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

@mikeki I find it a bit awkward that I'm copying and pasting a lot of code from caching-pool-provider.ts, but I think it's better to minimize the refactoring in smart-order-router right? Also in this case, we will be able to delete caching-pool-provider.ts upon migration to dynamo cache.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you no longer are doing alot of copy pasting?

Copy link
Member Author

Choose a reason for hiding this comment

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

With the introduction of cache-dynamo.ts, I see an opportunity to avoid a lot of copy paste from caching-pool-provider.ts, as well as subsequent refactoring with dynamo-route-caching-provider.ts.

On high-level I think the dynamo caching can be abstracted into a common interface, which is my first attempt in this PR. However, I don't want to over expand the scope and keep the refactoring in future chance.

@jsy1218 jsy1218 changed the title [draft PR: not ready for review] dynamo cache pool provider [draft PR: not ready for review] v3 dynamo cache pool provider May 25, 2023
import { FeeAmount, Pool } from '@uniswap/v3-sdk'
import { DynamoDB } from 'aws-sdk'

export class DynamoPoolProvider implements IV3PoolProvider {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you no longer are doing alot of copy pasting?

@jsy1218 jsy1218 changed the title [draft PR: not ready for review] v3 dynamo cache pool provider [feat] v3 dynamo cache pool provider May 31, 2023
@jsy1218 jsy1218 self-assigned this May 31, 2023
@jsy1218 jsy1218 changed the title [feat] v3 dynamo cache pool provider [feat] [ROUTE-9] v3 dynamo cache pool provider May 31, 2023
@jsy1218 jsy1218 marked this pull request as ready for review May 31, 2023 18:30
@jsy1218 jsy1218 requested review from mikeki and lynnshaoyu May 31, 2023 18:32
lib/handlers/router-entities/cache-dynamo.ts Outdated Show resolved Hide resolved
TableName: this.tableName,
Key: {
poolAddress: partitionKey,
blockNumber: sortKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add some way of fetching more than just the last block? I think eventually (specially with V3 Pool Provider) we should be able to look at some past blocks to speed things up, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

aw what's the use case for fetching some past blocks? Is it when we don't know what's the latest the block number?

Copy link
Contributor

Choose a reason for hiding this comment

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

In case we want to optimistically use the previous block data, but I think we can go with what we have right now, and then see how it performs before making other changes :)

@jsy1218 jsy1218 requested a review from mikeki May 31, 2023 23:39
Copy link
Contributor

@mikeki mikeki left a comment

Choose a reason for hiding this comment

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

It looks good overall, let's just address the last comment I added, but this looks great!

@jsy1218 jsy1218 merged commit 113824c into main Jun 1, 2023
3 checks passed
@jsy1218 jsy1218 deleted the jsy1218/replace-in-memory-cache-with-dynamo-cache-for-pool branch June 1, 2023 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants