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

CCIP-1288 LogPoller - Ability to pass custom search queries #11242

Closed
wants to merge 6 commits into from

Conversation

mateusz-sekara
Copy link
Collaborator

@mateusz-sekara mateusz-sekara commented Nov 9, 2023

Adding the ability to create custom read queries in LogPoller. It's the 2nd part of improvements to LogPoller, which CCIP requires. TestSelectAny contains an example query we will use in CCIP to speed up execution and reduce the number of records fetched from the database.

Copy link
Contributor

github-actions bot commented Nov 9, 2023

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

@mateusz-sekara mateusz-sekara force-pushed the logpoller/any-query branch 2 times, most recently from 8fe631b to 3a782be Compare November 9, 2023 11:21
@mateusz-sekara mateusz-sekara force-pushed the logpoller/any-query branch 2 times, most recently from 6e540a6 to 0d7096f Compare November 13, 2023 07:05
@mateusz-sekara mateusz-sekara marked this pull request as ready for review November 13, 2023 07:05
AND executed.block_number <= %s
) < ('x' || encode(substring(reports.data from 32*:max_seq_word_index+25 for 8), 'hex'))::::bit(64)::::bigint - ('x' || encode(substring(reports.data from 32*:min_seq_word_index+25 for 8), 'hex'))::::bit(64)::::bigint + 1
ORDER BY (reports.block_number, reports.log_index)`,
logpoller.NestedBlockNumberQuery(confs),
Copy link
Collaborator Author

@mateusz-sekara mateusz-sekara Nov 13, 2023

Choose a reason for hiding this comment

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

As a next step, I want to cache lastBlock in the memory. This would simplify queries to sth like this

	args := logpoller.NewQueryArgs().
		WithNamedHash("commit_store_addr", commitStore).
		WithNamedHash("commit_store_event", commitStoreEvent).
		WithNamedHash("offramp_addr", offramp).
		WithNamedHash("offramp_event", offrampEvent).
		WithNamedArg("after", time.Now().Add(-time.Hour)).
		WithConfs("confirmed_at_block", confs)

	query := `
		SELECT reports.* FROM evm.logs reports
		    WHERE reports.evm_chain_id = :evm_chain_id 
			AND reports.address = :commit_store_addr
			AND reports.event_sig = :commit_store_event
			AND reports.block_timestamp > :after
			AND reports.block_number > :confirmed_at_block
	`

	logs, err := th.ORM.SelectAnyLogs("ccipUnexpiredRoots", query, *args)

WithConf will pick the proper value from cache:

if confs == Finalized {
    return cache.latest_finalized_block
} else {
   return cache.last_block - confs
}

@mateusz-sekara mateusz-sekara changed the title LogPoller - ability to pass custom search queries CCIP-1288 LogPoller - ability to pass custom search queries Nov 13, 2023
@mateusz-sekara mateusz-sekara force-pushed the logpoller/moving-tx-to-orm branch from a66a61d to 75b12e7 Compare November 13, 2023 07:27
@cl-sonarqube-production
Copy link

@mateusz-sekara mateusz-sekara changed the title CCIP-1288 LogPoller - ability to pass custom search queries CCIP-1288 LogPoller - Ability to pass custom search queries Nov 13, 2023
Base automatically changed from logpoller/moving-tx-to-orm to develop November 13, 2023 16:59
@mateusz-sekara mateusz-sekara deleted the logpoller/any-query branch November 14, 2023 11:51
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