From 71899b7b14ae1646e412df9bfd5391f9e625530c Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Wed, 24 Jan 2024 09:34:59 -0800 Subject: [PATCH] prioritization multiplier --- .../scheduler_controller.rs | 18 +++++++++--------- .../transaction_state_container.rs | 9 +++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/core/src/banking_stage/transaction_scheduler/scheduler_controller.rs b/core/src/banking_stage/transaction_scheduler/scheduler_controller.rs index a4d0d60c2b1d9d..246a6fd58b66b0 100644 --- a/core/src/banking_stage/transaction_scheduler/scheduler_controller.rs +++ b/core/src/banking_stage/transaction_scheduler/scheduler_controller.rs @@ -775,7 +775,7 @@ mod tests { &Keypair::new(), &Pubkey::new_unique(), 1, - 1, + 10, bank.last_blockhash(), ); let tx2 = create_and_fund_prioritized_transfer( @@ -784,7 +784,7 @@ mod tests { &Keypair::new(), &Pubkey::new_unique(), 1, - 2, + 20, bank.last_blockhash(), ); let tx1_hash = tx1.message().hash(); @@ -831,7 +831,7 @@ mod tests { &Keypair::new(), &pk, 1, - 1, + 10, bank.last_blockhash(), ); let tx2 = create_and_fund_prioritized_transfer( @@ -840,7 +840,7 @@ mod tests { &Keypair::new(), &pk, 1, - 2, + 20, bank.last_blockhash(), ); let tx1_hash = tx1.message().hash(); @@ -892,7 +892,7 @@ mod tests { &Keypair::new(), &Pubkey::new_unique(), i as u64, - 1, + 10, bank.last_blockhash(), ) }) @@ -905,7 +905,7 @@ mod tests { &Keypair::new(), &Pubkey::new_unique(), i as u64, - 2, + 20, bank.last_blockhash(), ) }) @@ -956,7 +956,7 @@ mod tests { &Keypair::new(), &Pubkey::new_unique(), 1, - i, + i * 10, bank.last_blockhash(), ) }) @@ -1022,7 +1022,7 @@ mod tests { &Keypair::new(), &Pubkey::new_unique(), 1, - 1, + 10, bank.last_blockhash(), ); let tx2 = create_and_fund_prioritized_transfer( @@ -1031,7 +1031,7 @@ mod tests { &Keypair::new(), &Pubkey::new_unique(), 1, - 2, + 20, bank.last_blockhash(), ); let tx1_hash = tx1.message().hash(); diff --git a/core/src/banking_stage/transaction_scheduler/transaction_state_container.rs b/core/src/banking_stage/transaction_scheduler/transaction_state_container.rs index abfce62de10f80..022eac43c825d8 100644 --- a/core/src/banking_stage/transaction_scheduler/transaction_state_container.rs +++ b/core/src/banking_stage/transaction_scheduler/transaction_state_container.rs @@ -166,8 +166,13 @@ impl TransactionStateContainer { lamports_per_signature * state.transaction_ttl().transaction.signatures().len() as u64; let cost = state.transaction_cost().sum(); - signature_fees - .saturating_add(priority_fee) + // We need a multiplier here to avoid rounding down too aggressively. + // For many small transactions, the cost will be greater than the fees in terms of raw lamports. + // For the purposes of calculating prioritization, we multiply the fees by a large number so that + // the cost is a small fraction. + const MULTIPLIER: u64 = 1_000_000; + (signature_fees.saturating_add(priority_fee)) + .saturating_mul(MULTIPLIER) .saturating_div(cost) } }