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: fetch events by src addresses #44

Merged
merged 4 commits into from
Dec 20, 2024

Conversation

0xnigir1
Copy link
Collaborator

@0xnigir1 0xnigir1 commented Dec 17, 2024

🤖 Linear

Closes GIT-205

Description

We want to be able to fetch all events for a now-handleable strategy, so we add a method to fetch all events between Genesis and lastProcessedEvent for a group of src addresses (all that corresponds to a strategyId)

Checklist before requesting a review

  • I have conducted a self-review of my code.
  • I have conducted a QA.
  • If it is a core feature, I have included comprehensive tests.

@0xnigir1 0xnigir1 self-assigned this Dec 17, 2024
Copy link

linear bot commented Dec 17, 2024

Comment on lines 24 to 36
async fetchEventsBySrcAddress(params: {
chainId: ChainId;
srcAddresses: Address[];
from?: {
blockNumber?: number;
logIndex?: number;
};
to: {
blockNumber: number;
logIndex: number;
};
limit?: number;
}): Promise<AnyIndexerFetchedEvent[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As a sidenote, you got the fetchEventsByBlockNumberAndLogIndex method that receives multiple parameters and you got this method that receives a params object.

Is there any particular reason for that?

And another question 👉 have you ever considered leveraging some kind of query builder pattern for the event fetcher? You could end up with a cool class:

const query = EventsFetcher.buildQuery()
  .withChainId(chainId)
  .withSrcAddressess(addresses)
  .withBlockNumber(blockNumber)
  ...

If you envision having more fetchEventsBy... methods, I'd consider this hehe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

regarding first, now that you mention that you're right, originally i wrote the method only with to param but when adding the from actually both methods can be combined into one

regarding second, i like query builders 😄 but i don't think we will benefit too much for now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i keep the old method until i integrate it with the rest of the code cuz if not i'll break everything

try {
const { chainId, srcAddresses, from, to, limit = 100 } = params;
const { blockNumber: toBlock, logIndex: toLogIndex } = to;
const { blockNumber: fromBlock, logIndex: fromLogIndex } = from ?? {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if from is {}?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch

Copy link
Collaborator

@0xkenj1 0xkenj1 left a comment

Choose a reason for hiding this comment

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

just smoll comments in docs and method signature

Comment on lines 27 to 33
from?: {
blockNumber?: number;
logIndex?: number;
};
to: {
blockNumber: number;
logIndex: number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

should it be like this ?

Suggested change
from?: {
blockNumber?: number;
logIndex?: number;
};
to: {
blockNumber: number;
logIndex: number;
from: {
blockNumber: number;
logIndex: number;
};
to?: {
blockNumber: number;
logIndex: number;

Comment on lines +21 to +28
/**
* Fetch the events by src address, block number and log index for a chain
* @param chainId id of the chain
* @param srcAddresses src addresses to fetch events from
* @param toBlock block number to fetch events from
* @param logIndex log index in the block to fetch events from
* @param limit limit of events to fetch
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this ok ?

@0xnigir1 0xnigir1 requested review from 0xkenj1 and 0xyaco December 18, 2024 22:15
Comment on lines +96 to +103
{ block_number: { _gt: $fromBlock } },
{
_and: [
{ block_number: { _eq: $fromBlock } },
{ log_index: { _gt: $fromLogIndex } }
]
}
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might not be relevant as you might be using this provider in a super specific way but how would you get all events from a single block?

I can only think of something like this:

from: { blockNumber: x, logIndex: 0 }
to: { blockNumber: x + 1, logIndex: 0 }

But it misses the log 0 from block x and includes log 0 from block x + 1.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

didn't think of this case since we fetch events individually (blockNumber and logIndex), not by blocks but i get your point. i will add it to tech debt

@0xnigir1 0xnigir1 requested a review from 0xyaco December 19, 2024 13:17
0xyaco
0xyaco previously approved these changes Dec 19, 2024
0xkenj1
0xkenj1 previously approved these changes Dec 20, 2024
@0xnigir1 0xnigir1 dismissed stale reviews from 0xkenj1 and 0xyaco via ab99914 December 20, 2024 14:44
@0xnigir1 0xnigir1 requested review from 0xyaco and 0xkenj1 December 20, 2024 14:45
@0xnigir1 0xnigir1 merged commit 26b90ac into dev Dec 20, 2024
6 checks passed
@0xnigir1 0xnigir1 deleted the feat/fetch-old-events-for-unhandled-strategies branch December 20, 2024 15:01
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