Skip to content

Commit 93f36fa

Browse files
apollo_batcher: add storage_reader_server to the batcher
1 parent 079f9a0 commit 93f36fa

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

crates/apollo_batcher/src/batcher.rs

Lines changed: 42 additions & 0 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,6 +38,7 @@ 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};
41+
use apollo_storage::storage_reader_server::{create_storage_reader_server, StorageReaderServer};
3842
use apollo_storage::{open_storage_with_metric, StorageReader, StorageResult, StorageWriter};
3943
use async_trait::async_trait;
4044
use 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

150162
impl 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 {
11081139
impl 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()

crates/apollo_batcher_config/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use apollo_config::converters::deserialize_milliseconds_to_duration;
55
use apollo_config::dumping::{prepend_sub_config_name, ser_param, SerializeConfig};
66
use apollo_config::secrets::Sensitive;
77
use apollo_config::{ParamPath, ParamPrivacyInput, SerializedParam};
8+
use apollo_storage::storage_reader_server::ServerConfig as StorageReaderServerConfig;
89
use blockifier::blockifier::config::{ContractClassManagerConfig, WorkerPoolConfig};
910
use blockifier::blockifier_versioned_constants::VersionedConstantsOverrides;
1011
use blockifier::bouncer::BouncerConfig;
@@ -153,6 +154,7 @@ pub struct BatcherConfig {
153154
pub max_l1_handler_txs_per_block_proposal: usize,
154155
pub pre_confirmed_cende_config: PreconfirmedCendeConfig,
155156
pub propose_l1_txs_every: u64,
157+
pub storage_reader_server_config: StorageReaderServerConfig,
156158
}
157159

158160
impl SerializeConfig for BatcherConfig {
@@ -186,6 +188,10 @@ impl SerializeConfig for BatcherConfig {
186188
),
187189
]);
188190
dump.append(&mut prepend_sub_config_name(self.storage.dump(), "storage"));
191+
dump.append(&mut prepend_sub_config_name(
192+
self.storage_reader_server_config.dump(),
193+
"storage_reader_server",
194+
));
189195
dump.append(&mut prepend_sub_config_name(
190196
self.block_builder_config.dump(),
191197
"block_builder_config",
@@ -227,6 +233,7 @@ impl Default for BatcherConfig {
227233
max_l1_handler_txs_per_block_proposal: 3,
228234
pre_confirmed_cende_config: PreconfirmedCendeConfig::default(),
229235
propose_l1_txs_every: 1, // Default is to propose L1 transactions every proposal.
236+
storage_reader_server_config: StorageReaderServerConfig::default(),
230237
}
231238
}
232239
}

0 commit comments

Comments
 (0)