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

Query Wildcard events concurrently with static events #409

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

DZakh
Copy link
Member

@DZakh DZakh commented Jan 9, 2025

  • This is a final preparation step for Wildcard RPC indexing support
  • As an additional benefit, this will add concurrency to the HyperSync fetching as well, making it a little bit faster
  • Unrelated change: The Indexer started failing with a user-readable error that there's nothing to fetch when there are no static contracts in the config or wildcard events are registered.

Even though the change looks scary, these are mostly test updates. What's going on:

  • To have better control and be able to build a query for Wildcard events on RPC we've decided to use an already existing partitioning mechanism
  • It used to use it before as well, but was implemented as a workaround by mixing in wildcard events to the first partition.
  • Now, there's always a separate partition for wildcard events, allowing us to build a wildcard get_logs rpc query

Besides the partitions refactoring done in the previous release, the mane challenge of the PR is to make sure, that we always create partitions with the correct initial addresses (you can see it in the ChainFetcher logic). Now, a normal partition without addresses shouldn't be possible, so we throw an error on FetchState creation.

@DZakh DZakh requested a review from JasoonS January 9, 2025 11:14
Comment on lines +20 to +25
| Normal({
contractAddressMapping: ContractAddressingMap.mapping,
//Used to prune dynamic contract registrations in the event
//of a rollback.
dynamicContracts: array<TablesStatic.DynamicContractRegistry.t>,
})
Copy link
Member Author

Choose a reason for hiding this comment

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

In the future, to support topic filtering for rpc, we'll need to have a partition per event.

Comment on lines +95 to +111
switch (p, target) {
| ({kind: Wildcard}, _)
| (_, {kind: Wildcard}) => (p, Some(target))
| (
{
kind: Normal({
contractAddressMapping: mergingContractAddressMapping,
dynamicContracts: mergingDynamicContracts,
}),
},
{
kind: Normal({
contractAddressMapping: targetContractAddressMapping,
dynamicContracts: targetDynamicContracts,
}),
},
) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

The code is the same as before, it only skips merging for Wildcard partitions

Comment on lines +381 to +400
type queryTarget =
| Head
| EndBlock({toBlock: int})
| Merge({
// The partition we are going to merge into
// It shouldn't be fetching during the query
intoPartitionId: string,
toBlock: int,
})

// Strip internal fields from partition kind like dynamicContracts
type querySelection =
| Wildcard
| Normal({contractAddressMapping: ContractAddressingMap.mapping})

type mergeQuery = {
// The catching up partition
type query = {
partitionId: string,
// The partition we are going to merge into
// It shouldn't be fetching during the query
intoPartitionId: string,
fromBlock: int,
toBlock: int,
contractAddressMapping: ContractAddressingMap.mapping,
}

type query =
| PartitionQuery(partitionQuery)
| MergeQuery(mergeQuery)

let queryFromBlock = query => {
switch query {
| PartitionQuery({fromBlock}) => fromBlock
| MergeQuery({fromBlock}) => fromBlock
}
}

let queryPartitionId = query => {
switch query {
| PartitionQuery({partitionId}) => partitionId
| MergeQuery({partitionId}) => partitionId
}
selection: querySelection,
target: queryTarget,
Copy link
Member Author

Choose a reason for hiding this comment

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

Change to make it easier to work according to the suggestion #405 (comment)

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.

1 participant