From 79f88821b70d556b697535b0e7b90c8172d26762 Mon Sep 17 00:00:00 2001 From: segfault-magnet Date: Sat, 28 Sep 2024 12:18:30 +0200 Subject: [PATCH] pr comment --- committer/src/setup.rs | 8 +-- packages/eth/src/blob_encoding/encoder.rs | 2 +- packages/services/src/block_importer.rs | 72 ++++------------------- packages/services/src/lib.rs | 6 +- 4 files changed, 19 insertions(+), 69 deletions(-) diff --git a/committer/src/setup.rs b/committer/src/setup.rs index 814134de..bae5f6cb 100644 --- a/committer/src/setup.rs +++ b/committer/src/setup.rs @@ -4,8 +4,8 @@ use clock::SystemClock; use eth::{AwsConfig, Eip4844BlobEncoder}; use metrics::{prometheus::Registry, HealthChecker, RegistersMetrics}; use services::{ - BlockBundler, BlockBundlerConfig, BlockCommitter, BlockImporterConfig, BlockValidator, - CommitListener, Runner, WalletBalanceTracker, + BlockBundler, BlockBundlerConfig, BlockCommitter, BlockValidator, CommitListener, Runner, + WalletBalanceTracker, }; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; @@ -147,9 +147,7 @@ pub fn block_importer( storage, fuel, validator, - BlockImporterConfig { - lookback_window: config.app.bundle.block_height_lookback, - }, + config.app.bundle.block_height_lookback, ); schedule_polling( diff --git a/packages/eth/src/blob_encoding/encoder.rs b/packages/eth/src/blob_encoding/encoder.rs index bf7c8d0b..0be34ed3 100644 --- a/packages/eth/src/blob_encoding/encoder.rs +++ b/packages/eth/src/blob_encoding/encoder.rs @@ -22,7 +22,7 @@ pub struct Eip4844BlobEncoder; impl Eip4844BlobEncoder { #[cfg(feature = "test-helpers")] pub const FRAGMENT_SIZE: usize = - FIELD_ELEMENTS_PER_BLOB as usize * FIELD_ELEMENT_BYTES as usize; + FIELD_ELEMENTS_PER_BLOB as usize * alloy::eips::eip4844::FIELD_ELEMENT_BYTES as usize; pub(crate) fn decode( fragments: impl IntoIterator, diff --git a/packages/services/src/block_importer.rs b/packages/services/src/block_importer.rs index 0d83faf4..3c00e070 100644 --- a/packages/services/src/block_importer.rs +++ b/packages/services/src/block_importer.rs @@ -9,20 +9,6 @@ use tracing::info; use crate::{validator::Validator, Result, Runner}; -#[derive(Debug, Clone, Copy)] -pub struct Config { - pub lookback_window: u32, -} - -#[cfg(test)] -impl Default for Config { - fn default() -> Self { - Self { - lookback_window: 1000, - } - } -} - /// The `BlockImporter` is responsible for importing blocks from the Fuel blockchain /// into local storage. It fetches blocks from the Fuel API, validates them, /// and stores them if they are not already present. @@ -30,7 +16,7 @@ pub struct BlockImporter { storage: Db, fuel_api: FuelApi, block_validator: BlockValidator, - config: Config, + lookback_window: u32, } impl BlockImporter { @@ -39,13 +25,13 @@ impl BlockImporter { storage: Db, fuel_api: FuelApi, block_validator: BlockValidator, - config: Config, + lookback_window: u32, ) -> Self { Self { storage, fuel_api, block_validator, - config, + lookback_window, } } } @@ -166,7 +152,7 @@ where { async fn run(&mut self) -> Result<()> { let chain_height = self.fuel_api.latest_height().await?; - let starting_height = chain_height.saturating_sub(self.config.lookback_window); + let starting_height = chain_height.saturating_sub(self.lookback_window); for range in self .storage @@ -220,12 +206,7 @@ mod tests { let fuel_mock = test_utils::mocks::fuel::these_blocks_exist(vec![block.clone()], true); let block_validator = BlockValidator::new(*secret_key.public_key().hash()); - let mut importer = BlockImporter::new( - setup.db(), - fuel_mock, - block_validator, - Config { lookback_window: 0 }, - ); + let mut importer = BlockImporter::new(setup.db(), fuel_mock, block_validator, 0); // when importer.run().await?; @@ -258,12 +239,7 @@ mod tests { let fuel_mock = test_utils::mocks::fuel::these_blocks_exist(vec![block.clone()], true); - let mut importer = BlockImporter::new( - setup.db(), - fuel_mock, - block_validator, - Config { lookback_window: 0 }, - ); + let mut importer = BlockImporter::new(setup.db(), fuel_mock, block_validator, 0); // when let result = importer.run().await; @@ -311,8 +287,7 @@ mod tests { let fuel_mock = test_utils::mocks::fuel::these_blocks_exist(new_blocks.clone(), true); let block_validator = BlockValidator::new(*secret_key.public_key().hash()); - let mut importer = - BlockImporter::new(setup.db(), fuel_mock, block_validator, Config::default()); + let mut importer = BlockImporter::new(setup.db(), fuel_mock, block_validator, 1000); // when importer.run().await?; @@ -353,14 +328,7 @@ mod tests { let fuel_mock = test_utils::mocks::fuel::these_blocks_exist(new_blocks.clone(), true); let block_validator = BlockValidator::new(*secret_key.public_key().hash()); - let mut importer = BlockImporter::new( - setup.db(), - fuel_mock, - block_validator, - Config { - lookback_window: 5, // Example lookback_window - }, - ); + let mut importer = BlockImporter::new(setup.db(), fuel_mock, block_validator, 5); // when importer.run().await?; @@ -399,12 +367,7 @@ mod tests { let fuel_mock = test_utils::mocks::fuel::these_blocks_exist(fuel_blocks, true); let block_validator = BlockValidator::new(*secret_key.public_key().hash()); - let mut importer = BlockImporter::new( - setup.db(), - fuel_mock, - block_validator, - Config { lookback_window: 0 }, - ); + let mut importer = BlockImporter::new(setup.db(), fuel_mock, block_validator, 0); // when importer.run().await?; @@ -435,12 +398,8 @@ mod tests { let fuel_mock = test_utils::mocks::fuel::these_blocks_exist(blocks_to_import, true); let block_validator = BlockValidator::new(*secret_key.public_key().hash()); - let mut importer = BlockImporter::new( - setup.db(), - fuel_mock, - block_validator, - Config { lookback_window }, - ); + let mut importer = + BlockImporter::new(setup.db(), fuel_mock, block_validator, lookback_window); // when importer.run().await?; @@ -512,14 +471,7 @@ mod tests { let block_validator = BlockValidator::new(*secret_key.public_key().hash()); - let mut importer = BlockImporter::new( - setup.db(), - fuel_mock, - block_validator, - Config { - lookback_window: 101, - }, - ); + let mut importer = BlockImporter::new(setup.db(), fuel_mock, block_validator, 101); // when importer.run().await?; diff --git a/packages/services/src/lib.rs b/packages/services/src/lib.rs index 9a983c10..6f48bbba 100644 --- a/packages/services/src/lib.rs +++ b/packages/services/src/lib.rs @@ -14,7 +14,7 @@ pub use block_bundler::{ BlockBundler, Config as BlockBundlerConfig, }; pub use block_committer::BlockCommitter; -pub use block_importer::{BlockImporter, Config as BlockImporterConfig}; +pub use block_importer::BlockImporter; pub use commit_listener::CommitListener; pub use health_reporter::HealthReporter; pub use state_committer::{Config as StateCommitterConfig, StateCommitter}; @@ -112,7 +112,7 @@ pub(crate) mod test_utils { use super::Runner; use crate::{ block_bundler::bundler::Factory, - block_importer::{self, encode_blocks, Config}, + block_importer::{self, encode_blocks}, BlockBundler, BlockBundlerConfig, BlockImporter, BlockValidator, StateCommitter, StateListener, }; @@ -549,7 +549,7 @@ pub(crate) mod test_utils { let mock = mocks::fuel::these_blocks_exist(fuel_blocks.clone(), false); ( - BlockImporter::new(self.db(), mock, block_validator, Config::default()), + BlockImporter::new(self.db(), mock, block_validator, 1000), ImportedBlocks { fuel_blocks, secret_key,