Skip to content

Commit dcc9a93

Browse files
apollo_batcher: add storage_reader_server to the batcher
1 parent 4227929 commit dcc9a93

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

crates/apollo_batcher/src/batcher.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use std::sync::Arc;
55
use apollo_batcher_config::config::BatcherConfig;
66
use apollo_batcher_types::batcher_types::{
77
BatcherResult,
8+
BatcherStorageReaderServerHandler,
9+
BatcherStorageRequest,
10+
BatcherStorageResponse,
811
CentralObjects,
912
DecisionReachedInput,
1013
DecisionReachedResponse,
@@ -35,7 +38,13 @@ use apollo_reverts::revert_block;
3538
use apollo_state_sync_types::state_sync_types::SyncBlock;
3639
use apollo_storage::metrics::BATCHER_STORAGE_OPEN_READ_TRANSACTIONS;
3740
use apollo_storage::state::{StateStorageReader, StateStorageWriter};
38-
use apollo_storage::{open_storage_with_metric, StorageReader, StorageResult, StorageWriter};
41+
use apollo_storage::storage_reader_server::StorageReaderServer;
42+
use apollo_storage::{
43+
open_storage_with_metric_and_server,
44+
StorageReader,
45+
StorageResult,
46+
StorageWriter,
47+
};
3948
use async_trait::async_trait;
4049
use blockifier::concurrency::worker_pool::WorkerPool;
4150
use blockifier::state::contract_class_manager::ContractClassManager;
@@ -100,6 +109,11 @@ use crate::utils::{
100109

101110
type OutputStreamReceiver = tokio::sync::mpsc::UnboundedReceiver<InternalConsensusTransaction>;
102111
type InputStreamSender = tokio::sync::mpsc::Sender<InternalConsensusTransaction>;
112+
type BatcherStorageReaderServer = StorageReaderServer<
113+
BatcherStorageReaderServerHandler,
114+
BatcherStorageRequest,
115+
BatcherStorageResponse,
116+
>;
103117

104118
pub struct Batcher {
105119
pub config: BatcherConfig,
@@ -145,6 +159,11 @@ pub struct Batcher {
145159
/// The proposal commitment of the previous height.
146160
/// This is returned by the decision_reached function.
147161
prev_proposal_commitment: Option<(BlockNumber, ProposalCommitment)>,
162+
163+
// TODO(Nadin): Remove #[allow(dead_code)].
164+
/// Optional storage reader server for handling remote storage reader queries.
165+
#[allow(dead_code)]
166+
storage_reader_server: Option<BatcherStorageReaderServer>,
148167
}
149168

150169
impl Batcher {
@@ -158,6 +177,7 @@ impl Batcher {
158177
transaction_converter: TransactionConverter,
159178
block_builder_factory: Box<dyn BlockBuilderFactoryTrait>,
160179
pre_confirmed_block_writer_factory: Box<dyn PreconfirmedBlockWriterFactoryTrait>,
180+
storage_reader_server: Option<BatcherStorageReaderServer>,
161181
) -> Self {
162182
Self {
163183
config,
@@ -177,6 +197,7 @@ impl Batcher {
177197
// Allow the first few proposals to be without L1 txs while system starts up.
178198
proposals_counter: 1,
179199
prev_proposal_commitment: None,
200+
storage_reader_server,
180201
}
181202
}
182203

@@ -1020,9 +1041,13 @@ pub fn create_batcher(
10201041
class_manager_client: SharedClassManagerClient,
10211042
pre_confirmed_cende_client: Arc<dyn PreconfirmedCendeClientTrait>,
10221043
) -> Batcher {
1023-
let (storage_reader, storage_writer) =
1024-
open_storage_with_metric(config.storage.clone(), &BATCHER_STORAGE_OPEN_READ_TRANSACTIONS)
1025-
.expect("Failed to open batcher's storage");
1044+
let (storage_reader, storage_writer, storage_reader_server) =
1045+
open_storage_with_metric_and_server(
1046+
config.storage.clone(),
1047+
&BATCHER_STORAGE_OPEN_READ_TRANSACTIONS,
1048+
config.storage_reader_server_config.clone(),
1049+
)
1050+
.expect("Failed to open batcher's storage");
10261051

10271052
let execute_config = &config.block_builder_config.execute_config;
10281053
let worker_pool = Arc::new(WorkerPool::start(execute_config));
@@ -1053,6 +1078,7 @@ pub fn create_batcher(
10531078
transaction_converter,
10541079
block_builder_factory,
10551080
pre_confirmed_block_writer_factory,
1081+
storage_reader_server,
10561082
)
10571083
}
10581084

crates/apollo_batcher/src/batcher_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ async fn create_batcher(mock_dependencies: MockDependencies) -> Batcher {
179179
),
180180
Box::new(mock_dependencies.block_builder_factory),
181181
Box::new(mock_dependencies.pre_confirmed_block_writer_factory),
182+
None,
182183
);
183184
// Call post-creation functionality (e.g., metrics registration).
184185
batcher.start().await;

0 commit comments

Comments
 (0)