Skip to content

Commit

Permalink
migrate more
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jan 10, 2025
1 parent 51654d5 commit 82ffabe
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
21 changes: 19 additions & 2 deletions bin/reth-bench/src/bench/new_payload_fcu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ use crate::{
valid_payload::{call_forkchoice_updated, call_new_payload},
};
use alloy_primitives::B256;
use alloy_provider::Provider;
use alloy_provider::{network::AnyRpcBlock, Provider};
use alloy_rpc_types_engine::ForkchoiceState;
use clap::Parser;
use csv::Writer;
use reth_cli_runner::CliContext;
use reth_node_core::args::BenchmarkArgs;
use reth_primitives::SealedBlock;
use reth_primitives_traits::SealedHeader;
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::time::Instant;
use tracing::{debug, info};
Expand Down Expand Up @@ -46,7 +47,7 @@ impl Command {
let block_res =
block_provider.get_block_by_number(next_block.into(), true.into()).await;
let block = block_res.unwrap().unwrap();
let block: SealedBlock = block.try_into().unwrap();
let block = from_any_rpc_block(block);
let head_block_hash = block.hash();
let safe_block_hash = block_provider
.get_block_by_number(block.number.saturating_sub(32).into(), false.into());
Expand Down Expand Up @@ -161,3 +162,19 @@ impl Command {
Ok(())
}
}

// TODO(mattsse): integrate in alloy
pub(crate) fn from_any_rpc_block(block: AnyRpcBlock) -> SealedBlock {
let block = block.inner;
let block_hash = block.header.hash;
let block = block.try_map_transactions(|tx| tx.try_into()).unwrap();

SealedBlock::from_sealed_parts(
SealedHeader::new(block.header.inner.into_header_with_defaults(), block_hash),
reth_primitives::BlockBody {
transactions: block.transactions.into_transactions().collect(),
ommers: Default::default(),
withdrawals: block.withdrawals.map(|w| w.into_inner().into()),
},
)
}
4 changes: 2 additions & 2 deletions bin/reth-bench/src/bench/new_payload_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::{
bench::{
context::BenchContext,
new_payload_fcu::from_any_rpc_block,
output::{
NewPayloadResult, TotalGasOutput, TotalGasRow, GAS_OUTPUT_SUFFIX,
NEW_PAYLOAD_OUTPUT_SUFFIX,
Expand All @@ -16,7 +17,6 @@ use clap::Parser;
use csv::Writer;
use reth_cli_runner::CliContext;
use reth_node_core::args::BenchmarkArgs;
use reth_primitives::SealedBlock;
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::time::Instant;
use tracing::{debug, info};
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Command {
let block_res =
block_provider.get_block_by_number(next_block.into(), true.into()).await;
let block = block_res.unwrap().unwrap();
let block: SealedBlock = block.try_into().unwrap();
let block = from_any_rpc_block(block);

next_block += 1;
sender.send(block).await.unwrap();
Expand Down
10 changes: 4 additions & 6 deletions crates/engine/invalid-block-hooks/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_evm::{
ConfigureEvm,
};
use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader};
use reth_primitives_traits::SignedTransaction;
use reth_primitives_traits::{Block, BlockBody, SignedTransaction};
use reth_provider::{BlockExecutionOutput, ChainSpecProvider, StateProviderFactory};
use reth_revm::{
database::StateProviderDatabase, db::states::bundle_state::BundleRetention,
Expand Down Expand Up @@ -99,7 +99,7 @@ where

// Re-execute all of the transactions in the block to load all touched accounts into
// the cache DB.
for tx in block.transactions() {
for tx in block.body().transactions() {
self.evm_config.fill_tx_env(
evm.tx_mut(),
tx,
Expand All @@ -113,10 +113,8 @@ where

// use U256::MAX here for difficulty, because fetching it is annoying
// NOTE: This is not mut because we are not doing the DAO irregular state change here
let balance_increments = post_block_balance_increments(
self.provider.chain_spec().as_ref(),
&block.clone().unseal().block,
);
let balance_increments =
post_block_balance_increments(self.provider.chain_spec().as_ref(), block.block());

// increment balances
db.increment_balances(balance_increments)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ mod tests {
let expected = blocks
.iter()
.cloned()
.map(|b| Some(ExecutionPayloadBodyV1::from_block(b.into_block::<Block>())))
.map(|b| Some(ExecutionPayloadBodyV1::from_block(b.into_block())))
.collect::<Vec<_>>();

let res = api.get_payload_bodies_by_range_v1(start, count).await.unwrap();
Expand Down Expand Up @@ -1197,7 +1197,7 @@ mod tests {
if first_missing_range.contains(&b.number) {
None
} else {
Some(ExecutionPayloadBodyV1::from_block(b.into_block::<Block>()))
Some(ExecutionPayloadBodyV1::from_block(b.into_block()))
}
})
.collect::<Vec<_>>();
Expand All @@ -1216,7 +1216,7 @@ mod tests {
{
None
} else {
Some(ExecutionPayloadBodyV1::from_block(b.into_block::<Block>()))
Some(ExecutionPayloadBodyV1::from_block(b.into_block()))
}
})
.collect::<Vec<_>>();
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-engine-api/tests/it/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn payload_body_roundtrip() {
BlockRangeParams { tx_count: 0..2, ..Default::default() },
) {
let payload_body: ExecutionPayloadBodyV1 =
ExecutionPayloadBodyV1::from_block(block.clone().into_block::<Block>());
ExecutionPayloadBodyV1::from_block(block.clone().into_block());

assert_eq!(
Ok(block.body().transactions.clone()),
Expand Down
2 changes: 1 addition & 1 deletion crates/static-file/static-file/src/static_file_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ mod tests {

let tx = db.factory.db_ref().tx_mut().expect("init tx");
for block in &blocks {
TestStageDB::insert_header(None, &tx, block.sealed_header(), U256::ZERO)
TestStageDB::insert_header(None, &tx, &block.clone_sealed_header(), U256::ZERO)
.expect("insert block header");
}
tx.commit().expect("commit tx");
Expand Down
9 changes: 5 additions & 4 deletions testing/ef-tests/src/cases/blockchain_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ impl Case for BlockchainTestCase {

// Insert initial test state into the provider.
provider.insert_historical_block(
SealedBlock::new(
case.genesis_block_header.clone().into(),
SealedBlock::seal_parts(
case.genesis_block_header.clone(),
BlockBody::default(),
)
.try_with_senders()
.try_recover()
.unwrap(),
)?;
case.pre.write_to_db(provider.tx_ref())?;
Expand All @@ -111,7 +111,8 @@ impl Case for BlockchainTestCase {

// Decode and insert blocks, creating a chain of blocks for the test case.
let last_block = case.blocks.iter().try_fold(None, |_, block| {
let decoded = SealedBlock::decode(&mut block.rlp.as_ref())?;
let decoded =
SealedBlock::<reth_primitives::Block>::decode(&mut block.rlp.as_ref())?;
provider
.insert_historical_block(decoded.clone().try_with_senders().unwrap())?;
Ok::<Option<SealedBlock>, Error>(Some(decoded))
Expand Down

0 comments on commit 82ffabe

Please sign in to comment.