-
Notifications
You must be signed in to change notification settings - Fork 228
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: fee-rate estimator #3783
feat: fee-rate estimator #3783
Conversation
98a6654
to
1feba63
Compare
1feba63
to
4a90cbf
Compare
4a90cbf
to
f4527f8
Compare
fn cmp(&self, other: &Self) -> ::std::cmp::Ordering { | ||
let order = self.fee_rate.cmp(&other.fee_rate); | ||
if order == ::std::cmp::Ordering::Equal { | ||
other.weight.cmp(&self.weight) | ||
} else { | ||
order | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this:
impl Ord for TxStatus {
fn cmp(&self, other: &Self) -> ::std::cmp::Ordering {
self.fee_rate
.cmp(&other.fee_rate)
.then_with(|| other.weight.cmp(&self.weight))
}
}
let fee_rate = FeeRate::calculate(Capacity::shannons(tx.fee()), weight); | ||
let new_tx = TxAdded::new(tx.hash(), weight, fee_rate, current_dt); | ||
self.txs.add_transaction(new_tx); | ||
self.txs.expire(expired_dt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.txs.expire(expired_dt);
have a return value, but it's never used.
fn expire(&mut self, expired_dt: Duration) -> usize { | ||
let count = self | ||
.0 | ||
.iter() | ||
.rev() | ||
.skip_while(|tx| tx.added_dt < expired_dt) | ||
.count(); | ||
let total = self.0.len(); | ||
if count > 0 && total >= count { | ||
self.0.truncate(total - count); | ||
} | ||
count | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this:
fn expire(&mut self, expired_dt: Duration) -> usize {
let original_len = self.0.len();
self.0.retain(|tx| tx.added_dt >= expired_dt);
original_len - self.0.len()
}
What is changed and how it works?
The algorithm of https://bitcoiner.live/?tab=info implements the fee-rate estimator to achieve the goal in #3673, and there are still some limitations, Weight-Units Flow algorithm is mainly for sampling and analyzing the transactions in tx-pool, so it will be available only after the node has been up for a warm-up period, if the estimator is accessed during the warm-up period it will fallback to the mean of the past historical data (21 blocks)
Check List
Tests
Release note