-
Notifications
You must be signed in to change notification settings - Fork 36
Add permit flashtestations tx calls from builder #285
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
Changes from 4 commits
2587c0b
d5bddbd
f757014
9f2874a
4a14be2
42df8eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ use alloy_consensus::TxEip1559; | |||||||
| use alloy_eips::Encodable2718; | ||||||||
| use alloy_evm::{Database, Evm}; | ||||||||
| use alloy_op_evm::OpEvm; | ||||||||
| use alloy_primitives::{Address, B256, TxKind}; | ||||||||
| use alloy_primitives::{Address, TxKind}; | ||||||||
| use alloy_sol_types::{Error, SolCall, SolEvent, SolInterface, sol}; | ||||||||
| use core::fmt::Debug; | ||||||||
| use op_alloy_consensus::OpTypedTransaction; | ||||||||
|
|
@@ -11,8 +11,9 @@ use reth_evm::{ConfigureEvm, precompiles::PrecompilesMap}; | |||||||
| use reth_optimism_primitives::OpTransactionSigned; | ||||||||
| use reth_primitives::Recovered; | ||||||||
| use reth_provider::StateProvider; | ||||||||
| use reth_revm::{State, database::StateProviderDatabase}; | ||||||||
| use reth_revm::State; | ||||||||
| use revm::{ | ||||||||
| DatabaseRef, | ||||||||
| context::result::{ExecutionResult, ResultAndState}, | ||||||||
| inspector::NoOpInspector, | ||||||||
| }; | ||||||||
|
|
@@ -21,9 +22,10 @@ use tracing::warn; | |||||||
| use crate::{ | ||||||||
| builders::{ | ||||||||
| BuilderTransactionCtx, BuilderTransactionError, BuilderTransactions, | ||||||||
| builder_tx::{BuilderTxBase, get_nonce, log_exists}, | ||||||||
| InvalidContractDataError, | ||||||||
| builder_tx::{BuilderTxBase, get_nonce}, | ||||||||
| context::OpPayloadBuilderCtx, | ||||||||
| flashblocks::payload::FlashblocksExtraCtx, | ||||||||
| flashblocks::payload::{FlashblocksExecutionInfo, FlashblocksExtraCtx}, | ||||||||
| }, | ||||||||
| flashtestations::builder_tx::FlashtestationsBuilderTx, | ||||||||
| primitives::reth::ExecutionInfo, | ||||||||
|
|
@@ -53,8 +55,6 @@ sol!( | |||||||
| pub(super) enum FlashblockNumberError { | ||||||||
| #[error("flashblocks number contract tx reverted: {0:?}")] | ||||||||
| Revert(IFlashblockNumber::IFlashblockNumberErrors), | ||||||||
| #[error("contract may be invalid, mismatch in log emitted: expected {0:?}")] | ||||||||
| LogMismatch(B256), | ||||||||
| #[error("unknown revert: {0} err: {1}")] | ||||||||
| Unknown(String, Error), | ||||||||
| #[error("halt: {0:?}")] | ||||||||
|
|
@@ -64,14 +64,17 @@ pub(super) enum FlashblockNumberError { | |||||||
| // This will be the end of block transaction of a regular block | ||||||||
| #[derive(Debug, Clone)] | ||||||||
| pub(super) struct FlashblocksBuilderTx { | ||||||||
| pub base_builder_tx: BuilderTxBase, | ||||||||
| pub flashtestations_builder_tx: Option<FlashtestationsBuilderTx>, | ||||||||
| pub base_builder_tx: BuilderTxBase<FlashblocksExtraCtx>, | ||||||||
| pub flashtestations_builder_tx: | ||||||||
| Option<FlashtestationsBuilderTx<FlashblocksExtraCtx, FlashblocksExecutionInfo>>, | ||||||||
| } | ||||||||
|
|
||||||||
| impl FlashblocksBuilderTx { | ||||||||
| pub(super) fn new( | ||||||||
| signer: Option<Signer>, | ||||||||
| flashtestations_builder_tx: Option<FlashtestationsBuilderTx>, | ||||||||
| flashtestations_builder_tx: Option< | ||||||||
| FlashtestationsBuilderTx<FlashblocksExtraCtx, FlashblocksExecutionInfo>, | ||||||||
| >, | ||||||||
| ) -> Self { | ||||||||
| let base_builder_tx = BuilderTxBase::new(signer); | ||||||||
| Self { | ||||||||
|
|
@@ -81,40 +84,46 @@ impl FlashblocksBuilderTx { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| impl BuilderTransactions<FlashblocksExtraCtx> for FlashblocksBuilderTx { | ||||||||
| fn simulate_builder_txs<Extra: Debug + Default>( | ||||||||
| impl BuilderTransactions<FlashblocksExtraCtx, FlashblocksExecutionInfo> for FlashblocksBuilderTx { | ||||||||
| fn simulate_builder_txs( | ||||||||
| &self, | ||||||||
| state_provider: impl StateProvider + Clone, | ||||||||
| info: &mut ExecutionInfo<Extra>, | ||||||||
| info: &mut ExecutionInfo<FlashblocksExecutionInfo>, | ||||||||
| ctx: &OpPayloadBuilderCtx<FlashblocksExtraCtx>, | ||||||||
| db: &mut State<impl Database>, | ||||||||
| db: &mut State<impl Database + DatabaseRef>, | ||||||||
| top_of_block: bool, | ||||||||
| ) -> Result<Vec<BuilderTransactionCtx>, BuilderTransactionError> { | ||||||||
| let mut builder_txs = Vec::<BuilderTransactionCtx>::new(); | ||||||||
|
|
||||||||
| if ctx.is_first_flashblock() { | ||||||||
| let flashblocks_builder_tx = self.base_builder_tx.simulate_builder_tx(ctx, db)?; | ||||||||
| let flashblocks_builder_tx = self.base_builder_tx.simulate_builder_tx(ctx, &mut *db)?; | ||||||||
| builder_txs.extend(flashblocks_builder_tx.clone()); | ||||||||
| } | ||||||||
|
|
||||||||
| if ctx.is_last_flashblock() { | ||||||||
| let base_tx = self.base_builder_tx.simulate_builder_tx(ctx, db)?; | ||||||||
| let base_tx = self.base_builder_tx.simulate_builder_tx(ctx, &mut *db)?; | ||||||||
| builder_txs.extend(base_tx.clone()); | ||||||||
|
|
||||||||
| if let Some(flashtestations_builder_tx) = &self.flashtestations_builder_tx { | ||||||||
| // Commit state that is included to get the correct nonce | ||||||||
| if let Some(builder_tx) = base_tx { | ||||||||
| self.commit_txs(vec![builder_tx.signed_tx], ctx, db)?; | ||||||||
| } | ||||||||
| // We only include flashtestations txs in the last flashblock | ||||||||
| let mut simulation_state = self.simulate_builder_txs_state::<FlashblocksExtraCtx>( | ||||||||
| state_provider.clone(), | ||||||||
| base_tx.iter().collect(), | ||||||||
| ctx, | ||||||||
| db, | ||||||||
| )?; | ||||||||
| let flashtestations_builder_txs = flashtestations_builder_tx.simulate_builder_txs( | ||||||||
| match flashtestations_builder_tx.simulate_builder_txs( | ||||||||
| state_provider, | ||||||||
| info, | ||||||||
| ctx, | ||||||||
| &mut simulation_state, | ||||||||
| )?; | ||||||||
| builder_txs.extend(flashtestations_builder_txs); | ||||||||
| db, | ||||||||
| top_of_block, | ||||||||
| ) { | ||||||||
| Ok(flashtestations_builder_txs) => { | ||||||||
| builder_txs.extend(flashtestations_builder_txs) | ||||||||
| } | ||||||||
| Err(e) => { | ||||||||
| warn!(target: "flashtestations", error = ?e, "failed to add flashtestations builder tx") | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| Ok(builder_txs) | ||||||||
|
|
@@ -126,15 +135,18 @@ impl BuilderTransactions<FlashblocksExtraCtx> for FlashblocksBuilderTx { | |||||||
| pub(super) struct FlashblocksNumberBuilderTx { | ||||||||
| pub signer: Option<Signer>, | ||||||||
| pub flashblock_number_address: Address, | ||||||||
| pub base_builder_tx: BuilderTxBase, | ||||||||
| pub flashtestations_builder_tx: Option<FlashtestationsBuilderTx>, | ||||||||
| pub base_builder_tx: BuilderTxBase<FlashblocksExtraCtx>, | ||||||||
| pub flashtestations_builder_tx: | ||||||||
| Option<FlashtestationsBuilderTx<FlashblocksExtraCtx, FlashblocksExecutionInfo>>, | ||||||||
| } | ||||||||
|
|
||||||||
| impl FlashblocksNumberBuilderTx { | ||||||||
| pub(super) fn new( | ||||||||
| signer: Option<Signer>, | ||||||||
| flashblock_number_address: Address, | ||||||||
| flashtestations_builder_tx: Option<FlashtestationsBuilderTx>, | ||||||||
| flashtestations_builder_tx: Option< | ||||||||
| FlashtestationsBuilderTx<FlashblocksExtraCtx, FlashblocksExecutionInfo>, | ||||||||
| >, | ||||||||
| ) -> Self { | ||||||||
| let base_builder_tx = BuilderTxBase::new(signer); | ||||||||
| Self { | ||||||||
|
|
@@ -145,14 +157,11 @@ impl FlashblocksNumberBuilderTx { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // TODO: remove and clean up in favour of simulate_call() | ||||||||
|
||||||||
| // TODO: remove and clean up in favour of simulate_call() | |
| // TODO: remove and clean up in favour of simulate_call(). | |
| // Tracking issue: https://github.com/your-org/your-repo/issues/1234 |
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.
Do we want to put actual logs in there?
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.
no planning to deprecate this soon after permit changes are tested and merged
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.
can you just pass db?