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

small refactoring in payload crate #6358

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 4 additions & 12 deletions crates/payload/builder/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use reth_primitives::{
},
U256,
};

use std::{
cell::RefCell,
collections::{hash_map::Entry, HashMap},
Expand Down Expand Up @@ -91,17 +90,10 @@ impl<'a, DB: DatabaseRef> Database for CachedReadsDbMut<'a, DB> {

fn storage(&mut self, address: Address, index: U256) -> Result<U256, Self::Error> {
match self.cached.accounts.entry(address) {
Entry::Occupied(mut acc_entry) => {
let acc_entry = acc_entry.get_mut();
match acc_entry.storage.entry(index) {
Entry::Occupied(entry) => Ok(*entry.get()),
Entry::Vacant(entry) => {
let slot = self.db.storage_ref(address, index)?;
entry.insert(slot);
Ok(slot)
}
}
}
Entry::Occupied(mut acc_entry) => match acc_entry.get_mut().storage.entry(index) {
Entry::Occupied(entry) => Ok(*entry.get()),
Entry::Vacant(entry) => Ok(*entry.insert(self.db.storage_ref(address, index)?)),
},
Entry::Vacant(acc_entry) => {
// acc needs to be loaded for us to access slots.
let info = self.db.basic_ref(address)?;
Expand Down
6 changes: 4 additions & 2 deletions crates/payload/builder/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ where
/// Creates a new [NoopPayloadBuilderService].
pub fn new() -> (Self, PayloadBuilderHandle<Engine>) {
let (service_tx, command_rx) = mpsc::unbounded_channel();
let handle = PayloadBuilderHandle::new(service_tx);
(Self { command_rx: UnboundedReceiverStream::new(command_rx) }, handle)
(
Self { command_rx: UnboundedReceiverStream::new(command_rx) },
PayloadBuilderHandle::new(service_tx),
)
}
}

Expand Down
15 changes: 5 additions & 10 deletions crates/payload/builder/src/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,11 @@ impl PayloadBuilderAttributes for OptimismPayloadBuilderAttributes {
(payload_id_optimism(&parent, &attributes, &transactions), transactions)
};

let withdraw = attributes.payload_attributes.withdrawals.map(
|withdrawals: Vec<reth_rpc_types::withdrawal::Withdrawal>| {
Withdrawals::new(
withdrawals
.into_iter()
.map(convert_standalone_withdraw_to_withdrawal) // Removed the parentheses here
.collect(),
)
},
);
let withdraw = attributes.payload_attributes.withdrawals.map(|withdrawals| {
Withdrawals::new(
withdrawals.into_iter().map(convert_standalone_withdraw_to_withdrawal).collect(),
)
});

let payload_attributes = EthPayloadBuilderAttributes {
id,
Expand Down
18 changes: 8 additions & 10 deletions crates/payload/builder/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,14 @@ impl EthPayloadBuilderAttributes {
pub fn new(parent: B256, attributes: PayloadAttributes) -> Self {
let id = payload_id(&parent, &attributes);

let withdraw = attributes.withdrawals.map(
|withdrawals: Vec<reth_rpc_types::withdrawal::Withdrawal>| {
Withdrawals::new(
withdrawals
.into_iter()
.map(convert_standalone_withdraw_to_withdrawal) // Removed the parentheses here
.collect(),
)
},
);
let withdraw = attributes.withdrawals.map(|withdrawals| {
Withdrawals::new(
withdrawals
.into_iter()
.map(convert_standalone_withdraw_to_withdrawal) // Removed the parentheses here
.collect(),
)
});

Self {
id,
Expand Down
Loading