Skip to content

feat: add vercel blobs to cache historical subgraph data #240

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

mrice32
Copy link
Member

@mrice32 mrice32 commented Aug 8, 2025

No description provided.

Signed-off-by: Matt Rice <[email protected]>
Copy link

vercel bot commented Aug 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
amoy-optimistic-oracle-dapp-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 10:00am
optimistic-oracle-dapp-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 10:00am
sepolia-optimistic-oracle-dapp-v2 🛑 Canceled (Inspect) Aug 8, 2025 10:00am

Signed-off-by: Matt Rice <[email protected]>
@vercel vercel bot temporarily deployed to Preview – amoy-optimistic-oracle-dapp-v2 August 8, 2025 02:45 Inactive
@vercel vercel bot temporarily deployed to Preview – sepolia-optimistic-oracle-dapp-v2 August 8, 2025 02:45 Inactive
Signed-off-by: Matt Rice <[email protected]>
@vercel vercel bot temporarily deployed to Preview – sepolia-optimistic-oracle-dapp-v2 August 8, 2025 02:59 Inactive
@vercel vercel bot temporarily deployed to Preview – amoy-optimistic-oracle-dapp-v2 August 8, 2025 02:59 Inactive
mrice32 added 3 commits August 8, 2025 00:29
Signed-off-by: Matt Rice <[email protected]>
Signed-off-by: Matt Rice <[email protected]>
Signed-off-by: Matt Rice <[email protected]>
mrice32 added 2 commits August 8, 2025 05:36
Signed-off-by: Matt Rice <[email protected]>
Signed-off-by: Matt Rice <[email protected]>
Copy link
Collaborator

@gsteenkamp89 gsteenkamp89 left a comment

Choose a reason for hiding this comment

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

I've done some light testing and it looks pretty good so far.
I'll play around a bit more, see if we don't have big gaps in latest data

Comment on lines +32 to +38
const remainingRequests = await fetchAllRequests(
url,
queryName,
oracleType,
Number(requests[0].time),
);
requests = [...remainingRequests, ...requests];
Copy link
Collaborator

Choose a reason for hiding this comment

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

So does this mean we're sorting from oldest to newest? Then we'd have some newest (< 12hrs old ) requests not stored in the blob, those will be fetched from the subgraph?

Copy link
Member Author

@mrice32 mrice32 Aug 8, 2025

Choose a reason for hiding this comment

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

Yep! Technically, everything is in descending order of timestamp and both are generated with the same code. The local one just has a single parameter difference that it filters for elements after the last timestamp in the blob.


if (blobValue === null || isBlobExpired(blobValue)) {
// This forces the vercel function to update the blob in the background.
waitUntil(updateBlob(blobName, url, queryName, oracleType as OracleType));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't know waitUntil was available, that's great 👍


const blobValue = await kv.get<BlobValue>(blobName);

if (blobValue === null || isBlobExpired(blobValue)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean that ALL requests are potentially stale by up to 12 hours? For example if request A has been proposed, in this cached data will still be marked as "Requested" for 12 hours until the cache is updated.

Copy link
Member Author

@mrice32 mrice32 Aug 8, 2025

Choose a reason for hiding this comment

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

No, so the blob will be out of date, but we augment the blob data with local data from the subgraph.

One thing I'm assuming is that the graph data doesn't change once its timestamp has passed (i.e. each element that we get from the graph effectively represents an event). So this is a good point. If that's not true, then this may allow for stale state if the timestamp isn't updated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

These entities from the subgraph don't represent events per se, they are single PriceRequest object that get updated as they change in state (Requested, Proposed, Settled).
The time field is set once at request time when they are initially created.
There's also proposalTimestamp, added at proposal time. We can add another at settle time if we need to.
Would this help at all? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmmm, yeah, so this may be a problem.

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.

2 participants