Skip to content

Conversation

@cctdaniel
Copy link
Contributor

@cctdaniel cctdaniel commented Jan 12, 2023

generally:

  • store the VAAs in an object with the price feed id as the key and the value is an array of objects that has a publishTime and vaa (VAAs are stored in an ascending order based on publishTime)
  • because VAAs are stored in an ascending order based on publishTime, we can run binary search on the array to find the publishTime greater than or equal to the target on O(logn) time
  • the endpoint first hits the cache and tries to find the VAA, if it doesn't exists it hits the DB
  • every minute, the cache will be cleaned up, and publishTime that has expired will be removed from the cache

other considerations:

  • balanced bst (not trivial + since the array is already sorted we can just use binary search)

@cctdaniel cctdaniel requested a review from ali-behjati January 12, 2023 12:18
if (
publishTime <
Math.floor(Date.now() / 1000) -
PYTH_WRITER_INSERT_LATENCY_SECONDS ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think injecting pyth writer logic be good here. The check seems unnecessary to me.

Copy link
Collaborator

@ali-behjati ali-behjati left a comment

Choose a reason for hiding this comment

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

🚢 it ser

@ali-behjati ali-behjati changed the title add /get_vaa endpoint that serves cache and db vaas [price-service] add /get_vaa endpoint that serves cache and db vaas Jan 13, 2023
@ali-behjati ali-behjati merged commit ad864c6 into main Jan 13, 2023
@ali-behjati ali-behjati deleted the price-service-vaa-cache branch January 13, 2023 15:08
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.

3 participants