Skip to content

Commit

Permalink
refactor(papyrus_p2p_sync): rename stream builder
Browse files Browse the repository at this point in the history
  • Loading branch information
eitanm-starkware committed Jan 12, 2025
1 parent 3d4a638 commit b7a723e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions crates/papyrus_p2p_sync/src/client/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use super::stream_builder::{
BadPeerError,
BlockData,
BlockNumberLimit,
DataStreamBuilder,
ParseDataError,
StreamBuilder,
};
use super::{P2PSyncClientError, NETWORK_DATA_TIMEOUT};

Expand All @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_p2p_sync/src/client/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use super::stream_builder::{
BadPeerError,
BlockData,
BlockNumberLimit,
DataStreamBuilder,
ParseDataError,
StreamBuilder,
};
use super::{P2PSyncClientError, ALLOWED_SIGNATURES_LENGTH, NETWORK_DATA_TIMEOUT};

Expand Down Expand Up @@ -65,7 +65,7 @@ impl BlockData for SignedBlockHeader {

pub(crate) struct HeaderStreamBuilder;

impl DataStreamBuilder<SignedBlockHeader> for HeaderStreamBuilder {
impl StreamBuilder<SignedBlockHeader> for HeaderStreamBuilder {
type Output = SignedBlockHeader;

const TYPE_DESCRIPTION: &'static str = "headers";
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_p2p_sync/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,7 +173,7 @@ impl P2PSyncClientChannels {
storage_reader: StorageReader,
config: P2PSyncClientConfig,
internal_blocks_receivers: InternalBlocksReceivers,
) -> impl Stream<Item = DataStreamResult> + Send + 'static {
) -> impl Stream<Item = StreamResult> + Send + 'static {
let header_stream = HeaderStreamBuilder::create_stream(
self.header_sender,
storage_reader.clone(),
Expand Down
9 changes: 2 additions & 7 deletions crates/papyrus_p2p_sync/src/client/state_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -38,7 +33,7 @@ impl BlockData for (ThinStateDiff, BlockNumber) {

pub(crate) struct StateDiffStreamBuilder;

impl DataStreamBuilder<StateDiffChunk> for StateDiffStreamBuilder {
impl StreamBuilder<StateDiffChunk> for StateDiffStreamBuilder {
type Output = (ThinStateDiff, BlockNumber);

const TYPE_DESCRIPTION: &'static str = "state diffs";
Expand Down
6 changes: 3 additions & 3 deletions crates/papyrus_p2p_sync/src/client/stream_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tracing::{debug, info, warn};

use super::{P2PSyncClientError, STEP};

pub type DataStreamResult = Result<Box<dyn BlockData>, P2PSyncClientError>;
pub type StreamResult = Result<Box<dyn BlockData>, P2PSyncClientError>;

pub(crate) trait BlockData: Send {
fn write_to_storage(
Expand All @@ -36,7 +36,7 @@ pub(crate) enum BlockNumberLimit {
StateDiffMarker,
}

pub(crate) trait DataStreamBuilder<InputFromNetwork>
pub(crate) trait StreamBuilder<InputFromNetwork>
where
InputFromNetwork: Send + 'static,
DataOrFin<InputFromNetwork>: TryFrom<Vec<u8>, Error = ProtobufConversionError>,
Expand Down Expand Up @@ -100,7 +100,7 @@ where
mut internal_block_receiver: Option<Receiver<(BlockNumber, SyncBlock)>>,
wait_period_for_new_data: Duration,
num_blocks_per_query: u64,
) -> BoxStream<'static, DataStreamResult>
) -> BoxStream<'static, StreamResult>
where
TQuery: From<Query> + Send + 'static,
Vec<u8>: From<TQuery>,
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_p2p_sync/src/client/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use super::stream_builder::{
BadPeerError,
BlockData,
BlockNumberLimit,
DataStreamBuilder,
ParseDataError,
StreamBuilder,
};
use super::{P2PSyncClientError, NETWORK_DATA_TIMEOUT};

Expand All @@ -30,7 +30,7 @@ impl BlockData for (BlockBody, BlockNumber) {

pub(crate) struct TransactionStreamFactory;

impl DataStreamBuilder<FullTransaction> for TransactionStreamFactory {
impl StreamBuilder<FullTransaction> for TransactionStreamFactory {
// TODO(Eitan): Add events protocol to BlockBody or split their write to storage
type Output = (BlockBody, BlockNumber);

Expand Down

0 comments on commit b7a723e

Please sign in to comment.