Skip to content
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

refactor: use EC-recovered tx in builder #21

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use reth_payload_builder::{
use reth_primitives::{
constants::{BEACON_NONCE, EMPTY_OMMER_ROOT},
proofs, Block, BlockNumber, ChainSpec, Header, Receipt, SealedBlock, SealedHeader,
TransactionSigned, U256,
TransactionSigned, TransactionSignedEcRecovered, U256,
};
use reth_provider::{
BlockReaderIdExt, CanonStateNotification, PostState, StateProvider, StateProviderFactory,
Expand All @@ -41,7 +41,7 @@ use tokio_stream::wrappers::{errors::BroadcastStreamRecvError, BroadcastStream};
use tokio_util::time::DelayQueue;

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct BundleCompact(Vec<TransactionSigned>);
pub struct BundleCompact(Vec<TransactionSignedEcRecovered>);

impl BundleCompact {
/// returns whether `self` conflicts with `other` in the sense that both cannot be executed
Expand All @@ -65,7 +65,7 @@ type BundleId = u64;
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Bundle {
pub id: BundleId,
pub txs: Vec<TransactionSigned>,
pub txs: Vec<TransactionSignedEcRecovered>,
pub block_num: BlockNumber,
pub eligibility: RangeInclusive<u64>,
}
Expand Down Expand Up @@ -546,7 +546,7 @@ fn build_on_state<S: StateProvider, I: Iterator<Item = (BundleId, BundleCompact)
&config.attributes,
config.extra_data,
&block_env,
txs,
txs.into_iter().map(|tx| tx.into_signed()).collect(),
post_state,
cumulative_gas_used,
)?;
Expand Down Expand Up @@ -577,7 +577,7 @@ fn execute<DB, I>(
where
DB: DatabaseRef,
<DB as DatabaseRef>::Error: std::fmt::Debug,
I: Iterator<Item = TransactionSigned>,
I: Iterator<Item = TransactionSignedEcRecovered>,
{
let base_fee = block_env.basefee.to::<u64>();
let block_num = block_env.number.to::<u64>();
Expand All @@ -586,12 +586,6 @@ where
let mut post_state = PostState::default();

for tx in txs {
let tx = tx
.into_ecrecovered()
.ok_or(PayloadBuilderError::Internal(RethError::Custom(
"unable to recover tx signer".into(),
)))?;

// construct EVM
let tx_env = tx_env_with_recovered(&tx);
let env = Env {
Expand Down Expand Up @@ -764,6 +758,7 @@ mod tests {
let tx_encoded = tx.rlp_signed(&signature);
let tx = TransactionSigned::decode_enveloped(Bytes::from(tx_encoded.as_ref()))
.expect("can decode tx");
let tx = tx.into_ecrecovered().expect("can recover tx signer");

let execution = execute(&mut db, &cfg_env, &block_env, 0, vec![tx].into_iter())
.expect("execution doesn't fail");
Expand Down