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(API): polish web3 api block-related types #1994

Merged
merged 7 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions core/lib/basic_types/src/web3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ pub struct BlockHeader {
#[serde(rename = "gasLimit", default)]
pub gas_limit: U256,
/// Base fee per unit of gas (if past London)
#[serde(rename = "baseFeePerGas", skip_serializing_if = "Option::is_none")]
pub base_fee_per_gas: Option<U256>,
#[serde(rename = "baseFeePerGas")]
pub base_fee_per_gas: U256,
/// Extra data
#[serde(rename = "extraData")]
pub extra_data: Bytes,
Expand Down Expand Up @@ -406,8 +406,8 @@ pub struct Block<TX> {
#[serde(rename = "gasLimit", default)]
pub gas_limit: U256,
/// Base fee per unit of gas (if past London)
#[serde(rename = "baseFeePerGas", skip_serializing_if = "Option::is_none")]
pub base_fee_per_gas: Option<U256>,
#[serde(rename = "baseFeePerGas")]
pub base_fee_per_gas: U256,
/// Extra data
#[serde(rename = "extraData")]
pub extra_data: Bytes,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions core/lib/dal/src/blocks_web3_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ impl BlocksWeb3Dal<'_, '_> {
miniblocks.hash,
miniblocks.number,
prev_miniblock.hash AS "parent_hash?",
miniblocks.timestamp
miniblocks.timestamp,
miniblocks.base_fee_per_gas,
miniblocks.gas_limit AS "block_gas_limit?"
FROM
miniblocks
LEFT JOIN miniblocks prev_miniblock ON prev_miniblock.number = miniblocks.number - 1
Expand Down Expand Up @@ -200,8 +202,11 @@ impl BlocksWeb3Dal<'_, '_> {
receipts_root: H256::zero(),
number: Some(U64::from(row.number)),
gas_used: U256::zero(),
gas_limit: U256::zero(),
base_fee_per_gas: None,
gas_limit: (row
.block_gas_limit
.unwrap_or(i64::from(LEGACY_BLOCK_GAS_LIMIT)) as u64)
.into(),
base_fee_per_gas: bigdecimal_to_u256(row.base_fee_per_gas),
extra_data: Bytes::default(),
// TODO: include logs
logs_bloom: H2048::default(),
Expand Down
4 changes: 2 additions & 2 deletions core/lib/eth_client/src/clients/http/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ where
};

latency.observe();
// base_fee_per_gas always exists after London fork
Ok(block.base_fee_per_gas.unwrap())

Ok(block.base_fee_per_gas)
}

async fn get_tx_status(&self, hash: H256) -> Result<Option<ExecutedTxStatus>, Error> {
Expand Down
37 changes: 34 additions & 3 deletions core/node/api_server/src/web3/tests/ws.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! WS-related tests.

use std::collections::HashSet;
use std::{collections::HashSet, str::FromStr};

use assert_matches::assert_matches;
use async_trait::async_trait;
use http::StatusCode;
use tokio::sync::watch;
use zksync_config::configs::chain::NetworkConfig;
use zksync_dal::ConnectionPool;
use zksync_types::{api, Address, L1BatchNumber, H256, U64};
use zksync_types::{api, Address, L1BatchNumber, H160, H2048, H256, U64};
use zksync_web3_decl::{
client::{WsClient, L2},
jsonrpsee::{
Expand All @@ -19,7 +20,7 @@ use zksync_web3_decl::{
rpc_params,
},
namespaces::{EthNamespaceClient, ZksNamespaceClient},
types::{BlockHeader, PubSubFilter},
types::{BlockHeader, Bytes, PubSubFilter},
};

use super::*;
Expand Down Expand Up @@ -290,15 +291,45 @@ impl WsTest for BasicSubscriptionsTest {
.await
.context("Timed out waiting for new block header")?
.context("New blocks subscription terminated")??;

let sha3_uncles_hash =
H256::from_str("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")
.unwrap();

assert_eq!(
received_block_header.number,
Some(new_l2_block.number.0.into())
);
assert_eq!(received_block_header.hash, Some(new_l2_block.hash));
assert_matches!(received_block_header.parent_hash, H256(_));
assert_eq!(received_block_header.uncles_hash, sha3_uncles_hash);
assert_eq!(received_block_header.author, H160::zero());
assert_eq!(received_block_header.state_root, H256::zero());
assert_eq!(received_block_header.transactions_root, H256::zero());
assert_eq!(received_block_header.receipts_root, H256::zero());
assert_eq!(
received_block_header.number,
Some(U64::from(new_l2_block.number.0))
);
assert_eq!(received_block_header.gas_used, U256::zero());
assert_eq!(
received_block_header.gas_limit,
new_l2_block.gas_limit.into()
);
assert_eq!(
received_block_header.base_fee_per_gas,
new_l2_block.base_fee_per_gas.into()
);
assert_eq!(received_block_header.extra_data, Bytes::default());
assert_eq!(received_block_header.logs_bloom, H2048::default());
assert_eq!(
received_block_header.timestamp,
new_l2_block.timestamp.into()
);
assert_eq!(received_block_header.difficulty, U256::zero());
assert_eq!(received_block_header.mix_hash, None);
assert_eq!(received_block_header.nonce, None);

blocks_subscription.unsubscribe().await?;
Ok(())
}
Expand Down
14 changes: 6 additions & 8 deletions core/node/fee_model/src/l1_gas_price/gas_adjuster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,13 @@ impl GasAdjuster {
let mut blob_base_fee_history = Vec::new();
for block_number in block_range {
let header = eth_client.block(U64::from(block_number).into()).await?;
if let Some(base_fee_per_gas) =
header.as_ref().and_then(|header| header.base_fee_per_gas)
{
base_fee_history.push(base_fee_per_gas.as_u64())
}

if let Some(excess_blob_gas) = header.as_ref().and_then(|header| header.excess_blob_gas)
{
blob_base_fee_history.push(Self::blob_base_fee(excess_blob_gas.as_u64()))
if let Some(header) = header.as_ref() {
base_fee_history.push(header.base_fee_per_gas.as_u64());

if let Some(excess_blob_gas) = header.excess_blob_gas {
blob_base_fee_history.push(Self::blob_base_fee(excess_blob_gas.as_u64()));
}
}
}

Expand Down
Loading