Skip to content

Commit abd2732

Browse files
apollo_storage, apollo_batcher: spawn storage reader server independently
1 parent 4f29510 commit abd2732

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

crates/apollo_batcher/src/batcher.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,6 @@ pub struct Batcher {
173173
/// This is returned by the decision_reached function.
174174
prev_proposal_commitment: Option<(BlockNumber, ProposalCommitment)>,
175175

176-
/// Optional storage reader server for handling remote storage reader queries.
177-
/// Kept alive to maintain the server running.
178-
#[allow(dead_code)]
179-
storage_reader_server: Option<GenericStorageReaderServer>,
180176
commitment_manager: ApolloCommitmentManager,
181177
}
182178

@@ -192,7 +188,6 @@ impl Batcher {
192188
transaction_converter: TransactionConverter,
193189
block_builder_factory: Box<dyn BlockBuilderFactoryTrait>,
194190
pre_confirmed_block_writer_factory: Box<dyn PreconfirmedBlockWriterFactoryTrait>,
195-
storage_reader_server: Option<GenericStorageReaderServer>,
196191
commitment_manager: ApolloCommitmentManager,
197192
) -> Self {
198193
Self {
@@ -214,7 +209,6 @@ impl Batcher {
214209
// Allow the first few proposals to be without L1 txs while system starts up.
215210
proposals_counter: 1,
216211
prev_proposal_commitment: None,
217-
storage_reader_server,
218212
commitment_manager,
219213
}
220214
}
@@ -1271,6 +1265,8 @@ pub async fn create_batcher(
12711265
)
12721266
.expect("Failed to open batcher's storage");
12731267

1268+
GenericStorageReaderServer::spawn_if_enabled(storage_reader_server);
1269+
12741270
let execute_config = &config.block_builder_config.execute_config;
12751271
let worker_pool = Arc::new(WorkerPool::start(execute_config));
12761272
let pre_confirmed_block_writer_factory = Box::new(PreconfirmedBlockWriterFactory {
@@ -1310,7 +1306,6 @@ pub async fn create_batcher(
13101306
transaction_converter,
13111307
block_builder_factory,
13121308
pre_confirmed_block_writer_factory,
1313-
storage_reader_server,
13141309
commitment_manager,
13151310
)
13161311
}

crates/apollo_batcher/src/batcher_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ async fn create_batcher_impl<R: BatcherStorageReader + 'static>(
194194
TransactionConverter::new(clients.class_manager_client, CHAIN_ID_FOR_TESTS.clone()),
195195
Box::new(clients.block_builder_factory),
196196
Box::new(clients.pre_confirmed_block_writer_factory),
197-
None,
198197
commitment_manager,
199198
);
200199
// Call post-creation functionality (e.g., metrics registration).

crates/apollo_storage/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ starknet-types-core = { workspace = true, features = ["papyrus-serialization"] }
3636
starknet_api.workspace = true
3737
tempfile = { workspace = true, optional = true }
3838
thiserror.workspace = true
39+
tokio.workspace = true
3940
tower = { workspace = true, optional = true }
4041
tracing = { workspace = true, features = ["log"] }
4142
validator = { workspace = true, features = ["derive"] }

crates/apollo_storage/src/storage_reader_server.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ where
160160
StorageError::IOError(io::Error::other(e))
161161
})
162162
}
163+
164+
/// Spawns the storage reader server in a background task if it's enabled.
165+
pub fn spawn_if_enabled(server: Option<Self>)
166+
where
167+
RequestHandler: Send + Sync + 'static,
168+
Request: Send + Sync + 'static,
169+
Response: Send + Sync + 'static,
170+
{
171+
if let Some(server) = server {
172+
tokio::spawn(async move {
173+
if let Err(e) = server.run().await {
174+
tracing::error!("Storage reader server error: {:?}", e);
175+
}
176+
});
177+
}
178+
}
163179
}
164180

165181
/// Axum handler for storage query requests.

0 commit comments

Comments
 (0)