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

@ -13,7 +13,7 @@ use reth_codecs_derive::add_arbitrary_tests;
#[cfg_attr(test, derive(arbitrary::Arbitrary, serde::Serialize, serde::Deserialize))]
#[add_arbitrary_tests(compact)]
pub(crate) struct Authorization {
chain_id: U256,
chain_id: u64,
address: Address,
nonce: u64,
}
@ -78,7 +78,7 @@ mod tests {
#[test]
fn test_roundtrip_compact_authorization_list_item() {
let authorization = AlloyAuthorization {
chain_id: U256::from(1),
chain_id: 1u64,
address: address!("dac17f958d2ee523a2206206994597c13d831ec7"),
nonce: 1,
}

View File

@ -45,7 +45,7 @@ pub(crate) struct Header {
#[cfg_attr(test, derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Compact)]
pub(crate) struct HeaderExt {
requests_root: Option<B256>,
requests_hash: Option<B256>,
}
impl HeaderExt {
@ -53,7 +53,7 @@ impl HeaderExt {
///
/// Required since [`Header`] uses `Option<HeaderExt>` as a field.
const fn into_option(self) -> Option<Self> {
if self.requests_root.is_some() {
if self.requests_hash.is_some() {
Some(self)
} else {
None
@ -66,7 +66,7 @@ impl Compact for AlloyHeader {
where
B: bytes::BufMut + AsMut<[u8]>,
{
let extra_fields = HeaderExt { requests_root: self.requests_root };
let extra_fields = HeaderExt { requests_hash: self.requests_hash };
let header = Header {
parent_hash: self.parent_hash,
@ -116,7 +116,7 @@ impl Compact for AlloyHeader {
blob_gas_used: header.blob_gas_used,
excess_blob_gas: header.excess_blob_gas,
parent_beacon_block_root: header.parent_beacon_block_root,
requests_root: header.extra_fields.and_then(|h| h.requests_root),
requests_hash: header.extra_fields.and_then(|h| h.requests_hash),
extra_data: header.extra_data,
};
(alloy_header, buf)
@ -176,7 +176,7 @@ mod tests {
#[test]
fn test_extra_fields() {
let mut header = HOLESKY_BLOCK;
header.extra_fields = Some(HeaderExt { requests_root: Some(B256::random()) });
header.extra_fields = Some(HeaderExt { requests_hash: Some(B256::random()) });
let mut encoded_header = vec![];
let len = header.to_compact(&mut encoded_header);

View File

@ -3,7 +3,6 @@ mod authorization_list;
mod genesis_account;
mod header;
mod log;
mod request;
mod signature;
mod transaction;
mod trie;
@ -14,7 +13,6 @@ mod withdrawal;
mod tests {
use crate::{
alloy::{
authorization_list::Authorization,
genesis_account::{GenesisAccount, GenesisAccountRef, StorageEntries, StorageEntry},
header::{Header, HeaderExt},
transaction::{
@ -38,7 +36,6 @@ mod tests {
validate_bitflag_backwards_compat!(StorageEntries, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StorageEntry, UnusedBits::Zero);
validate_bitflag_backwards_compat!(Authorization, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(GenesisAccountRef<'_>, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(GenesisAccount, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(TxEip1559, UnusedBits::NotZero);

View File

@ -1,40 +0,0 @@
//! Native Compact codec impl for EIP-7685 requests.
use crate::Compact;
use alloy_consensus::Request;
use alloy_eips::eip7685::{Decodable7685, Encodable7685};
use alloy_primitives::Bytes;
use bytes::BufMut;
impl Compact for Request {
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: BufMut + AsMut<[u8]>,
{
let encoded: Bytes = self.encoded_7685().into();
encoded.to_compact(buf)
}
fn from_compact(buf: &[u8], _: usize) -> (Self, &[u8]) {
let (raw, buf) = Bytes::from_compact(buf, buf.len());
(Self::decode_7685(&mut raw.as_ref()).expect("invalid eip-7685 request in db"), buf)
}
}
#[cfg(test)]
mod tests {
use super::*;
use proptest::proptest;
use proptest_arbitrary_interop::arb;
proptest! {
#[test]
fn roundtrip(request in arb::<Request>()) {
let mut buf = Vec::<u8>::new();
request.to_compact(&mut buf);
let (decoded, _) = Request::from_compact(&buf, buf.len());
assert_eq!(request, decoded);
}
}
}