@@ -69,6 +69,7 @@ use starknet_api::core::{ContractAddress, GlobalRoot, Nonce};
6969use starknet_api:: state:: { StateNumber , ThinStateDiff } ;
7070use starknet_api:: transaction:: TransactionHash ;
7171use tokio:: sync:: Mutex ;
72+ use tokio:: task:: JoinHandle ;
7273use tracing:: { debug, error, info, instrument, trace, Instrument } ;
7374
7475use crate :: block_builder:: {
@@ -173,11 +174,10 @@ pub struct Batcher {
173174 /// This is returned by the decision_reached function.
174175 prev_proposal_commitment : Option < ( BlockNumber , ProposalCommitment ) > ,
175176
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 > ,
180177 commitment_manager : ApolloCommitmentManager ,
178+
179+ /// Task handle for the storage reader server, if enabled.
180+ storage_reader_server_handle : Option < JoinHandle < ( ) > > ,
181181}
182182
183183impl Batcher {
@@ -192,8 +192,8 @@ impl Batcher {
192192 transaction_converter : TransactionConverter ,
193193 block_builder_factory : Box < dyn BlockBuilderFactoryTrait > ,
194194 pre_confirmed_block_writer_factory : Box < dyn PreconfirmedBlockWriterFactoryTrait > ,
195- storage_reader_server : Option < GenericStorageReaderServer > ,
196195 commitment_manager : ApolloCommitmentManager ,
196+ storage_reader_server_handle : Option < JoinHandle < ( ) > > ,
197197 ) -> Self {
198198 Self {
199199 config,
@@ -214,8 +214,8 @@ impl Batcher {
214214 // Allow the first few proposals to be without L1 txs while system starts up.
215215 proposals_counter : 1 ,
216216 prev_proposal_commitment : None ,
217- storage_reader_server,
218217 commitment_manager,
218+ storage_reader_server_handle,
219219 }
220220 }
221221
@@ -1255,6 +1255,15 @@ fn log_txs_execution_result(
12551255 }
12561256}
12571257
1258+ impl Drop for Batcher {
1259+ fn drop ( & mut self ) {
1260+ // Abort the storage reader server task if it was spawned.
1261+ if let Some ( handle) = self . storage_reader_server_handle . take ( ) {
1262+ handle. abort ( ) ;
1263+ }
1264+ }
1265+ }
1266+
12581267pub async fn create_batcher (
12591268 config : BatcherConfig ,
12601269 committer_client : SharedCommitterClient ,
@@ -1271,6 +1280,9 @@ pub async fn create_batcher(
12711280 )
12721281 . expect ( "Failed to open batcher's storage" ) ;
12731282
1283+ let storage_reader_server_handle =
1284+ GenericStorageReaderServer :: spawn_if_enabled ( storage_reader_server) ;
1285+
12741286 let execute_config = & config. block_builder_config . execute_config ;
12751287 let worker_pool = Arc :: new ( WorkerPool :: start ( execute_config) ) ;
12761288 let pre_confirmed_block_writer_factory = Box :: new ( PreconfirmedBlockWriterFactory {
@@ -1310,8 +1322,8 @@ pub async fn create_batcher(
13101322 transaction_converter,
13111323 block_builder_factory,
13121324 pre_confirmed_block_writer_factory,
1313- storage_reader_server,
13141325 commitment_manager,
1326+ storage_reader_server_handle,
13151327 )
13161328}
13171329
0 commit comments