-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Implement txpool interop support for optimism #15105
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
mattsse
merged 2 commits into
paradigmxyz:main
from
NethermindEth:msozin/op-reth-txpool-interop
Mar 27, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,47 @@ | ||
| use crate::supervisor::{InteropTxValidatorError, InvalidInboxEntry}; | ||
| use op_alloy_consensus::interop::SafetyLevel; | ||
| use reth_transaction_pool::error::PoolTransactionError; | ||
| use std::any::Any; | ||
|
|
||
| /// Wrapper for [`InteropTxValidatorError`] to implement [`PoolTransactionError`] for it. | ||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum InvalidCrossTx { | ||
| /// Errors produced by supervisor validation | ||
| #[error(transparent)] | ||
| ValidationError(#[from] InteropTxValidatorError), | ||
| /// Error cause by cross chain tx during not active interop hardfork | ||
| #[error("cross chain tx is invalid before interop")] | ||
| CrossChainTxPreInterop, | ||
| } | ||
|
|
||
| impl PoolTransactionError for InvalidCrossTx { | ||
| fn is_bad_transaction(&self) -> bool { | ||
| match self { | ||
| Self::ValidationError(err) => { | ||
| match err { | ||
| InteropTxValidatorError::InvalidInboxEntry(err) => match err { | ||
| // This transaction could become valid after a while | ||
| InvalidInboxEntry::MinimumSafety { got, .. } => match got { | ||
| // This transaction will never become valid | ||
| SafetyLevel::Invalid => true, | ||
| // This transaction will become valid when origin chain progress | ||
| _ => false, | ||
| }, | ||
| // This tx will not become valid unless supervisor is reconfigured | ||
| InvalidInboxEntry::UnknownChain(_) => true, | ||
| }, | ||
| // Rpc error or supervisor haven't responded in time | ||
| InteropTxValidatorError::RpcClientError(_) | | ||
| InteropTxValidatorError::ValidationTimeout(_) => false, | ||
| // Transaction caused unknown (for parsing) error in supervisor | ||
| InteropTxValidatorError::SupervisorServerError(_) => true, | ||
| } | ||
| } | ||
| Self::CrossChainTxPreInterop => true, | ||
|
Comment on lines
19
to
40
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. nice code comments! |
||
| } | ||
| } | ||
|
|
||
| fn as_any(&self) -> &dyn Any { | ||
| self | ||
| } | ||
| } | ||
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,41 @@ | ||
| // Source: https://github.com/op-rs/kona | ||
| // Copyright © 2023 kona contributors Copyright © 2024 Optimism | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
| // associated documentation files (the “Software”), to deal in the Software without restriction, | ||
| // including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
| // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in all copies or | ||
| // substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
| // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| use crate::supervisor::CROSS_L2_INBOX_ADDRESS; | ||
| use alloy_eips::eip2930::AccessListItem; | ||
| use alloy_primitives::B256; | ||
|
|
||
| /// Parses [`AccessListItem`]s to inbox entries. | ||
| /// | ||
| /// Return flattened iterator with all inbox entries. | ||
| pub fn parse_access_list_items_to_inbox_entries<'a>( | ||
| access_list_items: impl Iterator<Item = &'a AccessListItem>, | ||
| ) -> impl Iterator<Item = &'a B256> { | ||
| access_list_items.filter_map(parse_access_list_item_to_inbox_entries).flatten() | ||
| } | ||
|
|
||
| /// Parse [`AccessListItem`] to inbox entries, if any. | ||
| /// Max 3 inbox entries can exist per [`AccessListItem`] that points to [`CROSS_L2_INBOX_ADDRESS`]. | ||
| /// | ||
| /// Returns `Vec::new()` if [`AccessListItem`] address doesn't point to [`CROSS_L2_INBOX_ADDRESS`]. | ||
| // TODO: add url to spec once [pr](https://github.com/ethereum-optimism/specs/pull/612) is merged | ||
| fn parse_access_list_item_to_inbox_entries( | ||
| access_list_item: &AccessListItem, | ||
| ) -> Option<impl Iterator<Item = &B256>> { | ||
| (access_list_item.address == CROSS_L2_INBOX_ADDRESS) | ||
| .then(|| access_list_item.storage_keys.iter()) | ||
| } |
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,107 @@ | ||
| //! This is our custom implementation of validator struct | ||
|
|
||
| use crate::supervisor::{ExecutingDescriptor, InteropTxValidatorError}; | ||
| use alloy_primitives::B256; | ||
| use alloy_rpc_client::ReqwestClient; | ||
| use futures_util::future::BoxFuture; | ||
| use op_alloy_consensus::interop::SafetyLevel; | ||
| use std::{borrow::Cow, future::IntoFuture, time::Duration}; | ||
|
|
||
| /// Supervisor hosted by op-labs | ||
| // TODO: This should be changes to actual supervisor url | ||
| pub const DEFAULT_SUPERVISOR_URL: &str = "http://localhost:1337/"; | ||
|
|
||
| /// The default request timeout to use | ||
| const DEFAULT_REQUEST_TIMOUT: Duration = Duration::from_millis(100); | ||
|
|
||
| /// Implementation of the supervisor trait for the interop. | ||
| #[derive(Debug, Clone)] | ||
| pub struct SupervisorClient { | ||
| client: ReqwestClient, | ||
| /// The default | ||
| safety: SafetyLevel, | ||
| /// The default request timeout | ||
| timeout: Duration, | ||
| } | ||
|
|
||
| impl SupervisorClient { | ||
| /// Creates a new supervisor validator. | ||
| pub async fn new(supervisor_endpoint: impl Into<String>, safety: SafetyLevel) -> Self { | ||
| let client = ReqwestClient::builder() | ||
| .connect(supervisor_endpoint.into().as_str()) | ||
| .await | ||
| .expect("building supervisor client"); | ||
| Self { client, safety, timeout: DEFAULT_REQUEST_TIMOUT } | ||
| } | ||
|
|
||
| /// Configures a custom timeout | ||
| pub fn with_timeout(mut self, timeout: Duration) -> Self { | ||
| self.timeout = timeout; | ||
| self | ||
| } | ||
|
|
||
| /// Returns safely level | ||
| pub fn safety(&self) -> SafetyLevel { | ||
| self.safety | ||
| } | ||
|
|
||
| /// Executes a `supervisor_checkAccessList` with the configured safety level. | ||
| pub fn check_access_list<'a>( | ||
| &self, | ||
| inbox_entries: &'a [B256], | ||
| executing_descriptor: ExecutingDescriptor, | ||
| ) -> CheckAccessListRequest<'a> { | ||
| CheckAccessListRequest { | ||
| client: self.client.clone(), | ||
| inbox_entries: Cow::Borrowed(inbox_entries), | ||
| executing_descriptor, | ||
| timeout: self.timeout, | ||
| safety: self.safety, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A Request future that issues a `supervisor_checkAccessList` request. | ||
| #[derive(Debug, Clone)] | ||
| pub struct CheckAccessListRequest<'a> { | ||
| client: ReqwestClient, | ||
| inbox_entries: Cow<'a, [B256]>, | ||
| executing_descriptor: ExecutingDescriptor, | ||
| timeout: Duration, | ||
| safety: SafetyLevel, | ||
| } | ||
|
|
||
| impl CheckAccessListRequest<'_> { | ||
| /// Configures the timeout to use for the request if any. | ||
| pub fn with_timeout(mut self, timeout: Duration) -> Self { | ||
| self.timeout = timeout; | ||
| self | ||
| } | ||
|
|
||
| /// Configures the [`SafetyLevel`] for this request | ||
| pub fn with_safety(mut self, safety: SafetyLevel) -> Self { | ||
| self.safety = safety; | ||
| self | ||
| } | ||
| } | ||
|
|
||
| impl<'a> IntoFuture for CheckAccessListRequest<'a> { | ||
| type Output = Result<(), InteropTxValidatorError>; | ||
| type IntoFuture = BoxFuture<'a, Self::Output>; | ||
|
|
||
| fn into_future(self) -> Self::IntoFuture { | ||
| let Self { client, inbox_entries, executing_descriptor, timeout, safety } = self; | ||
| Box::pin(async move { | ||
| tokio::time::timeout( | ||
| timeout, | ||
| client.request( | ||
| "supervisor_checkAccessList", | ||
| (inbox_entries, safety, executing_descriptor), | ||
| ), | ||
| ) | ||
| .await | ||
| .map_err(|_| InteropTxValidatorError::ValidationTimeout(timeout.as_secs()))? | ||
| .map_err(InteropTxValidatorError::client) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
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.