From ee0e600e67e5317b0bdf515e66f99422a2f2f53c Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Tue, 10 Dec 2024 11:50:00 +0200 Subject: [PATCH] chore(papyrus_p2p_sync): add block data receiver to p2psyncclient --- Cargo.lock | 1 + crates/papyrus_node/src/run.rs | 1 + crates/papyrus_p2p_sync/Cargo.toml | 1 + crates/papyrus_p2p_sync/src/client/mod.rs | 8 +++++++- crates/papyrus_p2p_sync/src/client/test_utils.rs | 2 ++ 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 050c36691c9..e20ff554466 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7575,6 +7575,7 @@ dependencies = [ "serde", "starknet-types-core", "starknet_api", + "starknet_state_sync_types", "static_assertions", "thiserror", "tokio", diff --git a/crates/papyrus_node/src/run.rs b/crates/papyrus_node/src/run.rs index e26b3797595..d261ff4d7cb 100644 --- a/crates/papyrus_node/src/run.rs +++ b/crates/papyrus_node/src/run.rs @@ -304,6 +304,7 @@ async fn spawn_sync_client( storage_reader, storage_writer, p2p_sync_client_channels, + Box::pin(futures::stream::pending()), ); tokio::spawn(async move { Ok(p2p_sync.run().await?) }) } diff --git a/crates/papyrus_p2p_sync/Cargo.toml b/crates/papyrus_p2p_sync/Cargo.toml index 653fbd259b4..f39a8bc76b5 100644 --- a/crates/papyrus_p2p_sync/Cargo.toml +++ b/crates/papyrus_p2p_sync/Cargo.toml @@ -22,6 +22,7 @@ papyrus_storage.workspace = true rand.workspace = true serde.workspace = true starknet_api.workspace = true +starknet_state_sync_types.workspace = true starknet-types-core.workspace = true thiserror.workspace = true tokio.workspace = true diff --git a/crates/papyrus_p2p_sync/src/client/mod.rs b/crates/papyrus_p2p_sync/src/client/mod.rs index 01e13465f72..bf16e791941 100644 --- a/crates/papyrus_p2p_sync/src/client/mod.rs +++ b/crates/papyrus_p2p_sync/src/client/mod.rs @@ -19,6 +19,7 @@ use std::time::Duration; use class::ClassStreamBuilder; use futures::channel::mpsc::SendError; +use futures::stream::BoxStream; use futures::Stream; use header::HeaderStreamBuilder; use papyrus_common::pending_classes::ApiContractClass; @@ -40,11 +41,13 @@ use serde::{Deserialize, Serialize}; use starknet_api::block::BlockNumber; 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 tokio_stream::StreamExt; use tracing::instrument; use transaction::TransactionStreamFactory; + const STEP: u64 = 1; const ALLOWED_SIGNATURES_LENGTH: usize = 1; @@ -226,6 +229,8 @@ pub struct P2PSyncClient { storage_reader: StorageReader, storage_writer: StorageWriter, p2p_sync_channels: P2PSyncClientChannels, + #[allow(dead_code)] + block_data_receiver: BoxStream<'static, SyncBlock>, } impl P2PSyncClient { @@ -234,8 +239,9 @@ impl P2PSyncClient { storage_reader: StorageReader, storage_writer: StorageWriter, p2p_sync_channels: P2PSyncClientChannels, + block_data_receiver: BoxStream<'static, SyncBlock>, ) -> Self { - Self { config, storage_reader, storage_writer, p2p_sync_channels } + Self { config, storage_reader, storage_writer, p2p_sync_channels, block_data_receiver } } #[instrument(skip(self), level = "debug", err)] diff --git a/crates/papyrus_p2p_sync/src/client/test_utils.rs b/crates/papyrus_p2p_sync/src/client/test_utils.rs index 006ce510f96..db62be58e91 100644 --- a/crates/papyrus_p2p_sync/src/client/test_utils.rs +++ b/crates/papyrus_p2p_sync/src/client/test_utils.rs @@ -112,6 +112,7 @@ pub fn setup() -> TestArgs { storage_reader.clone(), storage_writer, p2p_sync_channels, + Box::pin(futures::stream::pending()), ); TestArgs { p2p_sync, @@ -194,6 +195,7 @@ pub async fn run_test(max_query_lengths: HashMap, actions: Vec