Skip to content

Commit

Permalink
Patch transaction pool ordering zero tip (#2643)
Browse files Browse the repository at this point in the history
## Description
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

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog
- [x] New behavior is reflected in tests
- [x] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [x] I have reviewed the code myself
- [x] I have created follow-up issues caused by this PR and linked them
here
  • Loading branch information
AurelienFT authored Jan 31, 2025
1 parent 8974076 commit a2cda1b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
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

0 comments on commit a2cda1b

Please sign in to comment.