Skip to content

Commit

Permalink
Merge pull request #4648 from eval-exec/exec/backport/4647
Browse files Browse the repository at this point in the history
backport # 4647 `get_fee_rate_statistics` should skip first (cellbase) Transaction
  • Loading branch information
zhangsoledad authored Sep 14, 2024
2 parents fd822d5 + 46ee6fe commit 247e1fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
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

0 comments on commit 247e1fd

Please sign in to comment.