chore: upstreamed to alloy (#7)

* upstreamed to alloy

* upstreamed to alloy
This commit is contained in:
Soubhik Singha Mahapatra
2025-07-06 18:38:59 +05:30
committed by GitHub
parent 8da02d7f38
commit 3cbb9a90e5
9 changed files with 0 additions and 302 deletions

View File

@@ -1,77 +0,0 @@
//! Contains the `AccountChanges` struct, which represents storage, balance, nonce, code changes and
//! read for the account. All changes for a single account, grouped by field type.
//! This eliminates address redundancy across different change types.
use alloy_primitives::{Address, StorageKey};
use crate::{
balance_change::BalanceChange, code_change::CodeChange, nonce_change::NonceChange,
StorageChange, MAX_SLOTS, MAX_TXS,
};
/// This struct is used to track the changes across accounts in a block.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AccountChanges {
/// The address of the account whoose changes are stored.
pub address: Address,
/// List of storage changes for this account.
pub storage_changes: Vec<StorageChange>,
/// List of storage reads for this account.
pub storage_reads: Vec<StorageKey>,
/// List of balance changes for this account.
pub balance_changes: Vec<BalanceChange>,
/// List of nonce changes for this account.
pub nonce_changes: Vec<NonceChange>,
/// List of code changes for this account.
pub code_changes: Vec<CodeChange>,
}
impl AccountChanges {
/// Creates a new `AccountChanges` instance for the given address.
pub fn new(address: Address) -> Self {
Self {
address,
storage_changes: Vec::with_capacity(MAX_SLOTS),
storage_reads: Vec::with_capacity(MAX_SLOTS),
balance_changes: Vec::with_capacity(MAX_TXS),
nonce_changes: Vec::with_capacity(MAX_TXS),
code_changes: Vec::with_capacity(MAX_TXS),
}
}
/// Returns the address of the account.
#[inline]
pub const fn address(&self) -> Address {
self.address
}
/// Returns the storage changes for this account.
#[inline]
pub fn storage_changes(&self) -> &[StorageChange] {
&self.storage_changes
}
/// Returns the storage reads for this account.
#[inline]
pub fn storage_reads(&self) -> &[StorageKey] {
&self.storage_reads
}
/// Returns the balance changes for this account.
#[inline]
pub fn balance_changes(&self) -> &[BalanceChange] {
&self.balance_changes
}
/// Returns the nonce changes for this account.
#[inline]
pub fn nonce_changes(&self) -> &[NonceChange] {
&self.nonce_changes
}
/// Returns the code changes for this account.
#[inline]
pub fn code_changes(&self) -> &[CodeChange] {
&self.code_changes
}
}

View File

@@ -1,23 +0,0 @@
//! Contains the `BlockAccessList` struct, which represents a simple list of account changes.
use crate::{account_change::AccountChanges, MAX_ACCOUNTS};
/// This struct is used to store `account_changes` in a block.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BlockAccessList {
/// List of account changes in the block.
pub account_changes: Vec<AccountChanges>,
}
impl BlockAccessList {
/// Creates a new `BlockAccessList` instance.
pub fn new() -> Self {
Self { account_changes: Vec::with_capacity(MAX_ACCOUNTS) }
}
/// Returns the account changes in the block.
#[inline]
pub fn account_changes(&self) -> &[AccountChanges] {
&self.account_changes
}
}

View File

@@ -1,32 +0,0 @@
//! Contains the `BalanceChange` struct, which represents a post balance for an account.
//! Single balance change: `tx_index` -> `post_balance`
use alloy_primitives::TxIndex;
/// This struct is used to track the balance changes of accounts in a block.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BalanceChange {
/// The index of the transaction that caused this balance change.
pub tx_index: TxIndex,
/// The post-transaction balance of the account.
pub post_balance: u128,
}
impl BalanceChange {
/// Creates a new `BalanceChange`.
pub const fn new(tx_index: TxIndex, post_balance: u128) -> Self {
Self { tx_index, post_balance }
}
/// Returns the transaction index.
#[inline]
pub const fn tx_index(&self) -> TxIndex {
self.tx_index
}
/// Returns the post-transaction balance.
#[inline]
pub const fn post_balance(&self) -> u128 {
self.post_balance
}
}

View File

@@ -1,33 +0,0 @@
//! Contains the `CodeChange` struct, which represents a new code for an account.
//! Single code change: `tx_index` -> `new_code`
use alloy_primitives::{Bytes, TxIndex};
use crate::MAX_CODE_SIZE;
/// This struct is used to track the new codes of accounts in a block.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CodeChange {
/// The index of the transaction that caused this balance change.
pub tx_index: TxIndex,
/// The new code of the account.
pub new_code: Vec<Bytes>,
}
impl CodeChange {
/// Creates a new `CodeChange`.
pub fn new(tx_index: TxIndex) -> Self {
Self { tx_index, new_code: Vec::with_capacity(MAX_CODE_SIZE) }
}
/// Returns the transaction index.
#[inline]
pub const fn tx_index(&self) -> TxIndex {
self.tx_index
}
/// Returns the new code.
#[inline]
pub fn new_code(&self) -> &[Bytes] {
&self.new_code
}
}

View File

@@ -1,12 +0,0 @@
/// Maximum number of transactions per block.
/// Chosen to support a 630 million gas limit.
pub const MAX_TXS: usize = 30_000;
/// Maximum number of unique storage slots modified in a block.
pub const MAX_SLOTS: usize = 300_000;
/// Maximum number of unique accounts accessed in a block.
pub const MAX_ACCOUNTS: usize = 300_000;
/// Maximum contract bytecode size in bytes.
pub const MAX_CODE_SIZE: usize = 24_576;

View File

@@ -1,20 +1 @@
//! Block-level access lists for Reth.
extern crate alloc;
/// Module for handling storage changes within a block.
pub mod storage_change;
pub use storage_change::*;
/// Module for managing storage slots and their changes.
pub mod slot_change;
pub use slot_change::*;
/// Module containing constants used throughout the block access list.
pub mod constants;
pub use constants::*;
pub mod account_change;
pub mod bal;
pub mod balance_change;
pub mod code_change;
pub mod nonce_change;

View File

@@ -1,30 +0,0 @@
//! Contains the `NonceChange` struct, which represents a new nonce for an account.
//! Single code change: `tx_index` -> `new_nonce`
use alloy_primitives::TxIndex;
/// This struct is used to track the new nonce of accounts in a block.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NonceChange {
/// The index of the transaction that caused this nonce change.
pub tx_index: TxIndex,
/// The new code of the account.
pub new_nonce: u64,
}
impl NonceChange {
/// Creates a new `NonceChange`.
pub const fn new(tx_index: TxIndex, new_nonce: u64) -> Self {
Self { tx_index, new_nonce }
}
/// Returns the transaction index.
pub const fn tx_index(&self) -> TxIndex {
self.tx_index
}
/// Returns the new nonce.
pub const fn new_nonce(&self) -> u64 {
self.new_nonce
}
}

View File

@@ -1,40 +0,0 @@
use crate::{StorageChange, MAX_TXS};
use alloc::vec::Vec;
use alloy_primitives::StorageKey;
/// Represents all changes made to a single storage slot across multiple transactions.
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct SlotChanges {
/// The storage slot key being modified.
pub slot: StorageKey,
/// A list of write operations to this slot, ordered by transaction index.
pub changes: Vec<StorageChange>,
}
impl SlotChanges {
/// Creates a new `SlotChanges` instance for the given slot key.
///
/// Preallocates capacity for up to 300,000 changes.
#[inline]
pub fn new(slot: StorageKey) -> Self {
Self { slot, changes: Vec::with_capacity(MAX_TXS) }
}
/// Appends a storage change to the list.
#[inline]
pub fn push(&mut self, change: StorageChange) {
self.changes.push(change)
}
/// Returns `true` if no changes have been recorded.
#[inline]
pub fn is_empty(&self) -> bool {
self.changes.is_empty()
}
/// Returns the number of changes recorded for this slot.
#[inline]
pub fn len(&self) -> usize {
self.changes.len()
}
}

View File

@@ -1,36 +0,0 @@
use alloy_primitives::{StorageValue, TxIndex};
/// Represents a single storage write operation within a transaction.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct StorageChange {
/// Index of the transaction that performed the write.
pub tx_index: TxIndex,
/// The new value written to the storage slot.
pub new_value: StorageValue,
}
impl StorageChange {
/// Creates a new `StorageChange`.
#[inline]
pub const fn new(tx_index: TxIndex, new_value: StorageValue) -> Self {
Self { tx_index, new_value }
}
/// Returns true if the new value is zero.
#[inline]
pub fn is_zero(&self) -> bool {
self.new_value == StorageValue::ZERO
}
/// Returns true if this change was made by the given transaction.
#[inline]
pub const fn is_from_tx(&self, tx: TxIndex) -> bool {
self.tx_index == tx
}
/// Returns a copy with a different storage value.
#[inline]
pub const fn with_value(&self, value: StorageValue) -> Self {
Self { tx_index: self.tx_index, new_value: value }
}
}