Skip to content

Commit

Permalink
fix(api_server): fix blob_gas length (#2673)
Browse files Browse the repository at this point in the history
Discovered during testing Gateway integration (our own asserts from
query.rs started being triggered by our eth api implementation :D )

---------

Co-authored-by: perekopskiy <[email protected]>
  • Loading branch information
tomg10 and perekopskiy authored Sep 23, 2024
1 parent a2d4126 commit 44a8f79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/node/api_server/src/web3/namespaces/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,15 +690,16 @@ impl EthNamespace {
base_fee_per_gas.len()
]);

// `base_fee_per_gas` for next L2 block cannot be calculated, appending last fee as a placeholder.
base_fee_per_gas.push(*base_fee_per_gas.last().unwrap());

// We do not support EIP-4844, but per API specification we should return 0 for pre EIP-4844 blocks.
let base_fee_per_blob_gas = vec![U256::zero(); base_fee_per_gas.len()];
let blob_gas_used_ratio = vec![0.0; base_fee_per_gas.len()];
let blob_gas_used_ratio = vec![0.0; gas_used_ratio.len()];

// `base_fee_per_gas` for next L2 block cannot be calculated, appending last fee as a placeholder.
base_fee_per_gas.push(*base_fee_per_gas.last().unwrap());
Ok(FeeHistory {
inner: web3::FeeHistory {
oldest_block: zksync_types::web3::BlockNumber::Number(oldest_block.into()),
oldest_block: web3::BlockNumber::Number(oldest_block.into()),
base_fee_per_gas,
gas_used_ratio,
reward,
Expand Down
4 changes: 4 additions & 0 deletions core/tests/ts-integration/tests/api/web3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,10 @@ describe('web3 API compatibility tests', () => {
expect(parseInt(response.oldestBlock)).toEqual(receipt.blockNumber - 1);

expect(response.baseFeePerGas).toHaveLength(3);
expect(response.baseFeePerBlobGas).toHaveLength(3);
expect(response.gasUsedRatio).toHaveLength(2);
expect(response.blobGasUsedRatio).toHaveLength(2);
expect(response.l2PubdataPrice).toHaveLength(2);
for (let i = 0; i < 2; i += 1) {
const expectedBaseFee = (await alice.provider.getBlock(receipt.blockNumber - 1 + i)).baseFeePerGas;
expect(BigInt(response.baseFeePerGas[i])).toEqual(expectedBaseFee);
Expand Down

0 comments on commit 44a8f79

Please sign in to comment.