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

returns blocks via hashes #8

Closed
wants to merge 5 commits into from
Closed
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
44 changes: 39 additions & 5 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ serde_json = "1.0.67"
bigdecimal = { version = "0.2.0" }
hex = "0.4"
ethabi = "16.0.0"
itertools = "0.10.5"
itertools = "0.10.5"

[dev-dependencies]
httptest = "0.15.4"
11 changes: 10 additions & 1 deletion src/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tokio::runtime::Builder;
use zksync_basic_types::{Address, L1BatchNumber, L2ChainId, MiniblockNumber, H256, U256, U64};

use zksync_types::{
api::{BlockIdVariant, BlockNumber, Transaction},
api::{Block, BlockIdVariant, BlockNumber, Transaction, TransactionVariant},
l2::L2Tx,
StorageKey,
};
Expand Down Expand Up @@ -205,6 +205,13 @@ pub trait ForkSource {
&self,
block_number: MiniblockNumber,
) -> eyre::Result<Vec<zksync_types::Transaction>>;

/// Returns the block for a given hash.
fn get_block_by_hash(
&self,
hash: H256,
full_transactions: bool,
) -> eyre::Result<Option<Block<TransactionVariant>>>;
}

/// Holds the information about the original chain.
Expand All @@ -216,6 +223,7 @@ pub struct ForkDetails<S> {
// Block number at which we forked (the next block to create is l1_block + 1)
pub l1_block: L1BatchNumber,
pub l2_miniblock: u64,
pub l2_miniblock_hash: Option<H256>,
pub block_timestamp: u64,
pub overwrite_chain_id: Option<L2ChainId>,
pub l1_gas_price: u64,
Expand Down Expand Up @@ -248,6 +256,7 @@ impl ForkDetails<HttpForkSource> {
l1_block: l1_batch_number,
block_timestamp: block_details.base.timestamp,
l2_miniblock: miniblock,
l2_miniblock_hash: block_details.base.root_hash,
overwrite_chain_id: chain_id,
l1_gas_price: block_details.base.l1_gas_price,
}
Expand Down
10 changes: 10 additions & 0 deletions src/http_fork_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,14 @@ impl ForkSource for HttpForkSource {
block_on(async move { client.get_raw_block_transactions(block_number).await })
.wrap_err("fork http client failed")
}

fn get_block_by_hash(
&self,
hash: zksync_basic_types::H256,
full_transactions: bool,
) -> eyre::Result<Option<zksync_types::api::Block<zksync_types::api::TransactionVariant>>> {
let client = self.create_client();
block_on(async move { client.get_block_by_hash(hash, full_transactions).await })
.wrap_err("fork http client failed")
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pub mod node;
pub mod resolver;
pub mod utils;
pub mod zks;

mod testing;
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mod formatter;
mod http_fork_source;
mod node;
mod resolver;
mod testing;
mod utils;
mod zks;

Expand Down
Loading
Loading