Skip to content

Commit

Permalink
update other occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Sep 20, 2023
1 parent 467d466 commit 53a8f4c
Showing 1 changed file with 29 additions and 77 deletions.
106 changes: 29 additions & 77 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::{
formatter,
system_contracts::{self, SystemContracts},
utils::{
adjust_l1_gas_price_for_tx, derive_gas_estimation_overhead, to_human_size, IntoBoxedFuture,
self, adjust_l1_gas_price_for_tx, derive_gas_estimation_overhead, to_human_size,
IntoBoxedFuture,
},
};
use clap::Parser;
Expand Down Expand Up @@ -1387,74 +1388,30 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthNamespaceT for
Ok(r) => r,
Err(_) => return Err(into_jsrpc_error(Web3Error::InternalError)),
};
match block_number {
zksync_types::api::BlockNumber::Latest
| zksync_types::api::BlockNumber::Pending
| zksync_types::api::BlockNumber::Finalized
| zksync_types::api::BlockNumber::Committed => reader
.block_hashes
.get(&reader.current_miniblock)
.and_then(|hash| reader.blocks.get(hash))
.cloned()
.or_else(|| {
reader
.fork_storage
.inner
.read()
.expect("failed reading fork storage")
.fork
.as_ref()
.and_then(|fork| {
fork.fork_source
.get_block_by_number(block_number, true)
.ok()
.flatten()
})
}),
zksync_types::api::BlockNumber::Number(ask_number) => {
let block = reader
.block_hashes
.get(&ask_number.as_u64())
.and_then(|hash| reader.blocks.get(hash))
.cloned()
.or_else(|| {
reader
.fork_storage
.inner
.read()
.expect("failed reading fork storage")
.fork
.as_ref()
.and_then(|fork| {
fork.fork_source
.get_block_by_number(block_number, true)
.ok()
.flatten()
})
});
block
}
zksync_types::api::BlockNumber::Earliest => reader
.block_hashes
.get(&0)
.and_then(|hash| reader.blocks.get(hash))
.cloned()
.or_else(|| {
reader
.fork_storage
.inner
.read()
.expect("failed reading fork storage")
.fork
.as_ref()
.and_then(|fork| {
fork.fork_source
.get_block_by_number(block_number, true)
.ok()
.flatten()
})
}),
}
let number =
utils::to_real_block_number(block_number, U64::from(reader.current_miniblock))
.as_u64();

reader
.block_hashes
.get(&number)
.and_then(|hash| reader.blocks.get(hash))
.cloned()
.or_else(|| {
reader
.fork_storage
.inner
.read()
.expect("failed reading fork storage")
.fork
.as_ref()
.and_then(|fork| {
fork.fork_source
.get_block_by_number(block_number, true)
.ok()
.flatten()
})
})
};

match maybe_block {
Expand Down Expand Up @@ -2026,14 +1983,9 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthNamespaceT for
Ok(r) => r,
Err(_) => return Err(into_jsrpc_error(Web3Error::InternalError)),
};
let number = match block_number {
zksync_types::api::BlockNumber::Latest
| zksync_types::api::BlockNumber::Pending
| zksync_types::api::BlockNumber::Finalized
| zksync_types::api::BlockNumber::Committed => reader.current_miniblock,
zksync_types::api::BlockNumber::Number(ask_number) => ask_number.as_u64(),
zksync_types::api::BlockNumber::Earliest => 0,
};
let number =
utils::to_real_block_number(block_number, U64::from(reader.current_miniblock))
.as_u64();

reader
.block_hashes
Expand Down

0 comments on commit 53a8f4c

Please sign in to comment.