-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(bal): scaffold BAL store abstraction #23596
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5578ca4
feat(bal): scaffold BAL store abstraction
0xKarl98 45320b4
refactor(bal): rename BAL store handle
0xKarl98 92f1759
Merge origin/main into feat/bal-store-scaffold
0xKarl98 97b89b6
fmt
0xKarl98 cd86bc8
fix(rpc): make BAL store accessor non-const
0xKarl98 135838d
fix(node-builder): import BAL handle from provider
0xKarl98 3c5ac47
fix(bal): address builder and test compile errors
0xKarl98 5d7df44
refactor(bal): move BAL store ownership to provider
0xKarl98 d781535
undo
0xKarl98 5fdd891
fix(bal): support provider-owned BAL tests
0xKarl98 660102c
fix
0xKarl98 7d7d1da
fix(bal): align providers and builder cleanup
0xKarl98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| use alloc::{sync::Arc, vec::Vec}; | ||
| use alloy_primitives::{BlockHash, BlockNumber, Bytes}; | ||
| use reth_storage_errors::provider::ProviderResult; | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I addition, can we introduce a config type: |
||
| /// Store for Block Access Lists (BALs). | ||
| /// | ||
| /// This abstraction intentionally does not prescribe where BALs live. Implementations may keep | ||
| /// recent BALs in memory, read canonical BALs from static files, or compose multiple tiers behind | ||
| /// a single interface. | ||
| #[auto_impl::auto_impl(&, Arc, Box)] | ||
| pub trait BalStore: Send + Sync + 'static { | ||
| /// Insert the BAL for the given block. | ||
| fn insert( | ||
| &self, | ||
| block_hash: BlockHash, | ||
| block_number: BlockNumber, | ||
| bal: Bytes, | ||
| ) -> ProviderResult<()>; | ||
|
|
||
| /// Fetch BALs for the given block hashes. | ||
| /// | ||
| /// The returned vector must align with `block_hashes`. | ||
| fn get_by_hashes(&self, block_hashes: &[BlockHash]) -> ProviderResult<Vec<Option<Bytes>>>; | ||
|
|
||
| /// Fetch BALs for the requested range. | ||
| /// | ||
| /// Implementations may stop at the first gap and return the contiguous prefix. | ||
| fn get_by_range(&self, start: BlockNumber, count: u64) -> ProviderResult<Vec<Bytes>>; | ||
| } | ||
|
|
||
| /// Clone-friendly façade around a BAL store implementation. | ||
| #[derive(Clone)] | ||
| pub struct BalStoreHandle { | ||
| inner: Arc<dyn BalStore>, | ||
| } | ||
|
|
||
| impl BalStoreHandle { | ||
| /// Creates a new [`BalStoreHandle`] from the given implementation. | ||
| pub fn new(inner: impl BalStore) -> Self { | ||
| Self { inner: Arc::new(inner) } | ||
| } | ||
|
|
||
| /// Creates a [`BalStoreHandle`] backed by [`NoopBalStore`]. | ||
| pub fn noop() -> Self { | ||
| Self::new(NoopBalStore) | ||
| } | ||
|
|
||
| /// Insert the BAL for the given block. | ||
| #[inline] | ||
| pub fn insert( | ||
| &self, | ||
| block_hash: BlockHash, | ||
| block_number: BlockNumber, | ||
| bal: Bytes, | ||
| ) -> ProviderResult<()> { | ||
| self.inner.insert(block_hash, block_number, bal) | ||
| } | ||
|
|
||
| /// Fetch BALs for the given block hashes. | ||
| #[inline] | ||
| pub fn get_by_hashes(&self, block_hashes: &[BlockHash]) -> ProviderResult<Vec<Option<Bytes>>> { | ||
| self.inner.get_by_hashes(block_hashes) | ||
| } | ||
|
|
||
| /// Fetch BALs for the requested range. | ||
| #[inline] | ||
| pub fn get_by_range(&self, start: BlockNumber, count: u64) -> ProviderResult<Vec<Bytes>> { | ||
| self.inner.get_by_range(start, count) | ||
| } | ||
| } | ||
|
|
||
| impl Default for BalStoreHandle { | ||
| fn default() -> Self { | ||
| Self::noop() | ||
| } | ||
| } | ||
|
|
||
| impl core::fmt::Debug for BalStoreHandle { | ||
| fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| f.debug_struct("BalStoreHandle").finish_non_exhaustive() | ||
| } | ||
| } | ||
|
|
||
| /// Provider-side access to BAL storage. | ||
| #[auto_impl::auto_impl(&, Arc)] | ||
| pub trait BalProvider { | ||
| /// Returns the configured BAL store handle. | ||
| fn bal_store(&self) -> &BalStoreHandle; | ||
| } | ||
|
|
||
| /// No-op BAL store used as the default wiring target until a concrete implementation is injected. | ||
| #[derive(Debug, Default, Clone, Copy)] | ||
| pub struct NoopBalStore; | ||
|
|
||
| impl BalStore for NoopBalStore { | ||
| fn insert( | ||
| &self, | ||
| _block_hash: BlockHash, | ||
| _block_number: BlockNumber, | ||
| _bal: Bytes, | ||
| ) -> ProviderResult<()> { | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn get_by_hashes(&self, block_hashes: &[BlockHash]) -> ProviderResult<Vec<Option<Bytes>>> { | ||
| Ok(block_hashes.iter().map(|_| None).collect()) | ||
| } | ||
|
|
||
| fn get_by_range(&self, _start: BlockNumber, _count: u64) -> ProviderResult<Vec<Bytes>> { | ||
| Ok(Vec::new()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use alloy_primitives::B256; | ||
|
|
||
| #[test] | ||
| fn noop_store_returns_empty_results() { | ||
| let store = BalStoreHandle::default(); | ||
| let hashes = [B256::random(), B256::random()]; | ||
|
|
||
| let by_hash = store.get_by_hashes(&hashes).unwrap(); | ||
| let by_range = store.get_by_range(1, 10).unwrap(); | ||
|
|
||
| assert_eq!(by_hash, vec![None, None]); | ||
| assert!(by_range.is_empty()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, this is a good start