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

feat: add enough blob fee tx state #4680

Merged
merged 1 commit into from
Sep 20, 2023
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
12 changes: 8 additions & 4 deletions crates/transaction-pool/src/pool/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ bitflags::bitflags! {
const NOT_TOO_MUCH_GAS = 0b000100;
/// Covers the Dynamic fee requirement.
///
/// Set to 1 if `feeCap` of the transaction meets the requirement of the pending block.
/// Set to 1 if `maxBlobFeePerGas` of the transaction meets the requirement of the pending block.
const ENOUGH_FEE_CAP_BLOCK = 0b000010;
/// Covers the dynamic blob fee requirement, only relevant for EIP-4844 blob transactions
///
/// Set to 1 if `maxBlobFeePer` of the transaction meets the requirement of the pending block.
const ENOUGH_BLOB_FEE_CAP_BLOCK = 0b000001;

const PENDING_POOL_BITS = Self::NO_PARKED_ANCESTORS.bits()| Self::NO_NONCE_GAPS.bits() | Self::ENOUGH_BALANCE.bits() | Self::NOT_TOO_MUCH_GAS.bits() | Self::ENOUGH_FEE_CAP_BLOCK.bits();
const PENDING_POOL_BITS = Self::NO_PARKED_ANCESTORS.bits()| Self::NO_NONCE_GAPS.bits() | Self::ENOUGH_BALANCE.bits() | Self::NOT_TOO_MUCH_GAS.bits() | Self::ENOUGH_FEE_CAP_BLOCK.bits() | Self::ENOUGH_BLOB_FEE_CAP_BLOCK.bits();

const BASE_FEE_POOL_BITS = Self::NO_PARKED_ANCESTORS.bits() | Self::NO_NONCE_GAPS.bits() | Self::ENOUGH_BALANCE.bits() | Self::NOT_TOO_MUCH_GAS.bits();

Expand Down Expand Up @@ -140,12 +144,12 @@ mod tests {
assert_eq!(SubPool::Pending, state.into());
assert!(state.is_pending());

let bits = 0b111110;
let bits = 0b111111;
let state = TxState::from_bits(bits).unwrap();
assert_eq!(SubPool::Pending, state.into());
assert!(state.is_pending());

let bits = 0b111110;
let bits = 0b111111;
let state = TxState::from_bits(bits).unwrap();
assert_eq!(SubPool::Pending, state.into());
assert!(state.is_pending());
Expand Down
46 changes: 46 additions & 0 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,15 @@ impl<T: PoolTransaction> AllTransactions<T> {
if transaction.is_eip4844() {
transaction =
self.ensure_valid_blob_transaction(transaction, on_chain_balance, ancestor)?;
let blob_fee_cap = transaction.transaction.max_fee_per_blob_gas().unwrap_or_default();
if blob_fee_cap >= self.pending_blob_fee as u128 {
state.insert(TxState::ENOUGH_BLOB_FEE_CAP_BLOCK);
}
} else {
// Non-EIP4844 transaction always satisfy the blob fee cap condition
state.insert(TxState::ENOUGH_BLOB_FEE_CAP_BLOCK);
}

let transaction = Arc::new(transaction);

// If there's no ancestor tx then this is the next transaction.
Expand Down Expand Up @@ -1669,6 +1677,44 @@ mod tests {
traits::TransactionOrigin,
};

#[test]
fn test_insert_blob() {
let on_chain_balance = U256::MAX;
let on_chain_nonce = 0;
let mut f = MockTransactionFactory::default();
let mut pool = AllTransactions::default();
let tx = MockTransaction::eip4844().inc_price().inc_limit();
let valid_tx = f.validated(tx);
let InsertOk { updates, replaced_tx, move_to, state, .. } =
pool.insert_tx(valid_tx.clone(), on_chain_balance, on_chain_nonce).unwrap();
assert!(updates.is_empty());
assert!(replaced_tx.is_none());
assert!(state.contains(TxState::NO_NONCE_GAPS));
assert!(state.contains(TxState::ENOUGH_BALANCE));
assert!(state.contains(TxState::ENOUGH_BLOB_FEE_CAP_BLOCK));
assert_eq!(move_to, SubPool::Pending);

let inserted = pool.txs.get(&valid_tx.transaction_id).unwrap();
assert_eq!(inserted.subpool, SubPool::Pending);
}

#[test]
fn test_insert_blob_not_enough_blob_fee() {
let on_chain_balance = U256::MAX;
let on_chain_nonce = 0;
let mut f = MockTransactionFactory::default();
let mut pool = AllTransactions { pending_blob_fee: 10_000_000, ..Default::default() };
pool.pending_blob_fee = 10_000_000;
let tx = MockTransaction::eip4844().inc_price().inc_limit();
let valid_tx = f.validated(tx);
let InsertOk { state, .. } =
pool.insert_tx(valid_tx.clone(), on_chain_balance, on_chain_nonce).unwrap();
assert!(state.contains(TxState::NO_NONCE_GAPS));
assert!(!state.contains(TxState::ENOUGH_BLOB_FEE_CAP_BLOCK));

let _ = pool.txs.get(&valid_tx.transaction_id).unwrap();
}

#[test]
fn test_insert_pending() {
let on_chain_balance = U256::MAX;
Expand Down
Loading