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

Handle u64 conversion #1091

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 12 additions & 11 deletions client/rpc/src/eth/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,19 +339,19 @@ where
let base_fee = client.runtime_api().gas_price(hash).unwrap_or_default();
let receipts = handler.current_receipts(hash);
let mut result = FeeHistoryCacheItem {
base_fee: if base_fee > U256::from(u64::MAX) { u64::MAX } else { base_fee.low_u64() },
base_fee: UniqueSaturatedInto::<u64>::unique_saturated_into(base_fee),
gas_used_ratio: 0f64,
rewards: Vec::new(),
};
if let (Some(block), Some(receipts)) = (block, receipts) {
block_number = Some(block.header.number.as_u64());
let gas_used = block.header.gas_used.as_u64() as f64;
let gas_limit = block.header.gas_limit.as_u64() as f64;
block_number = Some(UniqueSaturatedInto::<u64>::unique_saturated_into(block.header.number));
let gas_used = UniqueSaturatedInto::<u64>::unique_saturated_into(block.header.gas_used) as f64;
let gas_limit = UniqueSaturatedInto::<u64>::unique_saturated_into(block.header.gas_limit) as f64;
result.gas_used_ratio = gas_used / gas_limit;

let mut previous_cumulative_gas = U256::zero();
let used_gas = |current: U256, previous: &mut U256| -> u64 {
let r = current.saturating_sub(*previous).as_u64();
let r = UniqueSaturatedInto::<u64>::unique_saturated_into(current.saturating_sub(*previous));
*previous = current;
r
};
Expand All @@ -365,15 +365,16 @@ where
},
effective_reward: match block.transactions.get(i) {
Some(&ethereum::TransactionV2::Legacy(ref t)) => {
t.gas_price.saturating_sub(base_fee).as_u64()
UniqueSaturatedInto::<u64>::unique_saturated_into(t.gas_price.saturating_sub(base_fee))
}
Some(&ethereum::TransactionV2::EIP2930(ref t)) => {
t.gas_price.saturating_sub(base_fee).as_u64()
UniqueSaturatedInto::<u64>::unique_saturated_into(t.gas_price.saturating_sub(base_fee))
}
Some(&ethereum::TransactionV2::EIP1559(ref t)) => t
.max_priority_fee_per_gas
.min(t.max_fee_per_gas.saturating_sub(base_fee))
.as_u64(),
Some(&ethereum::TransactionV2::EIP1559(ref t)) => UniqueSaturatedInto::<u64>::unique_saturated_into(
t
.max_priority_fee_per_gas
.min(t.max_fee_per_gas.saturating_sub(base_fee))
),
None => 0,
},
})
Expand Down
3 changes: 2 additions & 1 deletion client/rpc/src/eth/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ where
.unwrap_or(default_elasticity)
.deconstruct();
let elasticity = elasticity as f64 / 1_000_000f64;
let last_fee_per_gas = last_fee_per_gas.as_u64() as f64;
let last_fee_per_gas =
UniqueSaturatedInto::<u64>::unique_saturated_into(*last_fee_per_gas) as f64;
if last_gas_used > &0.5 {
// Increase base gas
let increase = ((last_gas_used - 0.5) * 2f64) * elasticity;
Expand Down