feat: update el requests for devnet 4 (#11865)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Oliver
2024-10-19 14:48:35 +02:00
committed by GitHub
parent 2ae93682b4
commit 3bd695ee63
106 changed files with 799 additions and 1328 deletions

View File

@ -87,7 +87,7 @@ pub struct Header {
/// Parent beacon block root.
pub parent_beacon_block_root: Option<B256>,
/// Requests root.
pub requests_root: Option<B256>,
pub requests_hash: Option<B256>,
}
impl From<Header> for SealedHeader {
@ -113,7 +113,7 @@ impl From<Header> for SealedHeader {
blob_gas_used: value.blob_gas_used.map(|v| v.to::<u64>()),
excess_blob_gas: value.excess_blob_gas.map(|v| v.to::<u64>()),
parent_beacon_block_root: value.parent_beacon_block_root,
requests_root: value.requests_root,
requests_hash: value.requests_hash,
};
Self::new(header, value.hash)
}

View File

@ -14,10 +14,12 @@ workspace = true
[dependencies]
reth-primitives = { workspace = true, features = ["secp256k1"] }
alloy-eips.workspace = true
alloy-genesis.workspace = true
alloy-primitives.workspace = true
alloy-consensus.workspace = true
rand.workspace = true
secp256k1 = { workspace = true, features = ["rand"] }
[dev-dependencies]
alloy-eips.workspace = true

View File

@ -1,17 +1,14 @@
//! Generators for different data structures like block headers, block bodies and ranges of those.
use alloy_consensus::{Transaction as _, TxLegacy};
use alloy_eips::{
eip6110::DepositRequest, eip7002::WithdrawalRequest, eip7251::ConsolidationRequest,
};
use alloy_primitives::{Address, BlockNumber, Bytes, Parity, Sealable, TxKind, B256, U256};
pub use rand::Rng;
use rand::{
distributions::uniform::SampleRange, rngs::StdRng, seq::SliceRandom, thread_rng, SeedableRng,
};
use reth_primitives::{
proofs, sign_message, Account, BlockBody, Header, Log, Receipt, Request, Requests, SealedBlock,
SealedHeader, StorageEntry, Transaction, TransactionSigned, Withdrawal, Withdrawals,
proofs, sign_message, Account, BlockBody, Header, Log, Receipt, SealedBlock, SealedHeader,
StorageEntry, Transaction, TransactionSigned, Withdrawal, Withdrawals,
};
use secp256k1::{Keypair, Secp256k1};
use std::{
@ -201,11 +198,6 @@ pub fn random_block<R: Rng>(rng: &mut R, number: u64, block_params: BlockParams)
let transactions_root = proofs::calculate_transaction_root(&transactions);
let ommers_hash = proofs::calculate_ommers_root(&ommers);
let requests = block_params
.requests_count
.map(|count| (0..count).map(|_| random_request(rng)).collect::<Vec<_>>());
let requests_root = requests.as_ref().map(|requests| proofs::calculate_requests_root(requests));
let withdrawals = block_params.withdrawals_count.map(|count| {
(0..count)
.map(|i| Withdrawal {
@ -226,7 +218,8 @@ pub fn random_block<R: Rng>(rng: &mut R, number: u64, block_params: BlockParams)
transactions_root,
ommers_hash,
base_fee_per_gas: Some(rng.gen()),
requests_root,
// TODO(onbjerg): Proper EIP-7685 request support
requests_hash: None,
withdrawals_root,
..Default::default()
}
@ -236,12 +229,7 @@ pub fn random_block<R: Rng>(rng: &mut R, number: u64, block_params: BlockParams)
SealedBlock {
header: SealedHeader::new(header, seal),
body: BlockBody {
transactions,
ommers,
withdrawals: withdrawals.map(Withdrawals::new),
requests: requests.map(Requests),
},
body: BlockBody { transactions, ommers, withdrawals: withdrawals.map(Withdrawals::new) },
}
}
@ -470,31 +458,6 @@ pub fn random_log<R: Rng>(rng: &mut R, address: Option<Address>, topics_count: O
)
}
/// Generate random request
pub fn random_request<R: Rng>(rng: &mut R) -> Request {
let request_type = rng.gen_range(0..3);
match request_type {
0 => Request::DepositRequest(DepositRequest {
pubkey: rng.gen(),
withdrawal_credentials: rng.gen(),
amount: rng.gen(),
signature: rng.gen(),
index: rng.gen(),
}),
1 => Request::WithdrawalRequest(WithdrawalRequest {
source_address: rng.gen(),
validator_pubkey: rng.gen(),
amount: rng.gen(),
}),
2 => Request::ConsolidationRequest(ConsolidationRequest {
source_address: rng.gen(),
source_pubkey: rng.gen(),
target_pubkey: rng.gen(),
}),
_ => panic!("invalid request type"),
}
}
#[cfg(test)]
mod tests {
use super::*;