Skip to content

Conversation

@md0x
Copy link
Contributor

@md0x md0x commented Dec 4, 2025

Changes proposed in this PR:

  • Use subgraph to fetch PM OrderFilled events in PM notifier to improve x100 pm notifier performance.


const orderBookSubgraphEndpoint =
env.ORDER_BOOK_SUBGRAPH_ENDPOINT ||
"https://api.goldsky.com/api/public/project_cl6mb8i9h0003e201j6li0diw/subgraphs/orderbook-subgraph/0.0.1/gn";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@md0x md0x changed the title Pablo/pm events orders feat(pm-notifier): read order filled events from subgraph Dec 4, 2025
@md0x md0x marked this pull request as ready for review December 4, 2025 18:00
// Try the fast subgraph version
return await getOrderFilledEventsFromSubgraph(params, clobTokenIds, startTimestamp);
} catch (error) {
// Fallback to the slow version if subgraph fails
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 debug log this for better observability

const blockDifference = currentBlockNumber - subgraphBlockNumber;

// If subgraph is behind by more than tolerance, use slow method
if (blockDifference >= params.subgraphSyncTolerance) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the subgraphSyncTolerance naming implies that == should still be tolerated, so we might want to use > comparison here. Also running this couple of times I always observed subgraph lagging 1 block behind in my tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed

// Check subgraph sync status first
const subgraphBlockNumber = await checkSubgraphSyncStatus(params.httpClient, params.orderBookSubgraphEndpoint);

if (subgraphBlockNumber !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

when subgraphBlockNumber === null I don't think we should even try getOrderFilledEventsFromSubgraph below and instead fallback to getOrderFilledEventsSlow as subgraphSyncTolerance cannot be evaluated in this case.


// If subgraph is behind by more than tolerance, use slow method
if (blockDifference >= params.subgraphSyncTolerance) {
return await getOrderFilledEventsSlow(params, clobTokenIds, startBlockNumber);
Copy link
Contributor

Choose a reason for hiding this comment

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

also might want to debug log the fallback

@md0x md0x requested a review from Reinis-FRP December 5, 2025 14:33
Reinis-FRP
Reinis-FRP previously approved these changes Dec 5, 2025
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