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

backport # 4647 get_fee_rate_statistics should skip first (cellbase) Transaction #4648

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 10 additions & 3 deletions rpc/src/tests/fee_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ fn test_fee_rate_statics() {
total_difficulty: 0u64.into(),
total_uncles_count: 0,
verified: None,
txs_fees: vec![Capacity::shannons(i * i * 100)],
cycles: Some(vec![i * 100]),
txs_sizes: Some(vec![i * 100]),

// first element in txs_fees is belong to cellbase
txs_fees: vec![
Capacity::shannons(i * 1234),
Capacity::shannons(i * i * 100),
],
// first element in cycles is belong to cellbase
cycles: Some(vec![0, i * 100]),
// first element in txs_sizes is belong to cellbase
txs_sizes: Some(vec![i * 5678, i * 100]),
};
provider.append(i, ext);
}
Expand Down
8 changes: 6 additions & 2 deletions rpc/src/util/fee_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,19 @@ where
target = std::cmp::min(self.provider.max_target(), target);

let mut fee_rates = self.provider.collect(target, |mut fee_rates, block_ext| {
if !block_ext.txs_fees.is_empty()
if block_ext.txs_fees.len() > 1
&& block_ext.cycles.is_some()
&& block_ext.txs_sizes.is_some()
{
// block_ext.txs_fees, cycles, txs_sizes length is same
for (fee, cycles, size) in itertools::izip!(
block_ext.txs_fees,
block_ext.cycles.expect("checked"),
block_ext.txs_sizes.expect("checked")
) {
)
// skip cellbase (first element in the Vec)
.skip(1)
{
let weight = get_transaction_weight(size as usize, cycles);
if weight > 0 {
fee_rates.push(FeeRate::calculate(fee, weight).as_u64());
Expand Down