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: fee-rate estimator #3783

Conversation

zhangsoledad
Copy link
Member

@zhangsoledad zhangsoledad commented Jan 5, 2023

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

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Release note

Title Only: Include only the PR title in the release note.

@zhangsoledad zhangsoledad force-pushed the zhangsoledad/fee-rate-estimator branch 8 times, most recently from 98a6654 to 1feba63 Compare January 16, 2023 09:11
@zhangsoledad zhangsoledad marked this pull request as ready for review January 16, 2023 09:22
@zhangsoledad zhangsoledad requested a review from a team as a code owner January 16, 2023 09:22
@zhangsoledad zhangsoledad requested review from quake and removed request for a team January 16, 2023 09:22
@zhangsoledad zhangsoledad force-pushed the zhangsoledad/fee-rate-estimator branch from 1feba63 to 4a90cbf Compare January 16, 2023 09:26
@zhangsoledad zhangsoledad force-pushed the zhangsoledad/fee-rate-estimator branch from 4a90cbf to f4527f8 Compare April 5, 2023 10:11
Comment on lines +75 to +82
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
}
}
Copy link
Collaborator

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);
Copy link
Collaborator

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.

Comment on lines +104 to +117
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
}

Copy link
Collaborator

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()
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants