feat: add SealedBlock in reth-primitives-traits (#13735)

This commit is contained in:
Matthias Seitz
2025-01-15 02:12:43 +01:00
committed by GitHub
parent 1267718c7e
commit 83b2fb9b41
171 changed files with 3231 additions and 2866 deletions

View File

@ -91,11 +91,11 @@ impl Case for BlockchainTestCase {
// Insert initial test state into the provider.
provider.insert_historical_block(
SealedBlock::new(
SealedBlock::<reth_primitives::Block>::from_sealed_parts(
case.genesis_block_header.clone().into(),
BlockBody::default(),
)
.try_seal_with_senders()
.try_recover()
.unwrap(),
)?;
case.pre.write_to_db(provider.tx_ref())?;
@ -111,10 +111,9 @@ 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())?;
provider.insert_historical_block(
decoded.clone().try_seal_with_senders().unwrap(),
)?;
let decoded =
SealedBlock::<reth_primitives::Block>::decode(&mut block.rlp.as_ref())?;
provider.insert_historical_block(decoded.clone().try_recover().unwrap())?;
Ok::<Option<SealedBlock>, Error>(Some(decoded))
})?;
provider

View File

@ -1,6 +1,6 @@
//! Generators for different data structures like block headers, block bodies and ranges of those.
use alloy_consensus::{Header, Transaction as _, TxLegacy};
use alloy_consensus::{Block, Header, Transaction as _, TxLegacy};
use alloy_eips::{
eip1898::BlockWithParent,
eip4895::{Withdrawal, Withdrawals},
@ -16,7 +16,7 @@ use reth_primitives::{
TransactionSigned,
};
use reth_primitives_traits::crypto::secp256k1::sign_message;
use reth_primitives_traits::{crypto::secp256k1::sign_message, Block as _};
use secp256k1::{Keypair, Secp256k1};
use std::{
cmp::{max, min},
@ -125,7 +125,7 @@ pub fn random_header<R: Rng>(rng: &mut R, number: u64, parent: Option<B256>) ->
parent_hash: parent.unwrap_or_default(),
..Default::default()
};
SealedHeader::seal(header)
SealedHeader::seal_slow(header)
}
/// Generates a random legacy [Transaction].
@ -234,10 +234,11 @@ pub fn random_block<R: Rng>(rng: &mut R, number: u64, block_params: BlockParams)
..Default::default()
};
SealedBlock::new(
SealedHeader::seal(header),
BlockBody { transactions, ommers, withdrawals: withdrawals.map(Withdrawals::new) },
)
Block {
header,
body: BlockBody { transactions, ommers, withdrawals: withdrawals.map(Withdrawals::new) },
}
.seal_slow()
}
/// Generate a range of random blocks.