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

fix(eth-client): Use local FeeHistory type #1552

Merged
merged 1 commit into from
Apr 3, 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
21 changes: 13 additions & 8 deletions core/lib/eth_client/src/clients/http/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use zksync_types::web3::{

use crate::{
clients::http::{Method, COUNTERS, LATENCIES},
types::{Error, ExecutedTxStatus, FailureInfo, RawTokens},
types::{Error, ExecutedTxStatus, FailureInfo, FeeHistory, RawTokens},
Block, ContractCall, EthInterface, RawTransactionBytes,
};

Expand Down Expand Up @@ -104,14 +104,19 @@ impl EthInterface for QueryClient {
for chunk_start in (from_block..=upto_block).step_by(MAX_REQUEST_CHUNK) {
let chunk_end = (chunk_start + MAX_REQUEST_CHUNK).min(upto_block);
let chunk_size = chunk_end - chunk_start;
let chunk = self
.web3
.eth()
.fee_history(chunk_size.into(), chunk_end.into(), None)
.await?
.base_fee_per_gas;

history.extend(chunk);
let block_count = helpers::serialize(&U256::from(chunk_size));
let newest_block = helpers::serialize(&web3::types::BlockNumber::from(chunk_end));
let reward_percentiles = helpers::serialize(&Option::<()>::None);

let fee_history: FeeHistory = CallFuture::new(self.web3.transport().execute(
"eth_feeHistory",
vec![block_count, newest_block, reward_percentiles],
))
.await?;
perekopskiy marked this conversation as resolved.
Show resolved Hide resolved
if let Some(base_fees) = fee_history.base_fee_per_gas {
history.extend(base_fees);
}
}

latency.observe();
Expand Down
18 changes: 17 additions & 1 deletion core/lib/eth_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use zksync_types::{
Error as ContractError, Options,
},
ethabi,
types::{Address, BlockId, TransactionReceipt, H256, U256},
types::{Address, BlockId, BlockNumber, TransactionReceipt, H256, U256},
},
Bytes, EIP_4844_TX_TYPE, H160, H2048, U64,
};
Expand Down Expand Up @@ -260,6 +260,22 @@ pub struct FailureInfo {
pub gas_limit: U256,
}

/// The fee history type returned from RPC calls.
/// We don't use `FeeHistory` from `web3` crate because it's not compatible
/// with node implementations that skip empty `base_fee_per_gas`.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FeeHistory {
/// Lowest number block of the returned range.
pub oldest_block: BlockNumber,
/// A vector of block base fees per gas. This includes the next block after the newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 blocks.
pub base_fee_per_gas: Option<Vec<U256>>,
/// A vector of block gas used ratios. These are calculated as the ratio of gas used and gas limit.
pub gas_used_ratio: Option<Vec<f64>>,
/// A vector of effective priority fee per gas data points from a single block. All zeroes are returned if the block is empty. Returned only if requested.
pub reward: Option<Vec<Vec<U256>>>,
}

/// The block type returned from RPC calls.
/// This is generic over a `TX` type.
/// We can't use `Block` from `web3` crate because it doesn't support `excessBlobGas`.
Expand Down
Loading