chore(txpool): export validation constants (#3979)

This commit is contained in:
Roman Krasiuk
2023-07-28 14:10:55 +03:00
committed by GitHub
parent c04f3e443f
commit c33f93004b
4 changed files with 26 additions and 20 deletions

View File

@@ -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> {

View File

@@ -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;

View File

@@ -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,

View File

@@ -10,6 +10,7 @@ use reth_primitives::{
};
use std::{fmt, time::Instant};
mod constants;
mod eth;
mod task;
@@ -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> {