Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sdk): Add InMemorySize as super trait of data primitive traits #12465

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use alloy_consensus::{BlockHeader, Transaction, TxType};
use alloy_eips::{eip4895::Withdrawal, eip7685::Requests};
use alloy_primitives::{Address, B256};

use crate::Block;
use crate::{Block, InMemorySize};

/// Abstraction for block's body.
pub trait BlockBody:
Expand All @@ -22,6 +22,7 @@ pub trait BlockBody:
+ for<'de> serde::Deserialize<'de>
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ InMemorySize
{
/// Ordered list of signed transactions as committed in block.
// todo: requires trait for signed transaction
Expand Down Expand Up @@ -93,7 +94,4 @@ pub trait BlockBody:
fn blob_versioned_hashes(&self) -> Vec<&B256> {
self.blob_versioned_hashes_iter().collect()
}

/// Calculates a heuristic for the in-memory size of the [`BlockBody`].
fn size(&self) -> usize;
}
6 changes: 2 additions & 4 deletions crates/primitives-traits/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use alloc::{fmt, vec::Vec};
use alloy_primitives::{Address, B256};
use reth_codecs::Compact;

use crate::{BlockBody, BlockHeader, FullBlockHeader};
use crate::{BlockBody, BlockHeader, FullBlockHeader, InMemorySize};

/// Helper trait that unifies all behaviour required by block to support full node operations.
pub trait FullBlock: Block<Header: Compact> + Compact {}
Expand All @@ -32,6 +32,7 @@ pub trait Block:
+ for<'a> serde::Deserialize<'a>
+ From<(Self::Header, Self::Body)>
+ Into<(Self::Header, Self::Body)>
+ InMemorySize
{
/// Header part of the block.
type Header: BlockHeader;
Expand Down Expand Up @@ -104,7 +105,4 @@ pub trait Block:
// todo: can be default impl if sealed block type is made generic over header and body and
// migrated to alloy
fn with_recovered_senders(self) -> Option<Self::BlockWithSenders<Self>>;

/// Calculates a heuristic for the in-memory size of the [`Block`].
fn size(&self) -> usize;
}
6 changes: 3 additions & 3 deletions crates/primitives-traits/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use alloy_primitives::{TxKind, B256};
use reth_codecs::Compact;
use serde::{Deserialize, Serialize};

use crate::InMemorySize;

pub mod signed;

#[allow(dead_code)]
Expand All @@ -26,6 +28,7 @@ pub trait Transaction:
+ alloy_rlp::Decodable
+ for<'de> Deserialize<'de>
+ alloy_consensus::Transaction
+ InMemorySize
+ MaybeArbitrary
{
/// Heavy operation that return signature hash over rlp encoded transaction.
Expand All @@ -45,9 +48,6 @@ pub trait Transaction:
/// This encodes the transaction _without_ the signature, and is only suitable for creating a
/// hash intended for signing.
fn encode_without_signature(&self, out: &mut dyn bytes::BufMut);

/// Calculates a heuristic for the in-memory size of the [Transaction].
fn size(&self) -> usize;
}

#[cfg(not(feature = "arbitrary"))]
Expand Down
Loading