feat: remove todo (#20692)

This commit is contained in:
cui
2026-01-05 23:03:46 +08:00
committed by GitHub
parent 0f1bec0ad1
commit 39e2c5167a
2 changed files with 11 additions and 10 deletions

View File

@@ -103,14 +103,15 @@ impl BenchContext {
(bench_args.from, bench_args.to)
};
// If neither `--from` nor `--to` are provided, we will run the benchmark continuously,
// If `--to` are not provided, we will run the benchmark continuously,
// starting at the latest block.
let mut benchmark_mode = BenchMode::new(from, to)?;
let latest_block =
block_provider.get_block_by_number(BlockNumberOrTag::Latest).full().await?.unwrap();
let mut benchmark_mode = BenchMode::new(from, to, latest_block.into_inner().number())?;
let first_block = match benchmark_mode {
BenchMode::Continuous => {
// fetch Latest block
block_provider.get_block_by_number(BlockNumberOrTag::Latest).full().await?.unwrap()
BenchMode::Continuous(start) => {
block_provider.get_block_by_number(start.into()).full().await?.unwrap()
}
BenchMode::Range(ref mut range) => {
match range.next() {

View File

@@ -5,9 +5,8 @@ use std::ops::RangeInclusive;
/// Whether or not the benchmark should run as a continuous stream of payloads.
#[derive(Debug, PartialEq, Eq)]
pub enum BenchMode {
// TODO: just include the start block in `Continuous`
/// Run the benchmark as a continuous stream of payloads, until the benchmark is interrupted.
Continuous,
Continuous(u64),
/// Run the benchmark for a specific range of blocks.
Range(RangeInclusive<u64>),
}
@@ -16,18 +15,19 @@ impl BenchMode {
/// Check if the block number is in the range
pub fn contains(&self, block_number: u64) -> bool {
match self {
Self::Continuous => true,
Self::Continuous(start) => block_number >= *start,
Self::Range(range) => range.contains(&block_number),
}
}
/// Create a [`BenchMode`] from optional `from` and `to` fields.
pub fn new(from: Option<u64>, to: Option<u64>) -> Result<Self, eyre::Error> {
pub fn new(from: Option<u64>, to: Option<u64>, latest_block: u64) -> Result<Self, eyre::Error> {
// If neither `--from` nor `--to` are provided, we will run the benchmark continuously,
// starting at the latest block.
match (from, to) {
(Some(from), Some(to)) => Ok(Self::Range(from..=to)),
(None, None) => Ok(Self::Continuous),
(None, None) => Ok(Self::Continuous(latest_block)),
(Some(start), None) => Ok(Self::Continuous(start)),
_ => {
// both or neither are allowed, everything else is ambiguous
Err(eyre::eyre!("`from` and `to` must be provided together, or not at all."))