-
Notifications
You must be signed in to change notification settings - Fork 4
Move BRS to its own module #275
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 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0c2e786
feat: remove command + brs client
LeoPatOZ f27636f
feat: remove servce shutdown error
LeoPatOZ 56ae738
feat: remove block range scanner client
LeoPatOZ 29f68ae
docs: remove client
LeoPatOZ 915f6fb
feat: move block range scanner to brs folder and seperate crates
LeoPatOZ 1b37475
fix: docs
LeoPatOZ 4cfb3b2
feat: better rexports
LeoPatOZ 10e5f4c
feat: add back errors
LeoPatOZ c62ec4b
feat: add back error comments
LeoPatOZ 0376a4b
Merge branch 'refactor-brs' into merge-brs-crate
LeoPatOZ 16a37b3
ref: fix doc
LeoPatOZ a5c6f71
fmt: fix
LeoPatOZ 7126576
Merge branch 'main' into merge-brs-crate
LeoPatOZ bc91cff
ref: rename BRS to BRS Builder, and Connected BRS to BRS
LeoPatOZ 618ac72
fix: doc
LeoPatOZ ad364c6
fix: readme connect methods
LeoPatOZ 2f61cd3
ref: remove pub(crate) common
LeoPatOZ e2bbda2
ref: rename client to brs in test
LeoPatOZ 377a2c8
Remove empty line in src/block_range_scanner/builder.rs
0xNeshi f79b5c9
make RangeInterator internal to the brs module
0xNeshi 1e1be32
fix readme examples
0xNeshi 18fe117
revert changes to README
0xNeshi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| use alloy::network::Network; | ||
|
|
||
| use crate::{ | ||
| ScannerError, | ||
| block_range_scanner::{ | ||
| ConnectedBlockRangeScanner, DEFAULT_MAX_BLOCK_RANGE, DEFAULT_STREAM_BUFFER_CAPACITY, | ||
| RingBufferCapacity, | ||
| }, | ||
| robust_provider::IntoRobustProvider, | ||
| }; | ||
|
|
||
| /// Builder/configuration for the block-range streaming service. | ||
| #[derive(Clone, Debug)] | ||
| pub struct BlockRangeScanner { | ||
| /// Maximum number of blocks per streamed range. | ||
| pub max_block_range: u64, | ||
| /// How many past block hashes to keep in memory for reorg detection. | ||
| /// | ||
| /// If set to `RingBufferCapacity::Limited(0)`, reorg detection is disabled. | ||
| pub past_blocks_storage_capacity: RingBufferCapacity, | ||
| pub buffer_capacity: usize, | ||
| } | ||
|
|
||
| impl Default for BlockRangeScanner { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| impl BlockRangeScanner { | ||
| /// Creates a scanner with default configuration. | ||
| #[must_use] | ||
| pub fn new() -> Self { | ||
| Self { | ||
| max_block_range: DEFAULT_MAX_BLOCK_RANGE, | ||
|
|
||
0xNeshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| past_blocks_storage_capacity: RingBufferCapacity::Limited(10), | ||
| buffer_capacity: DEFAULT_STREAM_BUFFER_CAPACITY, | ||
| } | ||
| } | ||
|
|
||
| /// Sets the maximum number of blocks per streamed range. | ||
| /// | ||
| /// This controls batching for historical scans and for catch-up in live/sync scanners. | ||
| /// | ||
| /// Must be greater than 0. | ||
| #[must_use] | ||
| pub fn max_block_range(mut self, max_block_range: u64) -> Self { | ||
| self.max_block_range = max_block_range; | ||
| self | ||
| } | ||
|
|
||
| /// Sets how many past block hashes to keep in memory for reorg detection. | ||
| /// | ||
| /// If set to `RingBufferCapacity::Limited(0)`, reorg detection is disabled. | ||
| #[must_use] | ||
| pub fn past_blocks_storage_capacity( | ||
| mut self, | ||
| past_blocks_storage_capacity: RingBufferCapacity, | ||
| ) -> Self { | ||
| self.past_blocks_storage_capacity = past_blocks_storage_capacity; | ||
| self | ||
| } | ||
|
|
||
| /// Sets the stream buffer capacity. | ||
| /// | ||
| /// Controls the maximum number of messages that can be buffered in the stream | ||
| /// before backpressure is applied. | ||
| /// | ||
| /// # Arguments | ||
| /// | ||
| /// * `buffer_capacity` - Maximum number of messages to buffer (must be greater than 0) | ||
| #[must_use] | ||
| pub fn buffer_capacity(mut self, buffer_capacity: usize) -> Self { | ||
| self.buffer_capacity = buffer_capacity; | ||
| self | ||
| } | ||
|
|
||
| /// Connects to an existing provider | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if the provider connection fails. | ||
| pub async fn connect<N: Network>( | ||
| self, | ||
| provider: impl IntoRobustProvider<N>, | ||
| ) -> Result<ConnectedBlockRangeScanner<N>, ScannerError> { | ||
| if self.max_block_range == 0 { | ||
| return Err(ScannerError::InvalidMaxBlockRange); | ||
| } | ||
| if self.buffer_capacity == 0 { | ||
| return Err(ScannerError::InvalidBufferCapacity); | ||
| } | ||
| let provider = provider.into_robust_provider().await?; | ||
| Ok(ConnectedBlockRangeScanner { | ||
| provider, | ||
| max_block_range: self.max_block_range, | ||
| past_blocks_storage_capacity: self.past_blocks_storage_capacity, | ||
| buffer_capacity: self.buffer_capacity, | ||
| }) | ||
| } | ||
| } | ||
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,18 @@ | ||
| mod builder; | ||
| pub(crate) mod common; | ||
LeoPatOZ marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mod range_iterator; | ||
| mod reorg_handler; | ||
| mod ring_buffer; | ||
| mod scanner; | ||
| mod sync_handler; | ||
|
|
||
| pub use builder::BlockRangeScanner; | ||
| pub use common::BlockScannerResult; | ||
| pub use ring_buffer::RingBufferCapacity; | ||
| pub use scanner::ConnectedBlockRangeScanner; | ||
|
|
||
| pub use common::{ | ||
| DEFAULT_BLOCK_CONFIRMATIONS, DEFAULT_MAX_BLOCK_RANGE, DEFAULT_STREAM_BUFFER_CAPACITY, | ||
| }; | ||
|
|
||
| pub(crate) use range_iterator::RangeIterator; | ||
0xNeshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.