Skip to content

Query Wildcard events concurrently with static events - #409

Merged
DZakh merged 7 commits into
mainfrom
dz/partition-kinds
Jan 10, 2025
Merged

Query Wildcard events concurrently with static events#409
DZakh merged 7 commits into
mainfrom
dz/partition-kinds

Conversation

@DZakh

@DZakh DZakh commented Jan 9, 2025

Copy link
Copy Markdown
Member
  • 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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)

@DZakh
DZakh force-pushed the dz/partition-kinds branch from 7d28d73 to 678e186 Compare January 10, 2025 12:22
@DZakh
DZakh enabled auto-merge (squash) January 10, 2025 12:22
@DZakh
DZakh merged commit dbcc8d5 into main Jan 10, 2025
@DZakh
DZakh deleted the dz/partition-kinds branch January 10, 2025 12:31
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