-
Notifications
You must be signed in to change notification settings - Fork 178
Refactor: fix docs, clean up code quality #843
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
Open
prestwich
wants to merge
7
commits into
flashbots:develop
Choose a base branch
from
prestwich:prestwich/docs-and-cleanup
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2e7feaf
chore: update docs, clean up code quality
prestwich bc4a166
lint: clippy --all-targets
prestwich 2fad1e0
docs: improve filter documentation
prestwich a7a303d
doc: update SinkSubscription docs
prestwich fecdaae
nit: assume
prestwich ffa51ec
fix: filter logic
prestwich dd1647a
fix: typos
prestwich 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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
| @@ -1,62 +1,82 @@ | ||
| use alloy_eips::{eip7594::BlobTransactionSidecarVariant, Typed2718}; | ||
|
|
||
| use crate::live_builder::order_input::replaceable_order_sink::ReplaceableOrderSink; | ||
| use rbuilder_primitives::{BundleReplacementData, Order, TransactionSignedEcRecoveredWithBlobs}; | ||
| use tracing::trace; | ||
|
|
||
| /// Filters out Orders with incorrect blobs (pre/post fusaka). | ||
| /// Since it's very unlikely what we have many wrong blobs we only filter on insert_order without take note of filtered orders. | ||
| /// If remove_bundle is called we just forward the call to the sink so it might try to remove a filtered order. | ||
| pub struct BlobTypeOrderFilter<FilterFunc> { | ||
| /// Filters out [`Order`]s based on their blob type. [`Order`]s that do not | ||
| /// pass the filter are dropped not inserted. Preconfigured filters are | ||
| /// provided to remove pre-Fusaka [EIP-4844] blobs ([`Self::new_fusaka`]) or | ||
| /// post-Fusaka [EIP-7594] blobs ([`Self::new_pre_fusaka`]). | ||
| /// | ||
| /// Since it's very unlikely that we have many wrong blobs we only filter on | ||
| /// [`ReplaceableOrderSink::insert_order`] without taking note of filtered | ||
| /// [`Order`]s. | ||
| /// | ||
| /// [`ReplaceableOrderSink::remove_bundle`] calls are simply forwarded to the | ||
| /// sink, so it might try to remove a filtered [`Order`]. | ||
| /// | ||
| /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844 | ||
| /// [EIP-7594]: https://eips.ethereum.org/EIPS/eip-7594 | ||
| pub struct BlobTypeOrderFilter { | ||
| sink: Box<dyn ReplaceableOrderSink>, | ||
| ///true if it likes the blob sidecar, false if it doesn't (Order gets filtered). | ||
| filter_func: FilterFunc, | ||
|
|
||
| /// Name of the filter for logging purposes. | ||
| rule_name: &'static str, | ||
|
|
||
| /// `true` if it likes the blob sidecar, `false` if it doesn't ([`Order`] | ||
| /// gets filtered). | ||
| filter_func: fn(&TransactionSignedEcRecoveredWithBlobs) -> bool, | ||
| } | ||
|
|
||
| impl<FilterFunc> std::fmt::Debug for BlobTypeOrderFilter<FilterFunc> { | ||
| impl std::fmt::Debug for BlobTypeOrderFilter { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| f.debug_struct("BlobTypeOrderFilter") | ||
| .field("sink", &"<dyn ReplaceableOrderSink>") | ||
| .field("rule", &self.rule_name) | ||
| .finish() | ||
| } | ||
| } | ||
|
|
||
| /// Filters out EIP-7594 style blobs, supports only EIP-4844 style. | ||
| pub fn new_pre_fusaka( | ||
| sink: Box<dyn ReplaceableOrderSink>, | ||
| ) -> BlobTypeOrderFilter<impl Fn(&TransactionSignedEcRecoveredWithBlobs) -> bool + Send + Sync> { | ||
| BlobTypeOrderFilter::new(sink, |tx| { | ||
| if tx.is_eip4844() { | ||
| matches!(*tx.blobs_sidecar, BlobTransactionSidecarVariant::Eip4844(_)) | ||
| } else { | ||
| true | ||
| impl BlobTypeOrderFilter { | ||
| /// Creates a new [`BlobTypeOrderFilter`], using the given `filter_func` to | ||
| /// filter out orders. | ||
| pub const fn new( | ||
| sink: Box<dyn ReplaceableOrderSink>, | ||
| rule_name: &'static str, | ||
| filter_func: fn(&TransactionSignedEcRecoveredWithBlobs) -> bool, | ||
| ) -> Self { | ||
| Self { | ||
| sink, | ||
| rule_name, | ||
| filter_func, | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| /// Filters out EIP-4844 style, supports only EIP-7594 style blobs. | ||
| pub fn new_fusaka( | ||
| sink: Box<dyn ReplaceableOrderSink>, | ||
| ) -> BlobTypeOrderFilter<impl Fn(&TransactionSignedEcRecoveredWithBlobs) -> bool + Send + Sync> { | ||
| BlobTypeOrderFilter::new(sink, |tx| { | ||
| if tx.is_eip4844() { | ||
| matches!(*tx.blobs_sidecar, BlobTransactionSidecarVariant::Eip7594(_)) | ||
| } else { | ||
| true | ||
| /// Filters out [EIP-4844] style, allowing only [EIP-7594] style blobs. | ||
| /// | ||
| /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844 | ||
| /// [EIP-7594]: https://eips.ethereum.org/EIPS/eip-7594 | ||
| pub const fn new_fusaka(sink: Box<dyn ReplaceableOrderSink>) -> Self { | ||
| fn fusaka(tx: &TransactionSignedEcRecoveredWithBlobs) -> bool { | ||
| !tx.as_ref().is_eip4844() || tx.blobs_sidecar.is_eip7594() | ||
| } | ||
|
|
||
| Self::new(sink, "fusaka", fusaka) | ||
| } | ||
|
|
||
| /// Filters out [EIP-7594] style blobs, allowing only [EIP-4844] style. | ||
| /// | ||
| /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844 | ||
| /// [EIP-7594]: https://eips.ethereum.org/EIPS/eip-7594 | ||
| pub const fn new_pre_fusaka(sink: Box<dyn ReplaceableOrderSink>) -> Self { | ||
| fn pre_fusaka(tx: &TransactionSignedEcRecoveredWithBlobs) -> bool { | ||
| !tx.as_ref().is_eip4844() || tx.blobs_sidecar.is_eip4844() | ||
|
Author
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. this logic relies on 4844 validity condition that transactions cannot have 0 blobs See: |
||
| } | ||
| }) | ||
| } | ||
|
|
||
| impl<FilterFunc: Fn(&TransactionSignedEcRecoveredWithBlobs) -> bool> | ||
| BlobTypeOrderFilter<FilterFunc> | ||
| { | ||
| fn new(sink: Box<dyn ReplaceableOrderSink>, filter_func: FilterFunc) -> Self { | ||
| Self { sink, filter_func } | ||
| Self::new(sink, "pre-fusaka", pre_fusaka) | ||
| } | ||
| } | ||
|
|
||
| impl<FilterFunc: Fn(&TransactionSignedEcRecoveredWithBlobs) -> bool + Send + Sync> | ||
| ReplaceableOrderSink for BlobTypeOrderFilter<FilterFunc> | ||
| { | ||
| impl ReplaceableOrderSink for BlobTypeOrderFilter { | ||
| fn insert_order(&mut self, order: Order) -> bool { | ||
| if order | ||
| .list_txs() | ||
|
|
@@ -65,6 +85,7 @@ impl<FilterFunc: Fn(&TransactionSignedEcRecoveredWithBlobs) -> bool + Send + Syn | |
| { | ||
| self.sink.insert_order(order) | ||
| } else { | ||
| trace!(order_id = ?order.id(), rule = self.rule_name, "Order filtered out by BlobTypeOrderFilter"); | ||
| true | ||
| } | ||
| } | ||
|
|
||
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.
is this comment accurate? there is an
AsRef<Recovered<TransactionSigned>>implementation that allows direct access to the internal tx