mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: Drop reth_primitives::Log (#7651)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -374,11 +374,11 @@ pub fn random_receipt<R: Rng>(
|
||||
pub fn random_log<R: Rng>(rng: &mut R, address: Option<Address>, topics_count: Option<u8>) -> Log {
|
||||
let data_byte_count = rng.gen::<u8>() as usize;
|
||||
let topics_count = topics_count.unwrap_or_else(|| rng.gen()) as usize;
|
||||
Log {
|
||||
address: address.unwrap_or_else(|| rng.gen()),
|
||||
topics: std::iter::repeat_with(|| rng.gen()).take(topics_count).collect(),
|
||||
data: std::iter::repeat_with(|| rng.gen()).take(data_byte_count).collect::<Vec<_>>().into(),
|
||||
}
|
||||
Log::new_unchecked(
|
||||
address.unwrap_or_else(|| rng.gen()),
|
||||
std::iter::repeat_with(|| rng.gen()).take(topics_count).collect(),
|
||||
std::iter::repeat_with(|| rng.gen()).take(data_byte_count).collect::<Vec<_>>().into(),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -91,7 +91,7 @@ mod tests {
|
||||
message: GetReceipts(vec![
|
||||
hex!("00000000000000000000000000000000000000000000000000000000deadc0de").into(),
|
||||
hex!("00000000000000000000000000000000000000000000000000000000feedbeef").into(),
|
||||
])
|
||||
]),
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -109,14 +109,14 @@ mod tests {
|
||||
tx_type: TxType::Legacy,
|
||||
cumulative_gas_used: 0x1u64,
|
||||
logs: vec![
|
||||
Log {
|
||||
address: hex!("0000000000000000000000000000000000000011").into(),
|
||||
topics: vec![
|
||||
Log::new_unchecked(
|
||||
hex!("0000000000000000000000000000000000000011").into(),
|
||||
vec![
|
||||
hex!("000000000000000000000000000000000000000000000000000000000000dead").into(),
|
||||
hex!("000000000000000000000000000000000000000000000000000000000000beef").into(),
|
||||
],
|
||||
data: hex!("0100ff")[..].into(),
|
||||
},
|
||||
hex!("0100ff")[..].into(),
|
||||
),
|
||||
],
|
||||
success: false,
|
||||
#[cfg(feature = "optimism")]
|
||||
@ -148,14 +148,14 @@ mod tests {
|
||||
tx_type: TxType::Legacy,
|
||||
cumulative_gas_used: 0x1u64,
|
||||
logs: vec![
|
||||
Log {
|
||||
address: hex!("0000000000000000000000000000000000000011").into(),
|
||||
topics: vec![
|
||||
Log::new_unchecked(
|
||||
hex!("0000000000000000000000000000000000000011").into(),
|
||||
vec![
|
||||
hex!("000000000000000000000000000000000000000000000000000000000000dead").into(),
|
||||
hex!("000000000000000000000000000000000000000000000000000000000000beef").into(),
|
||||
],
|
||||
data: hex!("0100ff")[..].into(),
|
||||
},
|
||||
hex!("0100ff")[..].into(),
|
||||
),
|
||||
],
|
||||
success: false,
|
||||
#[cfg(feature = "optimism")]
|
||||
|
||||
@ -1,41 +1,7 @@
|
||||
use crate::{Address, Bloom, Bytes, B256};
|
||||
use alloy_primitives::Log as AlloyLog;
|
||||
use alloy_rlp::{RlpDecodable, RlpEncodable};
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use crate::Bloom;
|
||||
|
||||
/// Ethereum Log
|
||||
#[main_codec(rlp)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable, Default)]
|
||||
pub struct Log {
|
||||
/// Contract that emitted this log.
|
||||
pub address: Address,
|
||||
/// Topics of the log. The number of logs depend on what `LOG` opcode is used.
|
||||
#[cfg_attr(
|
||||
any(test, feature = "arbitrary"),
|
||||
proptest(
|
||||
strategy = "proptest::collection::vec(proptest::arbitrary::any::<B256>(), 0..=5)"
|
||||
)
|
||||
)]
|
||||
pub topics: Vec<B256>,
|
||||
/// Arbitrary length data.
|
||||
pub data: Bytes,
|
||||
}
|
||||
|
||||
impl From<AlloyLog> for Log {
|
||||
fn from(mut log: AlloyLog) -> Self {
|
||||
Self {
|
||||
address: log.address,
|
||||
topics: std::mem::take(log.data.topics_mut_unchecked()),
|
||||
data: log.data.data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Log> for AlloyLog {
|
||||
fn from(log: Log) -> AlloyLog {
|
||||
AlloyLog::new_unchecked(log.address, log.topics, log.data)
|
||||
}
|
||||
}
|
||||
/// Re-export `Log` from `alloy_primitives`.
|
||||
pub use alloy_primitives::Log;
|
||||
|
||||
/// Calculate receipt logs bloom.
|
||||
pub fn logs_bloom<'a, It>(logs: It) -> Bloom
|
||||
@ -45,7 +11,7 @@ where
|
||||
let mut bloom = Bloom::ZERO;
|
||||
for log in logs {
|
||||
bloom.m3_2048(log.address.as_slice());
|
||||
for topic in &log.topics {
|
||||
for topic in log.topics() {
|
||||
bloom.m3_2048(topic.as_slice());
|
||||
}
|
||||
}
|
||||
@ -54,8 +20,45 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use alloy_primitives::{Address, Bytes, Log as AlloyLog, B256};
|
||||
use alloy_rlp::{RlpDecodable, RlpEncodable};
|
||||
use proptest::proptest;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
|
||||
/// This type is kept for compatibility tests after the codec support was added to
|
||||
/// alloy-primitives Log type natively
|
||||
#[main_codec(rlp)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable, Default)]
|
||||
struct Log {
|
||||
/// Contract that emitted this log.
|
||||
address: Address,
|
||||
/// Topics of the log. The number of logs depend on what `LOG` opcode is used.
|
||||
#[cfg_attr(
|
||||
any(test, feature = "arbitrary"),
|
||||
proptest(
|
||||
strategy = "proptest::collection::vec(proptest::arbitrary::any::<B256>(), 0..=5)"
|
||||
)
|
||||
)]
|
||||
topics: Vec<B256>,
|
||||
/// Arbitrary length data.
|
||||
data: Bytes,
|
||||
}
|
||||
|
||||
impl From<AlloyLog> for Log {
|
||||
fn from(mut log: AlloyLog) -> Self {
|
||||
Self {
|
||||
address: log.address,
|
||||
topics: std::mem::take(log.data.topics_mut_unchecked()),
|
||||
data: log.data.data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Log> for AlloyLog {
|
||||
fn from(log: Log) -> AlloyLog {
|
||||
AlloyLog::new_unchecked(log.address, log.topics, log.data)
|
||||
}
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
@ -70,7 +73,8 @@ mod tests {
|
||||
// Create alloy_log from log and then convert it to buffer and compare compacted_alloy_log and compacted_log
|
||||
let alloy_log = AlloyLog::new_unchecked(log.address, log.topics, log.data);
|
||||
let mut compacted_alloy_log = Vec::<u8>::new();
|
||||
let _len = alloy_log.to_compact(&mut compacted_alloy_log);
|
||||
let alloy_len = alloy_log.to_compact(&mut compacted_alloy_log);
|
||||
assert_eq!(len, alloy_len);
|
||||
assert_eq!(compacted_log, compacted_alloy_log);
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ mod tests {
|
||||
bloom, constants::EMPTY_ROOT_HASH, hex_literal::hex, Block, GenesisAccount, Log, TxType,
|
||||
GOERLI, HOLESKY, MAINNET, SEPOLIA,
|
||||
};
|
||||
use alloy_primitives::b256;
|
||||
use alloy_primitives::{b256, LogData};
|
||||
use alloy_rlp::Decodable;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -338,32 +338,36 @@ mod tests {
|
||||
logs: vec![
|
||||
Log {
|
||||
address: hex!("ddb6dcce6b794415145eb5caa6cd335aeda9c272").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked(
|
||||
vec![
|
||||
b256!("c3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62"),
|
||||
b256!("000000000000000000000000c498902843af527e674846bb7edefa8ad62b8fb9"),
|
||||
b256!("000000000000000000000000c498902843af527e674846bb7edefa8ad62b8fb9"),
|
||||
b256!("0000000000000000000000000000000000000000000000000000000000000000"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001")),
|
||||
Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001"))
|
||||
)
|
||||
},
|
||||
Log {
|
||||
address: hex!("ddb6dcce6b794415145eb5caa6cd335aeda9c272").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked(
|
||||
vec![
|
||||
b256!("c3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62"),
|
||||
b256!("000000000000000000000000c498902843af527e674846bb7edefa8ad62b8fb9"),
|
||||
b256!("0000000000000000000000000000000000000000000000000000000000000000"),
|
||||
b256!("000000000000000000000000c498902843af527e674846bb7edefa8ad62b8fb9"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001")),
|
||||
Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001"))
|
||||
)
|
||||
},
|
||||
Log {
|
||||
address: hex!("ddb6dcce6b794415145eb5caa6cd335aeda9c272").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked(
|
||||
vec![
|
||||
b256!("0eb774bb9698a73583fe07b6972cf2dcc08d1d97581a22861f45feb86b395820"),
|
||||
b256!("000000000000000000000000c498902843af527e674846bb7edefa8ad62b8fb9"),
|
||||
b256!("000000000000000000000000c498902843af527e674846bb7edefa8ad62b8fb9"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000000000000000003")),
|
||||
], Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000000000000000003")))
|
||||
},
|
||||
],
|
||||
#[cfg(feature = "optimism")]
|
||||
@ -382,32 +386,32 @@ mod tests {
|
||||
logs: vec![
|
||||
Log {
|
||||
address: hex!("ddb6dcce6b794415145eb5caa6cd335aeda9c272").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked(vec![
|
||||
b256!("c3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62"),
|
||||
b256!("0000000000000000000000009d521a04bee134ff8136d2ec957e5bc8c50394ec"),
|
||||
b256!("0000000000000000000000009d521a04bee134ff8136d2ec957e5bc8c50394ec"),
|
||||
b256!("0000000000000000000000000000000000000000000000000000000000000000"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001")),
|
||||
Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001")))
|
||||
},
|
||||
Log {
|
||||
address: hex!("ddb6dcce6b794415145eb5caa6cd335aeda9c272").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked(vec![
|
||||
b256!("c3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62"),
|
||||
b256!("0000000000000000000000009d521a04bee134ff8136d2ec957e5bc8c50394ec"),
|
||||
b256!("0000000000000000000000000000000000000000000000000000000000000000"),
|
||||
b256!("0000000000000000000000009d521a04bee134ff8136d2ec957e5bc8c50394ec"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001")),
|
||||
Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001")))
|
||||
},
|
||||
Log {
|
||||
address: hex!("ddb6dcce6b794415145eb5caa6cd335aeda9c272").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked(vec![
|
||||
b256!("0eb774bb9698a73583fe07b6972cf2dcc08d1d97581a22861f45feb86b395820"),
|
||||
b256!("0000000000000000000000009d521a04bee134ff8136d2ec957e5bc8c50394ec"),
|
||||
b256!("0000000000000000000000009d521a04bee134ff8136d2ec957e5bc8c50394ec"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000000000000000003")),
|
||||
Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000000000000000003")))
|
||||
},
|
||||
],
|
||||
#[cfg(feature = "optimism")]
|
||||
@ -426,62 +430,62 @@ mod tests {
|
||||
logs: vec![
|
||||
Log {
|
||||
address: hex!("4200000000000000000000000000000000000006").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"),
|
||||
b256!("000000000000000000000000c3feb4ef4c2a5af77add15c95bd98f6b43640cc8"),
|
||||
b256!("0000000000000000000000002992607c1614484fe6d865088e5c048f0650afd4"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000018de76816d8000")),
|
||||
Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000018de76816d8000")))
|
||||
},
|
||||
Log {
|
||||
address: hex!("cf8e7e6b26f407dee615fc4db18bf829e7aa8c09").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"),
|
||||
b256!("0000000000000000000000002992607c1614484fe6d865088e5c048f0650afd4"),
|
||||
b256!("0000000000000000000000008dbffe4c8bf3caf5deae3a99b50cfcf3648cbc09"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("000000000000000000000000000000000000000000000002d24d8e9ac1aa79e2")),
|
||||
Bytes::from_static(&hex!("000000000000000000000000000000000000000000000002d24d8e9ac1aa79e2")))
|
||||
},
|
||||
Log {
|
||||
address: hex!("2992607c1614484fe6d865088e5c048f0650afd4").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("000000000000000000000000000000000000000000000009bd50642785c15736000000000000000000000000000000000000000000011bb7ac324f724a29bbbf")),
|
||||
Bytes::from_static(&hex!("000000000000000000000000000000000000000000000009bd50642785c15736000000000000000000000000000000000000000000011bb7ac324f724a29bbbf")))
|
||||
},
|
||||
Log {
|
||||
address: hex!("2992607c1614484fe6d865088e5c048f0650afd4").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("d78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822"),
|
||||
b256!("00000000000000000000000029843613c7211d014f5dd5718cf32bcd314914cb"),
|
||||
b256!("0000000000000000000000008dbffe4c8bf3caf5deae3a99b50cfcf3648cbc09"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000018de76816d800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d24d8e9ac1aa79e2")),
|
||||
Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000018de76816d800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d24d8e9ac1aa79e2")))
|
||||
},
|
||||
Log {
|
||||
address: hex!("6d0f8d488b669aa9ba2d0f0b7b75a88bf5051cd3").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"),
|
||||
b256!("0000000000000000000000008dbffe4c8bf3caf5deae3a99b50cfcf3648cbc09"),
|
||||
b256!("000000000000000000000000c3feb4ef4c2a5af77add15c95bd98f6b43640cc8"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000014bc73062aea8093")),
|
||||
Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000014bc73062aea8093")))
|
||||
},
|
||||
Log {
|
||||
address: hex!("8dbffe4c8bf3caf5deae3a99b50cfcf3648cbc09").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("00000000000000000000000000000000000000000000002f122cfadc1ca82a35000000000000000000000000000000000000000000000665879dc0609945d6d1")),
|
||||
Bytes::from_static(&hex!("00000000000000000000000000000000000000000000002f122cfadc1ca82a35000000000000000000000000000000000000000000000665879dc0609945d6d1")))
|
||||
},
|
||||
Log {
|
||||
address: hex!("8dbffe4c8bf3caf5deae3a99b50cfcf3648cbc09").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("d78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822"),
|
||||
b256!("00000000000000000000000029843613c7211d014f5dd5718cf32bcd314914cb"),
|
||||
b256!("000000000000000000000000c3feb4ef4c2a5af77add15c95bd98f6b43640cc8"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d24d8e9ac1aa79e200000000000000000000000000000000000000000000000014bc73062aea80930000000000000000000000000000000000000000000000000000000000000000")),
|
||||
Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d24d8e9ac1aa79e200000000000000000000000000000000000000000000000014bc73062aea80930000000000000000000000000000000000000000000000000000000000000000")))
|
||||
},
|
||||
],
|
||||
#[cfg(feature = "optimism")]
|
||||
@ -500,32 +504,32 @@ mod tests {
|
||||
logs: vec![
|
||||
Log {
|
||||
address: hex!("ac6564f3718837caadd42eed742d75c12b90a052").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"),
|
||||
b256!("0000000000000000000000000000000000000000000000000000000000000000"),
|
||||
b256!("000000000000000000000000a4fa7f3fbf0677f254ebdb1646146864c305b76e"),
|
||||
b256!("000000000000000000000000000000000000000000000000000000000011a1d3"),
|
||||
],
|
||||
data: Default::default(),
|
||||
Default::default())
|
||||
},
|
||||
Log {
|
||||
address: hex!("ac6564f3718837caadd42eed742d75c12b90a052").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("9d89e36eadf856db0ad9ffb5a569e07f95634dddd9501141ecf04820484ad0dc"),
|
||||
b256!("000000000000000000000000a4fa7f3fbf0677f254ebdb1646146864c305b76e"),
|
||||
b256!("000000000000000000000000000000000000000000000000000000000011a1d3"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000037697066733a2f2f516d515141646b33736538396b47716577395256567a316b68643548375562476d4d4a485a62566f386a6d346f4a2f30000000000000000000")),
|
||||
Bytes::from_static(&hex!("00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000037697066733a2f2f516d515141646b33736538396b47716577395256567a316b68643548375562476d4d4a485a62566f386a6d346f4a2f30000000000000000000")))
|
||||
},
|
||||
Log {
|
||||
address: hex!("ac6564f3718837caadd42eed742d75c12b90a052").into(),
|
||||
topics: vec![
|
||||
data: LogData::new_unchecked( vec![
|
||||
b256!("110d160a1bedeea919a88fbc4b2a9fb61b7e664084391b6ca2740db66fef80fe"),
|
||||
b256!("00000000000000000000000084d47f6eea8f8d87910448325519d1bb45c2972a"),
|
||||
b256!("000000000000000000000000a4fa7f3fbf0677f254ebdb1646146864c305b76e"),
|
||||
b256!("000000000000000000000000000000000000000000000000000000000011a1d3"),
|
||||
],
|
||||
data: Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000a4fa7f3fbf0677f254ebdb1646146864c305b76e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007717500762343034303661353035646234633961386163316433306335633332303265370000000000000000000000000000000000000000000000000000000000000037697066733a2f2f516d515141646b33736538396b47716577395256567a316b68643548375562476d4d4a485a62566f386a6d346f4a2f30000000000000000000")),
|
||||
Bytes::from_static(&hex!("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000a4fa7f3fbf0677f254ebdb1646146864c305b76e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007717500762343034303661353035646234633961386163316433306335633332303265370000000000000000000000000000000000000000000000000000000000000037697066733a2f2f516d515141646b33736538396b47716577395256567a316b68643548375562476d4d4a485a62566f386a6d346f4a2f30000000000000000000")))
|
||||
},
|
||||
],
|
||||
#[cfg(feature = "optimism")]
|
||||
@ -544,7 +548,10 @@ mod tests {
|
||||
#[cfg(feature = "optimism")]
|
||||
#[test]
|
||||
fn check_receipt_root_optimism() {
|
||||
let logs = vec![Log { address: Address::ZERO, topics: vec![], data: Default::default() }];
|
||||
let logs = vec![Log {
|
||||
address: Address::ZERO,
|
||||
data: LogData::new_unchecked(vec![], Default::default()),
|
||||
}];
|
||||
let bloom = bloom!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001");
|
||||
let receipt = ReceiptWithBloom {
|
||||
receipt: Receipt {
|
||||
@ -565,7 +572,10 @@ mod tests {
|
||||
#[cfg(not(feature = "optimism"))]
|
||||
#[test]
|
||||
fn check_receipt_root_optimism() {
|
||||
let logs = vec![Log { address: Address::ZERO, topics: vec![], data: Default::default() }];
|
||||
let logs = vec![Log {
|
||||
address: Address::ZERO,
|
||||
data: LogData::new_unchecked(vec![], Default::default()),
|
||||
}];
|
||||
let bloom = bloom!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001");
|
||||
let receipt = ReceiptWithBloom {
|
||||
receipt: Receipt {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#[cfg(feature = "zstd-codec")]
|
||||
use crate::compression::{RECEIPT_COMPRESSOR, RECEIPT_DECOMPRESSOR};
|
||||
use crate::{logs_bloom, Bloom, Bytes, Log, PruneSegmentError, TxType, B256};
|
||||
use crate::{logs_bloom, Bloom, Bytes, PruneSegmentError, TxType, B256};
|
||||
use alloy_primitives::Log;
|
||||
use alloy_rlp::{length_of_length, Decodable, Encodable};
|
||||
use bytes::{Buf, BufMut};
|
||||
#[cfg(any(test, feature = "arbitrary"))]
|
||||
@ -118,13 +119,15 @@ impl Receipts {
|
||||
|
||||
/// Retrieves gas spent by transactions as a vector of tuples (transaction index, gas used).
|
||||
pub fn gas_spent_by_tx(&self) -> Result<Vec<(u64, u64)>, PruneSegmentError> {
|
||||
let Some(block_r) = self.last() else { return Ok(vec![]) };
|
||||
let Some(block_r) = self.last() else {
|
||||
return Ok(vec![]);
|
||||
};
|
||||
let mut out = Vec::with_capacity(block_r.len());
|
||||
for (id, tx_r) in block_r.iter().enumerate() {
|
||||
if let Some(receipt) = tx_r.as_ref() {
|
||||
out.push((id as u64, receipt.cumulative_gas_used));
|
||||
} else {
|
||||
return Err(PruneSegmentError::ReceiptsPruned)
|
||||
return Err(PruneSegmentError::ReceiptsPruned);
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
@ -308,7 +311,7 @@ impl ReceiptWithBloom {
|
||||
let b = &mut &**buf;
|
||||
let rlp_head = alloy_rlp::Header::decode(b)?;
|
||||
if !rlp_head.list {
|
||||
return Err(alloy_rlp::Error::UnexpectedString)
|
||||
return Err(alloy_rlp::Error::UnexpectedString);
|
||||
}
|
||||
let started_len = b.len();
|
||||
|
||||
@ -353,7 +356,7 @@ impl ReceiptWithBloom {
|
||||
return Err(alloy_rlp::Error::ListLengthMismatch {
|
||||
expected: rlp_head.payload_length,
|
||||
got: consumed,
|
||||
})
|
||||
});
|
||||
}
|
||||
*buf = *b;
|
||||
Ok(this)
|
||||
@ -506,7 +509,7 @@ impl<'a> ReceiptWithBloomEncoder<'a> {
|
||||
fn encode_inner(&self, out: &mut dyn BufMut, with_header: bool) {
|
||||
if matches!(self.receipt.tx_type, TxType::Legacy) {
|
||||
self.encode_fields(out);
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
let mut payload = Vec::new();
|
||||
@ -578,14 +581,14 @@ mod tests {
|
||||
receipt: Receipt {
|
||||
tx_type: TxType::Legacy,
|
||||
cumulative_gas_used: 0x1u64,
|
||||
logs: vec![Log {
|
||||
address: address!("0000000000000000000000000000000000000011"),
|
||||
topics: vec![
|
||||
logs: vec![Log::new_unchecked(
|
||||
address!("0000000000000000000000000000000000000011"),
|
||||
vec![
|
||||
b256!("000000000000000000000000000000000000000000000000000000000000dead"),
|
||||
b256!("000000000000000000000000000000000000000000000000000000000000beef"),
|
||||
],
|
||||
data: bytes!("0100ff"),
|
||||
}],
|
||||
bytes!("0100ff"),
|
||||
)],
|
||||
success: false,
|
||||
#[cfg(feature = "optimism")]
|
||||
deposit_nonce: None,
|
||||
@ -612,14 +615,14 @@ mod tests {
|
||||
receipt: Receipt {
|
||||
tx_type: TxType::Legacy,
|
||||
cumulative_gas_used: 0x1u64,
|
||||
logs: vec![Log {
|
||||
address: address!("0000000000000000000000000000000000000011"),
|
||||
topics: vec![
|
||||
logs: vec![Log::new_unchecked(
|
||||
address!("0000000000000000000000000000000000000011"),
|
||||
vec![
|
||||
b256!("000000000000000000000000000000000000000000000000000000000000dead"),
|
||||
b256!("000000000000000000000000000000000000000000000000000000000000beef"),
|
||||
],
|
||||
data: bytes!("0100ff"),
|
||||
}],
|
||||
bytes!("0100ff"),
|
||||
)],
|
||||
success: false,
|
||||
#[cfg(feature = "optimism")]
|
||||
deposit_nonce: None,
|
||||
@ -692,20 +695,16 @@ mod tests {
|
||||
success: true,
|
||||
tx_type: TxType::Legacy,
|
||||
logs: vec![
|
||||
Log {
|
||||
address: address!("4bf56695415f725e43c3e04354b604bcfb6dfb6e"),
|
||||
topics: vec![b256!(
|
||||
"c69dc3d7ebff79e41f525be431d5cd3cc08f80eaf0f7819054a726eeb7086eb9"
|
||||
)],
|
||||
data: Bytes::from(vec![1; 0xffffff]),
|
||||
},
|
||||
Log {
|
||||
address: address!("faca325c86bf9c2d5b413cd7b90b209be92229c2"),
|
||||
topics: vec![b256!(
|
||||
"8cca58667b1e9ffa004720ac99a3d61a138181963b294d270d91c53d36402ae2"
|
||||
)],
|
||||
data: Bytes::from(vec![1; 0xffffff]),
|
||||
},
|
||||
Log::new_unchecked(
|
||||
address!("4bf56695415f725e43c3e04354b604bcfb6dfb6e"),
|
||||
vec![b256!("c69dc3d7ebff79e41f525be431d5cd3cc08f80eaf0f7819054a726eeb7086eb9")],
|
||||
Bytes::from(vec![1; 0xffffff]),
|
||||
),
|
||||
Log::new_unchecked(
|
||||
address!("faca325c86bf9c2d5b413cd7b90b209be92229c2"),
|
||||
vec![b256!("8cca58667b1e9ffa004720ac99a3d61a138181963b294d270d91c53d36402ae2")],
|
||||
Bytes::from(vec![1; 0xffffff]),
|
||||
),
|
||||
],
|
||||
#[cfg(feature = "optimism")]
|
||||
deposit_nonce: None,
|
||||
|
||||
@ -1,19 +1,9 @@
|
||||
use crate::{
|
||||
revm_primitives::{AccountInfo, Log},
|
||||
Account, Address, Log as RethLog, TransactionKind, KECCAK_EMPTY, U256,
|
||||
};
|
||||
use crate::{revm_primitives::AccountInfo, Account, Address, TransactionKind, KECCAK_EMPTY, U256};
|
||||
use revm::{
|
||||
interpreter::gas::validate_initial_tx_gas,
|
||||
primitives::{MergeSpec, ShanghaiSpec},
|
||||
};
|
||||
|
||||
/// Check equality between Revm and Reth `Log`s.
|
||||
pub fn is_log_equal(revm_log: &Log, reth_log: &RethLog) -> bool {
|
||||
revm_log.address == reth_log.address &&
|
||||
revm_log.data.data == reth_log.data &&
|
||||
revm_log.topics() == reth_log.topics
|
||||
}
|
||||
|
||||
/// Converts a Revm [`AccountInfo`] into a Reth [`Account`].
|
||||
///
|
||||
/// Sets `bytecode_hash` to `None` if `code_hash` is [`KECCAK_EMPTY`].
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#[inline]
|
||||
pub fn from_primitive_log(log: reth_primitives::Log) -> reth_rpc_types::Log {
|
||||
reth_rpc_types::Log {
|
||||
inner: log.into(),
|
||||
inner: log,
|
||||
block_hash: None,
|
||||
block_number: None,
|
||||
block_timestamp: None,
|
||||
@ -14,9 +14,3 @@ pub fn from_primitive_log(log: reth_primitives::Log) -> reth_rpc_types::Log {
|
||||
removed: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts from a [reth_rpc_types::Log] to a [reth_primitives::Log]
|
||||
#[inline]
|
||||
pub fn to_primitive_log(log: reth_rpc_types::Log) -> reth_primitives::Log {
|
||||
log.inner.into()
|
||||
}
|
||||
|
||||
@ -1707,7 +1707,7 @@ pub(crate) fn build_transaction_receipt_with_block_receipts(
|
||||
let mut logs = Vec::with_capacity(receipt.logs.len());
|
||||
for (tx_log_idx, log) in receipt.logs.into_iter().enumerate() {
|
||||
let rpclog = Log {
|
||||
inner: log.into(),
|
||||
inner: log,
|
||||
block_hash: Some(meta.block_hash),
|
||||
block_number: Some(meta.block_number),
|
||||
block_timestamp: Some(meta.timestamp),
|
||||
|
||||
@ -22,7 +22,7 @@ where
|
||||
for log in receipt.logs.iter() {
|
||||
if log_matches_filter(block_num_hash, log, filter) {
|
||||
let log = Log {
|
||||
inner: log.clone().into(),
|
||||
inner: log.clone(),
|
||||
block_hash: Some(block_num_hash.hash),
|
||||
block_number: Some(block_num_hash.number),
|
||||
transaction_hash: Some(tx_hash),
|
||||
@ -90,7 +90,7 @@ pub(crate) fn append_matching_block_logs(
|
||||
}
|
||||
|
||||
let log = Log {
|
||||
inner: log.clone().into(),
|
||||
inner: log.clone(),
|
||||
block_hash: Some(block_num_hash.hash),
|
||||
block_number: Some(block_num_hash.number),
|
||||
transaction_hash,
|
||||
@ -118,7 +118,7 @@ pub(crate) fn log_matches_filter(
|
||||
(!params.filter_block_range(block.number) ||
|
||||
!params.filter_block_hash(block.hash) ||
|
||||
!params.filter_address(&log.address) ||
|
||||
!params.filter_topics(&log.topics))
|
||||
!params.filter_topics(log.topics()))
|
||||
{
|
||||
return false
|
||||
}
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
//! Dummy blocks and data for tests
|
||||
use crate::{BundleStateWithReceipts, DatabaseProviderRW};
|
||||
use alloy_primitives::Log;
|
||||
use alloy_rlp::Decodable;
|
||||
use reth_db::{database::Database, models::StoredBlockBodyIndices, tables};
|
||||
use reth_primitives::{
|
||||
b256,
|
||||
alloy_primitives, b256,
|
||||
hex_literal::hex,
|
||||
proofs::{state_root_unhashed, storage_root_unhashed},
|
||||
revm::compat::into_reth_acc,
|
||||
Address, BlockNumber, Bytes, Header, Log, Receipt, Receipts, SealedBlock,
|
||||
SealedBlockWithSenders, TxType, Withdrawal, Withdrawals, B256, U256,
|
||||
Address, BlockNumber, Bytes, Header, Receipt, Receipts, SealedBlock, SealedBlockWithSenders,
|
||||
TxType, Withdrawal, Withdrawals, B256, U256,
|
||||
};
|
||||
use revm::{
|
||||
db::BundleState,
|
||||
@ -150,11 +151,11 @@ fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BundleStateWithReceip
|
||||
tx_type: TxType::Eip2930,
|
||||
success: true,
|
||||
cumulative_gas_used: 300,
|
||||
logs: vec![Log {
|
||||
address: Address::new([0x60; 20]),
|
||||
topics: vec![B256::with_last_byte(1), B256::with_last_byte(2)],
|
||||
data: Bytes::default(),
|
||||
}],
|
||||
logs: vec![Log::new_unchecked(
|
||||
Address::new([0x60; 20]),
|
||||
vec![B256::with_last_byte(1), B256::with_last_byte(2)],
|
||||
Bytes::default(),
|
||||
)],
|
||||
#[cfg(feature = "optimism")]
|
||||
deposit_nonce: None,
|
||||
#[cfg(feature = "optimism")]
|
||||
@ -208,11 +209,11 @@ fn block2(
|
||||
tx_type: TxType::Eip1559,
|
||||
success: false,
|
||||
cumulative_gas_used: 400,
|
||||
logs: vec![Log {
|
||||
address: Address::new([0x61; 20]),
|
||||
topics: vec![B256::with_last_byte(3), B256::with_last_byte(4)],
|
||||
data: Bytes::default(),
|
||||
}],
|
||||
logs: vec![Log::new_unchecked(
|
||||
Address::new([0x61; 20]),
|
||||
vec![B256::with_last_byte(3), B256::with_last_byte(4)],
|
||||
Bytes::default(),
|
||||
)],
|
||||
#[cfg(feature = "optimism")]
|
||||
deposit_nonce: None,
|
||||
#[cfg(feature = "optimism")]
|
||||
@ -276,11 +277,11 @@ fn block3(
|
||||
tx_type: TxType::Eip1559,
|
||||
success: true,
|
||||
cumulative_gas_used: 400,
|
||||
logs: vec![Log {
|
||||
address: Address::new([0x61; 20]),
|
||||
topics: vec![B256::with_last_byte(3), B256::with_last_byte(4)],
|
||||
data: Bytes::default(),
|
||||
}],
|
||||
logs: vec![Log::new_unchecked(
|
||||
Address::new([0x61; 20]),
|
||||
vec![B256::with_last_byte(3), B256::with_last_byte(4)],
|
||||
Bytes::default(),
|
||||
)],
|
||||
#[cfg(feature = "optimism")]
|
||||
deposit_nonce: None,
|
||||
#[cfg(feature = "optimism")]
|
||||
@ -365,11 +366,11 @@ fn block4(
|
||||
tx_type: TxType::Eip1559,
|
||||
success: true,
|
||||
cumulative_gas_used: 400,
|
||||
logs: vec![Log {
|
||||
address: Address::new([0x61; 20]),
|
||||
topics: vec![B256::with_last_byte(3), B256::with_last_byte(4)],
|
||||
data: Bytes::default(),
|
||||
}],
|
||||
logs: vec![Log::new_unchecked(
|
||||
Address::new([0x61; 20]),
|
||||
vec![B256::with_last_byte(3), B256::with_last_byte(4)],
|
||||
Bytes::default(),
|
||||
)],
|
||||
#[cfg(feature = "optimism")]
|
||||
deposit_nonce: None,
|
||||
#[cfg(feature = "optimism")]
|
||||
@ -449,11 +450,11 @@ fn block5(
|
||||
tx_type: TxType::Eip1559,
|
||||
success: true,
|
||||
cumulative_gas_used: 400,
|
||||
logs: vec![Log {
|
||||
address: Address::new([0x61; 20]),
|
||||
topics: vec![B256::with_last_byte(3), B256::with_last_byte(4)],
|
||||
data: Bytes::default(),
|
||||
}],
|
||||
logs: vec![Log::new_unchecked(
|
||||
Address::new([0x61; 20]),
|
||||
vec![B256::with_last_byte(3), B256::with_last_byte(4)],
|
||||
Bytes::default(),
|
||||
)],
|
||||
#[cfg(feature = "optimism")]
|
||||
deposit_nonce: None,
|
||||
#[cfg(feature = "optimism")]
|
||||
|
||||
@ -201,7 +201,7 @@ fn receipts_provider_example<T: ReceiptProvider + TransactionsProvider + HeaderP
|
||||
let receipts = provider.receipt(header_num)?.ok_or(eyre::eyre!("receipt not found"))?;
|
||||
for log in &receipts.logs {
|
||||
if filter_params.filter_address(&log.address) &&
|
||||
filter_params.filter_topics(&log.topics)
|
||||
filter_params.filter_topics(log.topics())
|
||||
{
|
||||
// Do something with the log e.g. decode it.
|
||||
println!("Matching log found! {log:?}")
|
||||
|
||||
@ -215,7 +215,7 @@ fn decode_chain_into_events(
|
||||
.flat_map(|(block, tx, receipt)| receipt.logs.iter().map(move |log| (block, tx, log)))
|
||||
// Decode and filter bridge events
|
||||
.filter_map(|(block, tx, log)| {
|
||||
L1StandardBridgeEvents::decode_raw_log(&log.topics, &log.data, true)
|
||||
L1StandardBridgeEvents::decode_raw_log(log.topics(), &log.data.data, true)
|
||||
.ok()
|
||||
.map(|event| (block, tx, log, event))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user