From b7a723e9844261a9784365b38340051aa544a733 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Sun, 12 Jan 2025 10:28:56 +0200 Subject: [PATCH] refactor(papyrus_p2p_sync): rename stream builder --- crates/papyrus_p2p_sync/src/client/class.rs | 4 ++-- crates/papyrus_p2p_sync/src/client/header.rs | 4 ++-- crates/papyrus_p2p_sync/src/client/mod.rs | 4 ++-- crates/papyrus_p2p_sync/src/client/state_diff.rs | 9 ++------- crates/papyrus_p2p_sync/src/client/stream_builder.rs | 6 +++--- crates/papyrus_p2p_sync/src/client/transaction.rs | 4 ++-- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/crates/papyrus_p2p_sync/src/client/class.rs b/crates/papyrus_p2p_sync/src/client/class.rs index cf93e49487..f87813f100 100644 --- a/crates/papyrus_p2p_sync/src/client/class.rs +++ b/crates/papyrus_p2p_sync/src/client/class.rs @@ -17,8 +17,8 @@ use super::stream_builder::{ BadPeerError, BlockData, BlockNumberLimit, - DataStreamBuilder, ParseDataError, + StreamBuilder, }; use super::{P2PSyncClientError, NETWORK_DATA_TIMEOUT}; @@ -44,7 +44,7 @@ impl BlockData for (DeclaredClasses, DeprecatedDeclaredClasses, BlockNumber) { pub(crate) struct ClassStreamBuilder; -impl DataStreamBuilder<(ApiContractClass, ClassHash)> for ClassStreamBuilder { +impl StreamBuilder<(ApiContractClass, ClassHash)> for ClassStreamBuilder { type Output = (DeclaredClasses, DeprecatedDeclaredClasses, BlockNumber); const TYPE_DESCRIPTION: &'static str = "classes"; diff --git a/crates/papyrus_p2p_sync/src/client/header.rs b/crates/papyrus_p2p_sync/src/client/header.rs index c74948ea95..6f502d00bd 100644 --- a/crates/papyrus_p2p_sync/src/client/header.rs +++ b/crates/papyrus_p2p_sync/src/client/header.rs @@ -16,8 +16,8 @@ use super::stream_builder::{ BadPeerError, BlockData, BlockNumberLimit, - DataStreamBuilder, ParseDataError, + StreamBuilder, }; use super::{P2PSyncClientError, ALLOWED_SIGNATURES_LENGTH, NETWORK_DATA_TIMEOUT}; @@ -65,7 +65,7 @@ impl BlockData for SignedBlockHeader { pub(crate) struct HeaderStreamBuilder; -impl DataStreamBuilder for HeaderStreamBuilder { +impl StreamBuilder for HeaderStreamBuilder { type Output = SignedBlockHeader; const TYPE_DESCRIPTION: &'static str = "headers"; diff --git a/crates/papyrus_p2p_sync/src/client/mod.rs b/crates/papyrus_p2p_sync/src/client/mod.rs index 53646f748d..e2f7166e62 100644 --- a/crates/papyrus_p2p_sync/src/client/mod.rs +++ b/crates/papyrus_p2p_sync/src/client/mod.rs @@ -44,7 +44,7 @@ use starknet_api::core::ClassHash; use starknet_api::transaction::FullTransaction; use starknet_state_sync_types::state_sync_types::SyncBlock; use state_diff::StateDiffStreamBuilder; -use stream_builder::{DataStreamBuilder, DataStreamResult}; +use stream_builder::{StreamBuilder, StreamResult}; use tokio_stream::StreamExt; use tracing::{info, instrument}; use transaction::TransactionStreamFactory; @@ -173,7 +173,7 @@ impl P2PSyncClientChannels { storage_reader: StorageReader, config: P2PSyncClientConfig, internal_blocks_receivers: InternalBlocksReceivers, - ) -> impl Stream + Send + 'static { + ) -> impl Stream + Send + 'static { let header_stream = HeaderStreamBuilder::create_stream( self.header_sender, storage_reader.clone(), diff --git a/crates/papyrus_p2p_sync/src/client/state_diff.rs b/crates/papyrus_p2p_sync/src/client/state_diff.rs index 362daca121..0dff444757 100644 --- a/crates/papyrus_p2p_sync/src/client/state_diff.rs +++ b/crates/papyrus_p2p_sync/src/client/state_diff.rs @@ -15,12 +15,7 @@ use starknet_api::state::ThinStateDiff; use starknet_state_sync_types::state_sync_types::SyncBlock; use super::stream_builder::BadPeerError; -use crate::client::stream_builder::{ - BlockData, - BlockNumberLimit, - DataStreamBuilder, - ParseDataError, -}; +use crate::client::stream_builder::{BlockData, BlockNumberLimit, ParseDataError, StreamBuilder}; use crate::client::{P2PSyncClientError, NETWORK_DATA_TIMEOUT}; impl BlockData for (ThinStateDiff, BlockNumber) { @@ -38,7 +33,7 @@ impl BlockData for (ThinStateDiff, BlockNumber) { pub(crate) struct StateDiffStreamBuilder; -impl DataStreamBuilder for StateDiffStreamBuilder { +impl StreamBuilder for StateDiffStreamBuilder { type Output = (ThinStateDiff, BlockNumber); const TYPE_DESCRIPTION: &'static str = "state diffs"; diff --git a/crates/papyrus_p2p_sync/src/client/stream_builder.rs b/crates/papyrus_p2p_sync/src/client/stream_builder.rs index c785cdc2e4..98b61cd85a 100644 --- a/crates/papyrus_p2p_sync/src/client/stream_builder.rs +++ b/crates/papyrus_p2p_sync/src/client/stream_builder.rs @@ -20,7 +20,7 @@ use tracing::{debug, info, warn}; use super::{P2PSyncClientError, STEP}; -pub type DataStreamResult = Result, P2PSyncClientError>; +pub type StreamResult = Result, P2PSyncClientError>; pub(crate) trait BlockData: Send { fn write_to_storage( @@ -36,7 +36,7 @@ pub(crate) enum BlockNumberLimit { StateDiffMarker, } -pub(crate) trait DataStreamBuilder +pub(crate) trait StreamBuilder where InputFromNetwork: Send + 'static, DataOrFin: TryFrom, Error = ProtobufConversionError>, @@ -100,7 +100,7 @@ where mut internal_block_receiver: Option>, wait_period_for_new_data: Duration, num_blocks_per_query: u64, - ) -> BoxStream<'static, DataStreamResult> + ) -> BoxStream<'static, StreamResult> where TQuery: From + Send + 'static, Vec: From, diff --git a/crates/papyrus_p2p_sync/src/client/transaction.rs b/crates/papyrus_p2p_sync/src/client/transaction.rs index deea071ae3..5180842be2 100644 --- a/crates/papyrus_p2p_sync/src/client/transaction.rs +++ b/crates/papyrus_p2p_sync/src/client/transaction.rs @@ -14,8 +14,8 @@ use super::stream_builder::{ BadPeerError, BlockData, BlockNumberLimit, - DataStreamBuilder, ParseDataError, + StreamBuilder, }; use super::{P2PSyncClientError, NETWORK_DATA_TIMEOUT}; @@ -30,7 +30,7 @@ impl BlockData for (BlockBody, BlockNumber) { pub(crate) struct TransactionStreamFactory; -impl DataStreamBuilder for TransactionStreamFactory { +impl StreamBuilder for TransactionStreamFactory { // TODO(Eitan): Add events protocol to BlockBody or split their write to storage type Output = (BlockBody, BlockNumber);