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

Generic provider #218

Merged
merged 3 commits into from
Oct 23, 2024
Merged

Generic provider #218

merged 3 commits into from
Oct 23, 2024

Conversation

liamaharon
Copy link
Contributor

Closes #216

Replaces all concrete usage of ProviderFactory and ProviderFactoryReopener with generics bounded by reth provider traits. This allows running rbuilder in-process using a node provider and eases swapping to a more modern provider like BlockchainProvider in the future.

Note that not all trait methods can be implemented because ProviderFactoryReopener has no access to the blockchain tree (pending state etc.).

DB Consistency Checks

Consistency checks have been moved out of the rbuilder core into the trait implementation for ProviderFactoryReopener. Inside the trait implementation, the current head block number is not known, so the reopener cannot assume that the state of the block given - 256 blocks will be available.

To not redundantly re-check the consistency of the same block, ProviderFactoryReopener tracks the last block verified to have consistent state and will only re-check it when it changes. This adds 1 additional read per provider call to get the head of the chain, however I believe the cost will be insignificant.

@liamaharon liamaharon force-pushed the generic-db-provider branch 2 times, most recently from 01c9560 to 68ef419 Compare October 17, 2024 05:54
Copy link

github-actions bot commented Oct 17, 2024

Benchmark results for ce433b2

Report: https://flashbots-rbuilder-ci-stats.s3.us-east-2.amazonaws.com/benchmark/ce433b2-d96e721/report/index.html

Date (UTC) 2024-10-23T18:42:52+00:00
Commit ce433b212cd3b3eb8441279480484c6c0c94dad9
Base SHA d96e7215483bac0ab145459f4ddaa811d99459d6

Significant changes

None

impl<P, DB> CombinatorContext<P, DB>
where
DB: Database + Clone + 'static,
P: DatabaseProviderFactory<DB> + StateProviderFactory + Clone + 'static,
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work with Rbuilder as a module? AFAIK It only receives the StateProviderFactory, not DatabaseProviderFactory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@dvush dvush left a comment

Choose a reason for hiding this comment

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

LGTM overall.

I've tested it for a bit and it looks good.

I want to be sure that best block number will work in our case so we can avoid subtle bugs.

crates/rbuilder/src/utils/provider_factory_reopen.rs Outdated Show resolved Hide resolved
crates/rbuilder/src/utils/provider_factory_reopen.rs Outdated Show resolved Hide resolved
if !self.testing_mode {
match check_provider_factory_health(current_block_number, &provider_factory) {

// Don't need to check consistency for the block that was just checked.
Copy link
Contributor

Choose a reason for hiding this comment

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

I am pretty sure that its true but it can be possible that its not.

The only place that I see that would suffer from too much checking here is nonce cache in sim tree. But even then this check can have a small impact.

I don't think that we should change it now but I marked it to remember to revisit if we see some problems with reopening.

Copy link
Contributor

@dvush dvush left a comment

Choose a reason for hiding this comment

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

LGTM

@liamaharon liamaharon merged commit 3159c3f into develop Oct 23, 2024
5 checks passed
@liamaharon liamaharon deleted the generic-db-provider branch October 23, 2024 18:59
@dvush dvush mentioned this pull request Oct 23, 2024
astarinmymind pushed a commit that referenced this pull request Nov 1, 2024
Closes #216

Replaces all concrete usage of `ProviderFactory` and
`ProviderFactoryReopener` with generics bounded by [reth provider
traits](https://github.com/paradigmxyz/reth/blob/661b260f6172c047e8530e2331b2c84141e03c2b/crates/storage/provider/src/traits/full.rs#L14-L24).
This allows running rbuilder in-process using a node provider and eases
swapping to a more modern provider like `BlockchainProvider` in the
future.

Note that not all trait methods can be implemented because
`ProviderFactoryReopener` has no access to the blockchain tree (pending
state etc.).

Consistency checks have been moved out of the rbuilder core into the
trait implementation for `ProviderFactoryReopener`. Inside the trait
implementation, the current head block number is not known, so the
reopener cannot assume that the state of the block given - 256 blocks
will be available.

To not redundantly re-check the consistency of the same block,
`ProviderFactoryReopener` tracks the last block verified to have
consistent state and will only re-check it when it changes. This adds 1
additional read per provider call to get the head of the chain, however
I believe the cost will be insignificant.
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.

Access DB with a generic Provider
3 participants