@@ -5,6 +5,9 @@ use std::sync::Arc;
55use apollo_batcher_config:: config:: BatcherConfig ;
66use apollo_batcher_types:: batcher_types:: {
77 BatcherResult ,
8+ BatcherStorageReaderServerHandler ,
9+ BatcherStorageRequest ,
10+ BatcherStorageResponse ,
811 CentralObjects ,
912 DecisionReachedInput ,
1013 DecisionReachedResponse ,
@@ -35,6 +38,7 @@ use apollo_reverts::revert_block;
3538use apollo_state_sync_types:: state_sync_types:: SyncBlock ;
3639use apollo_storage:: metrics:: BATCHER_STORAGE_OPEN_READ_TRANSACTIONS ;
3740use apollo_storage:: state:: { StateStorageReader , StateStorageWriter } ;
41+ use apollo_storage:: storage_reader_server:: { create_storage_reader_server, StorageReaderServer } ;
3842use apollo_storage:: { open_storage_with_metric, StorageReader , StorageResult , StorageWriter } ;
3943use async_trait:: async_trait;
4044use blockifier:: concurrency:: worker_pool:: WorkerPool ;
@@ -145,6 +149,14 @@ pub struct Batcher {
145149 /// The proposal commitment of the previous height.
146150 /// This is returned by the decision_reached function.
147151 prev_proposal_commitment : Option < ( BlockNumber , ProposalCommitment ) > ,
152+ /// Optional HTTP server to expose storage queries remotely.
153+ storage_reader_server : Option <
154+ StorageReaderServer <
155+ BatcherStorageReaderServerHandler ,
156+ BatcherStorageRequest ,
157+ BatcherStorageResponse ,
158+ > ,
159+ > ,
148160}
149161
150162impl Batcher {
@@ -158,6 +170,13 @@ impl Batcher {
158170 transaction_converter : TransactionConverter ,
159171 block_builder_factory : Box < dyn BlockBuilderFactoryTrait > ,
160172 pre_confirmed_block_writer_factory : Box < dyn PreconfirmedBlockWriterFactoryTrait > ,
173+ storage_reader_server : Option <
174+ StorageReaderServer <
175+ BatcherStorageReaderServerHandler ,
176+ BatcherStorageRequest ,
177+ BatcherStorageResponse ,
178+ > ,
179+ > ,
161180 ) -> Self {
162181 Self {
163182 config,
@@ -177,6 +196,7 @@ impl Batcher {
177196 // Allow the first few proposals to be without L1 txs while system starts up.
178197 proposals_counter : 1 ,
179198 prev_proposal_commitment : None ,
199+ storage_reader_server,
180200 }
181201 }
182202
@@ -1024,6 +1044,16 @@ pub fn create_batcher(
10241044 open_storage_with_metric ( config. storage . clone ( ) , & BATCHER_STORAGE_OPEN_READ_TRANSACTIONS )
10251045 . expect ( "Failed to open batcher's storage" ) ;
10261046
1047+ let storage_reader_server = create_storage_reader_server :: <
1048+ BatcherStorageReaderServerHandler ,
1049+ BatcherStorageRequest ,
1050+ BatcherStorageResponse ,
1051+ > (
1052+ storage_reader. clone ( ) ,
1053+ config. storage_reader_server_config . socket ,
1054+ config. storage_reader_server_config . enable ,
1055+ ) ;
1056+
10271057 let execute_config = & config. block_builder_config . execute_config ;
10281058 let worker_pool = Arc :: new ( WorkerPool :: start ( execute_config) ) ;
10291059 let pre_confirmed_block_writer_factory = Box :: new ( PreconfirmedBlockWriterFactory {
@@ -1053,6 +1083,7 @@ pub fn create_batcher(
10531083 transaction_converter,
10541084 block_builder_factory,
10551085 pre_confirmed_block_writer_factory,
1086+ storage_reader_server,
10561087 )
10571088}
10581089
@@ -1108,6 +1139,17 @@ impl BatcherStorageWriter for StorageWriter {
11081139impl ComponentStarter for Batcher {
11091140 async fn start ( & mut self ) {
11101141 default_component_start_fn :: < Self > ( ) . await ;
1142+
1143+ // Start the storage reader server if configured
1144+ if let Some ( server) = self . storage_reader_server . take ( ) {
1145+ tokio:: spawn ( async move {
1146+ if let Err ( e) = server. run ( ) . await {
1147+ error ! ( "Batcher storage reader server error: {}" , e) ;
1148+ }
1149+ } ) ;
1150+ info ! ( "Batcher storage reader server started" ) ;
1151+ }
1152+
11111153 let storage_height = self
11121154 . storage_reader
11131155 . height ( )
0 commit comments