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

feat: change priority in mempool to take into account age #4737

Merged
merged 4 commits into from
Sep 27, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use std::{
fmt::{Display, Formatter},
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};

use tari_common_types::types::{HashOutput, PrivateKey, PublicKey};
Expand All @@ -46,11 +47,15 @@ impl FeePriority {
// Big-endian used here, the MSB is in the starting index. The ordering for Vec<u8> is big-endian and the
// unconfirmed pool expects the lowest priority to be sorted lowest to highest in the BTreeMap
let fee_priority = fee_per_byte.to_be_bytes();
let maturity_priority = (u64::MAX - transaction.min_input_maturity()).to_be_bytes();
let age = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(n) => n.as_secs(),
Err(_) => 0,
};
let age_priority = (u64::MAX - age).to_be_bytes();

let mut priority = vec![0u8; 8 + 8 + 64];
priority[..8].copy_from_slice(&fee_priority[..]);
priority[8..16].copy_from_slice(&maturity_priority[..]);
priority[8..16].copy_from_slice(&age_priority[..]);
// Use the aggregate signature and nonce.
// If a transaction has many kernels, unless they are all identical, the fee priority will be different.
let (agg_sig, agg_nonce) = transaction
Expand Down