Skip to content

Commit e4935a1

Browse files
Bashmuntayongkangc
authored andcommitted
fix(txpool): derive accurate queued reason for SubPool::Blob (#20095)
1 parent 7f83b1a commit e4935a1

File tree

1 file changed

+99
-1
lines changed
  • crates/transaction-pool/src/pool

1 file changed

+99
-1
lines changed

crates/transaction-pool/src/pool/state.rs

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,25 @@ impl TxState {
117117
}
118118
}
119119
SubPool::BaseFee => Some(QueuedReason::InsufficientBaseFee),
120-
SubPool::Blob => Some(QueuedReason::InsufficientBlobFee),
120+
SubPool::Blob => {
121+
// For blob transactions, derive the queued reason from flags similarly to Queued.
122+
if !self.contains(Self::NO_NONCE_GAPS) {
123+
Some(QueuedReason::NonceGap)
124+
} else if !self.contains(Self::ENOUGH_BALANCE) {
125+
Some(QueuedReason::InsufficientBalance)
126+
} else if !self.contains(Self::NO_PARKED_ANCESTORS) {
127+
Some(QueuedReason::ParkedAncestors)
128+
} else if !self.contains(Self::NOT_TOO_MUCH_GAS) {
129+
Some(QueuedReason::TooMuchGas)
130+
} else if !self.contains(Self::ENOUGH_FEE_CAP_BLOCK) {
131+
Some(QueuedReason::InsufficientBaseFee)
132+
} else if !self.contains(Self::ENOUGH_BLOB_FEE_CAP_BLOCK) {
133+
Some(QueuedReason::InsufficientBlobFee)
134+
} else {
135+
// Fallback for unexpected non-pending blob state
136+
Some(QueuedReason::InsufficientBlobFee)
137+
}
138+
}
121139
}
122140
}
123141
}
@@ -308,4 +326,84 @@ mod tests {
308326
assert!(state.is_blob());
309327
assert!(!state.is_pending());
310328
}
329+
330+
#[test]
331+
fn test_blob_reason_insufficient_base_fee() {
332+
// Blob tx with all structural bits set and blob fee sufficient, but base fee insufficient
333+
let state = TxState::NO_PARKED_ANCESTORS |
334+
TxState::NO_NONCE_GAPS |
335+
TxState::ENOUGH_BALANCE |
336+
TxState::NOT_TOO_MUCH_GAS |
337+
TxState::ENOUGH_BLOB_FEE_CAP_BLOCK |
338+
TxState::BLOB_TRANSACTION;
339+
// ENOUGH_FEE_CAP_BLOCK intentionally not set
340+
let subpool: SubPool = state.into();
341+
assert_eq!(subpool, SubPool::Blob);
342+
let reason = state.determine_queued_reason(subpool);
343+
assert_eq!(reason, Some(QueuedReason::InsufficientBaseFee));
344+
}
345+
346+
#[test]
347+
fn test_blob_reason_insufficient_blob_fee() {
348+
// Blob tx with all structural bits set and base fee sufficient, but blob fee insufficient
349+
let state = TxState::NO_PARKED_ANCESTORS |
350+
TxState::NO_NONCE_GAPS |
351+
TxState::ENOUGH_BALANCE |
352+
TxState::NOT_TOO_MUCH_GAS |
353+
TxState::ENOUGH_FEE_CAP_BLOCK |
354+
TxState::BLOB_TRANSACTION;
355+
// ENOUGH_BLOB_FEE_CAP_BLOCK intentionally not set
356+
let subpool: SubPool = state.into();
357+
assert_eq!(subpool, SubPool::Blob);
358+
let reason = state.determine_queued_reason(subpool);
359+
assert_eq!(reason, Some(QueuedReason::InsufficientBlobFee));
360+
}
361+
362+
#[test]
363+
fn test_blob_reason_nonce_gap() {
364+
// Blob tx with nonce gap should report NonceGap regardless of fee bits
365+
let mut state = TxState::NO_PARKED_ANCESTORS |
366+
TxState::ENOUGH_BALANCE |
367+
TxState::NOT_TOO_MUCH_GAS |
368+
TxState::ENOUGH_FEE_CAP_BLOCK |
369+
TxState::ENOUGH_BLOB_FEE_CAP_BLOCK |
370+
TxState::BLOB_TRANSACTION;
371+
state.remove(TxState::NO_NONCE_GAPS);
372+
let subpool: SubPool = state.into();
373+
assert_eq!(subpool, SubPool::Blob);
374+
let reason = state.determine_queued_reason(subpool);
375+
assert_eq!(reason, Some(QueuedReason::NonceGap));
376+
}
377+
378+
#[test]
379+
fn test_blob_reason_insufficient_balance() {
380+
// Blob tx with insufficient balance
381+
let state = TxState::NO_PARKED_ANCESTORS |
382+
TxState::NO_NONCE_GAPS |
383+
TxState::NOT_TOO_MUCH_GAS |
384+
TxState::ENOUGH_FEE_CAP_BLOCK |
385+
TxState::ENOUGH_BLOB_FEE_CAP_BLOCK |
386+
TxState::BLOB_TRANSACTION;
387+
// ENOUGH_BALANCE intentionally not set
388+
let subpool: SubPool = state.into();
389+
assert_eq!(subpool, SubPool::Blob);
390+
let reason = state.determine_queued_reason(subpool);
391+
assert_eq!(reason, Some(QueuedReason::InsufficientBalance));
392+
}
393+
394+
#[test]
395+
fn test_blob_reason_too_much_gas() {
396+
// Blob tx exceeding gas limit
397+
let mut state = TxState::NO_PARKED_ANCESTORS |
398+
TxState::NO_NONCE_GAPS |
399+
TxState::ENOUGH_BALANCE |
400+
TxState::ENOUGH_FEE_CAP_BLOCK |
401+
TxState::ENOUGH_BLOB_FEE_CAP_BLOCK |
402+
TxState::BLOB_TRANSACTION;
403+
state.remove(TxState::NOT_TOO_MUCH_GAS);
404+
let subpool: SubPool = state.into();
405+
assert_eq!(subpool, SubPool::Blob);
406+
let reason = state.determine_queued_reason(subpool);
407+
assert_eq!(reason, Some(QueuedReason::TooMuchGas));
408+
}
311409
}

0 commit comments

Comments
 (0)