Skip to content

Commit

Permalink
chore(txpool): export validation constants
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk committed Jul 28, 2023
1 parent d2cdd10 commit 9710683
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
18 changes: 0 additions & 18 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,6 @@ mod traits;
/// Common test helpers for mocking a pool
pub mod test_utils;

// TX_SLOT_SIZE is used to calculate how many data slots a single transaction
// takes up based on its size. The slots are used as DoS protection, ensuring
// that validating a new transaction remains a constant operation (in reality
// O(maxslots), where max slots are 4 currently).
pub(crate) const TX_SLOT_SIZE: usize = 32 * 1024;

// TX_MAX_SIZE is the maximum size a single transaction can have. This field has
// non-trivial consequences: larger transactions are significantly harder and
// more expensive to propagate; larger transactions also take more resources
// to validate whether they fit into the pool or not.
pub(crate) const TX_MAX_SIZE: usize = 4 * TX_SLOT_SIZE; //128KB

// Maximum bytecode to permit for a contract
pub(crate) const MAX_CODE_SIZE: usize = 24576;

// Maximum initcode to permit in a creation transaction and create instructions
pub(crate) const MAX_INIT_CODE_SIZE: usize = 2 * MAX_CODE_SIZE;

/// A shareable, generic, customizable `TransactionPool` implementation.
#[derive(Debug)]
pub struct Pool<V: TransactionValidator, T: TransactionOrdering> {
Expand Down
17 changes: 17 additions & 0 deletions crates/transaction-pool/src/validate/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// TX_SLOT_SIZE is used to calculate how many data slots a single transaction
/// takes up based on its size. The slots are used as DoS protection, ensuring
/// that validating a new transaction remains a constant operation (in reality
/// O(maxslots), where max slots are 4 currently).
pub const TX_SLOT_SIZE: usize = 32 * 1024;

/// TX_MAX_SIZE is the maximum size a single transaction can have. This field has
/// non-trivial consequences: larger transactions are significantly harder and
/// more expensive to propagate; larger transactions also take more resources
/// to validate whether they fit into the pool or not.
pub const TX_MAX_SIZE: usize = 4 * TX_SLOT_SIZE; // 128KB

/// Maximum bytecode to permit for a contract
pub const MAX_CODE_SIZE: usize = 24576;

/// Maximum initcode to permit in a creation transaction and create instructions
pub const MAX_INIT_CODE_SIZE: usize = 2 * MAX_CODE_SIZE;
7 changes: 5 additions & 2 deletions crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
use crate::{
error::InvalidPoolTransactionError,
traits::{PoolTransaction, TransactionOrigin},
validate::{task::ValidationJobSender, TransactionValidatorError, ValidationTask},
TransactionValidationOutcome, TransactionValidator, MAX_INIT_CODE_SIZE, TX_MAX_SIZE,
validate::{
task::ValidationJobSender, TransactionValidatorError, ValidationTask, MAX_INIT_CODE_SIZE,
TX_MAX_SIZE,
},
TransactionValidationOutcome, TransactionValidator,
};
use reth_primitives::{
constants::ETHEREUM_BLOCK_GAS_LIMIT, ChainSpec, InvalidTransactionError, EIP1559_TX_TYPE_ID,
Expand Down
4 changes: 4 additions & 0 deletions crates/transaction-pool/src/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use reth_primitives::{
};
use std::{fmt, time::Instant};

mod constants;
mod eth;
mod task;

Expand All @@ -19,6 +20,9 @@ pub use eth::{EthTransactionValidator, EthTransactionValidatorBuilder};
/// A spawnable task that performs transaction validation.
pub use task::ValidationTask;

/// Validation constants.
pub use constants::{MAX_CODE_SIZE, MAX_INIT_CODE_SIZE, TX_MAX_SIZE, TX_SLOT_SIZE};

/// A Result type returned after checking a transaction's validity.
#[derive(Debug)]
pub enum TransactionValidationOutcome<T: PoolTransaction> {
Expand Down

0 comments on commit 9710683

Please sign in to comment.