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

Patch transaction pool ordering zero tip #2643

Merged
merged 5 commits into from
Jan 31, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- [2387](https://github.com/FuelLabs/fuel-core/pull/2387): Update description `tx-max-depth` flag.
- [2630](https://github.com/FuelLabs/fuel-core/pull/2630): Removed some noisy `tracing::info!` logs
- [2643](https://github.com/FuelLabs/fuel-core/pull/2643): Before this fix when tip is zero, transactions that use 30M have the same priority as transactions with 1M gas. Now they are correctly ordered.

### Added
- [2553](https://github.com/FuelLabs/fuel-core/pull/2553): Scaffold global merkle root storage crate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ where

fn key(store_entry: &StorageData) -> Key {
let transaction = &store_entry.transaction;
let tip_gas_ratio = RatioTipGas::new(transaction.tip(), transaction.max_gas());
let tip_gas_ratio =
RatioTipGas::new(transaction.tip().saturating_add(1), transaction.max_gas());

Key {
ratio: tip_gas_ratio,
Expand Down
57 changes: 57 additions & 0 deletions crates/services/txpool_v2/src/tests/tests_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,63 @@ fn get_sorted_out_tx_same_tips() {
universe.assert_pool_integrity(&[]);
}

#[test]
fn get_sorted_out_zero_tip() {
let mut universe = TestPoolUniverse::default();
universe.build_pool();

// Given
let gas_coin = universe.setup_coin().1;
let tx1 = TransactionBuilder::script(vec![], vec![])
.tip(10)
.max_fee_limit(0)
.script_gas_limit(GAS_LIMIT)
.add_input(gas_coin)
.finalize_as_transaction();

let (_, gas_coin) = universe.setup_coin();
let tx2 = TransactionBuilder::script(vec![], vec![])
.tip(10)
.max_fee_limit(0)
.script_gas_limit(GAS_LIMIT / 2)
.add_input(gas_coin)
.finalize_as_transaction();

let (_, gas_coin) = universe.setup_coin();
let tx3 = TransactionBuilder::script(vec![], vec![])
.tip(10)
.max_fee_limit(0)
.script_gas_limit(GAS_LIMIT / 4)
.add_input(gas_coin)
.finalize_as_transaction();

let tx1_id = tx1.id(&ChainId::default());
let tx2_id = tx2.id(&ChainId::default());
let tx3_id = tx3.id(&ChainId::default());

universe.verify_and_insert(tx1).unwrap();
universe.verify_and_insert(tx2).unwrap();
universe.verify_and_insert(tx3).unwrap();

// When
let txs = universe
.get_pool()
.write()
.extract_transactions_for_block(Constraints {
minimal_gas_price: 0,
max_gas: u64::MAX,
maximum_txs: u16::MAX,
maximum_block_size: u32::MAX,
});

// Then
assert_eq!(txs.len(), 3, "Should have 3 txs");
assert_eq!(txs[0].id(), tx3_id, "First should be tx3");
assert_eq!(txs[1].id(), tx2_id, "Second should be tx2");
assert_eq!(txs[2].id(), tx1_id, "Third should be tx1");
universe.assert_pool_integrity(&[]);
}

#[test]
fn get_sorted_out_tx_profitable_ratios() {
let mut universe = TestPoolUniverse::default();
Expand Down
Loading