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: releax on canonical state change #13392

Merged
merged 1 commit into from
Dec 13, 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
30 changes: 17 additions & 13 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,6 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use crate::{identifier::TransactionId, pool::PoolInner};
use alloy_eips::eip4844::{BlobAndProofV1, BlobTransactionSidecar};
use alloy_primitives::{Address, TxHash, B256, U256};
use aquamarine as _;
use reth_eth_wire_types::HandleMempoolData;
use reth_execution_types::ChangedAccount;
use reth_primitives::RecoveredTx;
use reth_storage_api::StateProviderFactory;
use std::{collections::HashSet, sync::Arc};
use tokio::sync::mpsc::Receiver;
use tracing::{instrument, trace};

pub use crate::{
blobstore::{BlobStore, BlobStoreError},
config::{
Expand All @@ -182,6 +170,18 @@ pub use crate::{
TransactionValidator, ValidPoolTransaction,
},
};
use crate::{identifier::TransactionId, pool::PoolInner};
use alloy_eips::eip4844::{BlobAndProofV1, BlobTransactionSidecar};
use alloy_primitives::{Address, TxHash, B256, U256};
use aquamarine as _;
use reth_eth_wire_types::HandleMempoolData;
use reth_execution_types::ChangedAccount;
use reth_primitives::RecoveredTx;
use reth_primitives_traits::{BlockBody, BlockHeader};
use reth_storage_api::StateProviderFactory;
use std::{collections::HashSet, sync::Arc};
use tokio::sync::mpsc::Receiver;
use tracing::{instrument, trace};

pub mod error;
pub mod maintain;
Expand Down Expand Up @@ -614,7 +614,11 @@ where
self.pool.set_block_info(info)
}

fn on_canonical_state_change(&self, update: CanonicalStateUpdate<'_>) {
fn on_canonical_state_change<H, B>(&self, update: CanonicalStateUpdate<'_, H, B>)
where
H: BlockHeader,
B: BlockBody,
{
self.pool.on_canonical_state_change(update);
}

Expand Down
7 changes: 6 additions & 1 deletion crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub use events::{FullTransactionEvent, TransactionEvent};
pub use listener::{AllTransactionsEvents, TransactionEvents};
pub use parked::{BasefeeOrd, ParkedOrd, ParkedPool, QueuedOrd};
pub use pending::PendingPool;
use reth_primitives_traits::{BlockBody, BlockHeader};

mod best;
mod blob;
Expand Down Expand Up @@ -378,7 +379,11 @@ where
}

/// Updates the entire pool after a new block was executed.
pub fn on_canonical_state_change(&self, update: CanonicalStateUpdate<'_>) {
pub fn on_canonical_state_change<H, B>(&self, update: CanonicalStateUpdate<'_, H, B>)
where
H: BlockHeader,
B: BlockBody,
{
trace!(target: "txpool", ?update, "updating pool on canonical state change");

let block_info = update.block_info();
Expand Down
29 changes: 19 additions & 10 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};
use alloy_consensus::{
constants::{EIP1559_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID},
Transaction as _, Typed2718,
BlockHeader, Transaction as _, Typed2718,
};
use alloy_eips::{
eip2718::Encodable2718,
Expand All @@ -24,7 +24,7 @@ use reth_primitives::{
PooledTransaction, PooledTransactionsElementEcRecovered, RecoveredTx, SealedBlock, Transaction,
TransactionSigned,
};
use reth_primitives_traits::SignedTransaction;
use reth_primitives_traits::{BlockBody, SignedTransaction};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -517,7 +517,10 @@ pub trait TransactionPoolExt: TransactionPool {
/// sidecar must not be removed from the blob store. Only after a blob transaction is
/// finalized, its sidecar is removed from the blob store. This ensures that in case of a reorg,
/// the sidecar is still available.
fn on_canonical_state_change(&self, update: CanonicalStateUpdate<'_>);
fn on_canonical_state_change<H, B>(&self, update: CanonicalStateUpdate<'_, H, B>)
where
H: reth_primitives_traits::BlockHeader,
B: BlockBody;

/// Updates the accounts in the pool
fn update_accounts(&self, accounts: Vec<ChangedAccount>);
Expand Down Expand Up @@ -717,9 +720,9 @@ pub enum PoolUpdateKind {
///
/// This is used to update the pool state accordingly.
#[derive(Clone, Debug)]
pub struct CanonicalStateUpdate<'a> {
pub struct CanonicalStateUpdate<'a, H, B> {
/// Hash of the tip block.
pub new_tip: &'a SealedBlock,
pub new_tip: &'a SealedBlock<H, B>,
/// EIP-1559 Base fee of the _next_ (pending) block
///
/// The base fee of a block depends on the utilization of the last block and its base fee.
Expand All @@ -736,10 +739,13 @@ pub struct CanonicalStateUpdate<'a> {
pub update_kind: PoolUpdateKind,
}

impl CanonicalStateUpdate<'_> {
impl<H, B> CanonicalStateUpdate<'_, H, B>
where
H: BlockHeader,
{
/// Returns the number of the tip block.
pub fn number(&self) -> u64 {
self.new_tip.number
self.new_tip.number()
}

/// Returns the hash of the tip block.
Expand All @@ -749,13 +755,13 @@ impl CanonicalStateUpdate<'_> {

/// Timestamp of the latest chain update
pub fn timestamp(&self) -> u64 {
self.new_tip.timestamp
self.new_tip.timestamp()
}

/// Returns the block info for the tip block.
pub fn block_info(&self) -> BlockInfo {
BlockInfo {
block_gas_limit: self.new_tip.gas_limit,
block_gas_limit: self.new_tip.gas_limit(),
last_seen_block_hash: self.hash(),
last_seen_block_number: self.number(),
pending_basefee: self.pending_block_base_fee,
Expand All @@ -764,7 +770,10 @@ impl CanonicalStateUpdate<'_> {
}
}

impl fmt::Display for CanonicalStateUpdate<'_> {
impl<H, B> fmt::Display for CanonicalStateUpdate<'_, H, B>
where
H: BlockHeader,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CanonicalStateUpdate")
.field("hash", &self.hash())
Expand Down
Loading