Skip to content

Commit

Permalink
comments and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Oct 17, 2024
1 parent 7a75048 commit 7536dfc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion zero/src/bin/leader/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use zero::pre_checks::check_previous_proof_and_checkpoint;
use zero::proof_types::GeneratedBlockProof;
use zero::prover::{self, BlockProverInput, ProverConfig};
use zero::rpc;
use zero::rpc::{retry::build_http_retry_provider, RpcType};

use crate::ProofRuntime;

Expand Down
11 changes: 9 additions & 2 deletions zero/src/block_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;

use alloy::rpc::types::eth::BlockId;
use alloy::rpc::types::BlockTransactionsKind;
use alloy::{hex, providers::Provider, transports::Transport};
use alloy::{providers::Provider, transports::Transport};
use anyhow::{anyhow, Result};
use async_stream::try_stream;
use futures::Stream;
Expand Down Expand Up @@ -36,6 +36,9 @@ impl BlockInterval {
/// If end_block is None, the interval is unbounded and will follow from
/// start_block. If start_block == end_block, the interval is a single
/// block. Otherwise the interval is a range from start_block to end_block.
///
/// end_block is treated as inclusive because it may have been specified
/// as a block hash.
pub async fn new<ProviderT, TransportT>(
cached_provider: Arc<CachedProvider<ProviderT, TransportT>>,
start_block: BlockId,
Expand Down Expand Up @@ -91,12 +94,12 @@ impl BlockInterval {
}
}

/// Returns the start block number of the interval.
pub fn get_start_block(&self) -> Result<u64> {
match self {
BlockInterval::SingleBlockId(num) => Ok(*num),
BlockInterval::Range(range) => Ok(range.start),
BlockInterval::FollowFrom { start_block, .. } => Ok(*start_block),
_ => Err(anyhow!("Unknown BlockInterval variant")), // Handle unknown variants
}
}

Expand Down Expand Up @@ -137,6 +140,7 @@ impl BlockInterval {
}
}

/// Converts a [`BlockId`] into a block number by querying the provider.
pub async fn block_to_num<ProviderT, TransportT>(
cached_provider: Arc<CachedProvider<ProviderT, TransportT>>,
block: BlockId,
Expand All @@ -146,9 +150,12 @@ impl BlockInterval {
TransportT: Transport + Clone,
{
let block_num = match block {
// Number already provided
BlockId::Number(num) => num
.as_number()
.ok_or_else(|| anyhow!("invalid block number '{num}'"))?,

// Hash provided, query the provider for the block number.
BlockId::Hash(hash) => {
let block = cached_provider
.get_provider()
Expand Down

0 comments on commit 7536dfc

Please sign in to comment.