diff --git a/CHANGELOG.md b/CHANGELOG.md index ef58b7360af..798098f3400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/crates/services/txpool_v2/src/selection_algorithms/ratio_tip_gas.rs b/crates/services/txpool_v2/src/selection_algorithms/ratio_tip_gas.rs index 61fc4141736..afb8d116aba 100644 --- a/crates/services/txpool_v2/src/selection_algorithms/ratio_tip_gas.rs +++ b/crates/services/txpool_v2/src/selection_algorithms/ratio_tip_gas.rs @@ -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, diff --git a/crates/services/txpool_v2/src/tests/tests_pool.rs b/crates/services/txpool_v2/src/tests/tests_pool.rs index d601150f4db..780bbbd6450 100644 --- a/crates/services/txpool_v2/src/tests/tests_pool.rs +++ b/crates/services/txpool_v2/src/tests/tests_pool.rs @@ -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();