Skip to content

Commit 48f23ca

Browse files
refactor(starknet_sequencer_node): reordering of clients.rs (#3455)
commit-id:4dc6d3e5
1 parent 60f1a26 commit 48f23ca

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

crates/starknet_sequencer_node/src/clients.rs

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ use crate::config::node_config::SequencerNodeConfig;
6060
pub struct SequencerNodeClients {
6161
batcher_client: Client<BatcherRequest, BatcherResponse>,
6262
class_manager_client: Client<ClassManagerRequest, ClassManagerResponse>,
63-
mempool_client: Client<MempoolRequest, MempoolResponse>,
6463
gateway_client: Client<GatewayRequest, GatewayResponse>,
64+
l1_provider_client: Client<L1ProviderRequest, L1ProviderResponse>,
65+
mempool_client: Client<MempoolRequest, MempoolResponse>,
6566
mempool_p2p_propagator_client:
6667
Client<MempoolP2pPropagatorRequest, MempoolP2pPropagatorResponse>,
6768
sierra_compiler_client: Client<SierraCompilerRequest, SierraCompilerResponse>,
6869
state_sync_client: Client<StateSyncRequest, StateSyncResponse>,
69-
l1_provider_client: Client<L1ProviderRequest, L1ProviderResponse>,
7070
}
7171

7272
/// A macro to retrieve a shared client wrapped in an `Arc`. The returned client is either the local
@@ -111,20 +111,15 @@ macro_rules! get_shared_client {
111111
}
112112

113113
// TODO(Nadin): Refactor getters to remove code duplication.
114-
// TODO(Lev/Itay): Too many functions, need to be sorted in a meaningful way.
115114
impl SequencerNodeClients {
116-
pub fn get_batcher_shared_client(&self) -> Option<SharedBatcherClient> {
117-
get_shared_client!(self, batcher_client)
118-
}
119-
120115
pub fn get_batcher_local_client(
121116
&self,
122117
) -> Option<LocalComponentClient<BatcherRequest, BatcherResponse>> {
123118
self.batcher_client.get_local_client()
124119
}
125120

126-
pub fn get_class_manager_shared_client(&self) -> Option<SharedClassManagerClient> {
127-
get_shared_client!(self, class_manager_client)
121+
pub fn get_batcher_shared_client(&self) -> Option<SharedBatcherClient> {
122+
get_shared_client!(self, batcher_client)
128123
}
129124

130125
pub fn get_class_manager_local_client(
@@ -133,26 +128,20 @@ impl SequencerNodeClients {
133128
self.class_manager_client.get_local_client()
134129
}
135130

136-
pub fn get_mempool_shared_client(&self) -> Option<SharedMempoolClient> {
137-
get_shared_client!(self, mempool_client)
131+
pub fn get_class_manager_shared_client(&self) -> Option<SharedClassManagerClient> {
132+
get_shared_client!(self, class_manager_client)
138133
}
139134

140-
pub fn get_mempool_local_client(
135+
pub fn get_gateway_local_client(
141136
&self,
142-
) -> Option<LocalComponentClient<MempoolRequest, MempoolResponse>> {
143-
self.mempool_client.get_local_client()
137+
) -> Option<LocalComponentClient<GatewayRequest, GatewayResponse>> {
138+
self.gateway_client.get_local_client()
144139
}
145140

146141
pub fn get_gateway_shared_client(&self) -> Option<SharedGatewayClient> {
147142
get_shared_client!(self, gateway_client)
148143
}
149144

150-
pub fn get_gateway_local_client(
151-
&self,
152-
) -> Option<LocalComponentClient<GatewayRequest, GatewayResponse>> {
153-
self.gateway_client.get_local_client()
154-
}
155-
156145
pub fn get_l1_provider_local_client(
157146
&self,
158147
) -> Option<LocalComponentClient<L1ProviderRequest, L1ProviderResponse>> {
@@ -163,10 +152,14 @@ impl SequencerNodeClients {
163152
get_shared_client!(self, l1_provider_client)
164153
}
165154

166-
pub fn get_mempool_p2p_propagator_shared_client(
155+
pub fn get_mempool_local_client(
167156
&self,
168-
) -> Option<SharedMempoolP2pPropagatorClient> {
169-
get_shared_client!(self, mempool_p2p_propagator_client)
157+
) -> Option<LocalComponentClient<MempoolRequest, MempoolResponse>> {
158+
self.mempool_client.get_local_client()
159+
}
160+
161+
pub fn get_mempool_shared_client(&self) -> Option<SharedMempoolClient> {
162+
get_shared_client!(self, mempool_client)
170163
}
171164

172165
pub fn get_mempool_p2p_propagator_local_client(
@@ -176,8 +169,10 @@ impl SequencerNodeClients {
176169
self.mempool_p2p_propagator_client.get_local_client()
177170
}
178171

179-
pub fn get_sierra_compiler_shared_client(&self) -> Option<SharedSierraCompilerClient> {
180-
get_shared_client!(self, sierra_compiler_client)
172+
pub fn get_mempool_p2p_propagator_shared_client(
173+
&self,
174+
) -> Option<SharedMempoolP2pPropagatorClient> {
175+
get_shared_client!(self, mempool_p2p_propagator_client)
181176
}
182177

183178
pub fn get_sierra_compiler_local_client(
@@ -186,15 +181,19 @@ impl SequencerNodeClients {
186181
self.sierra_compiler_client.get_local_client()
187182
}
188183

189-
pub fn get_state_sync_shared_client(&self) -> Option<SharedStateSyncClient> {
190-
get_shared_client!(self, state_sync_client)
184+
pub fn get_sierra_compiler_shared_client(&self) -> Option<SharedSierraCompilerClient> {
185+
get_shared_client!(self, sierra_compiler_client)
191186
}
192187

193188
pub fn get_state_sync_local_client(
194189
&self,
195190
) -> Option<LocalComponentClient<StateSyncRequest, StateSyncResponse>> {
196191
self.state_sync_client.get_local_client()
197192
}
193+
194+
pub fn get_state_sync_shared_client(&self) -> Option<SharedStateSyncClient> {
195+
get_shared_client!(self, state_sync_client)
196+
}
198197
}
199198

200199
/// A macro for creating a component client fitting the component's execution mode. Returns a
@@ -263,6 +262,7 @@ pub fn create_node_clients(
263262
&config.components.batcher.remote_client_config,
264263
config.components.batcher.socket
265264
);
265+
266266
let class_manager_client = create_client!(
267267
&config.components.class_manager.execution_mode,
268268
LocalClassManagerClient,
@@ -271,14 +271,7 @@ pub fn create_node_clients(
271271
&config.components.class_manager.remote_client_config,
272272
config.components.class_manager.socket
273273
);
274-
let mempool_client = create_client!(
275-
&config.components.mempool.execution_mode,
276-
LocalMempoolClient,
277-
RemoteMempoolClient,
278-
channels.take_mempool_tx(),
279-
&config.components.mempool.remote_client_config,
280-
config.components.mempool.socket
281-
);
274+
282275
let gateway_client = create_client!(
283276
&config.components.gateway.execution_mode,
284277
LocalGatewayClient,
@@ -288,6 +281,24 @@ pub fn create_node_clients(
288281
config.components.gateway.socket
289282
);
290283

284+
let l1_provider_client = create_client!(
285+
&config.components.l1_provider.execution_mode,
286+
LocalL1ProviderClient,
287+
RemoteL1ProviderClient,
288+
channels.take_l1_provider_tx(),
289+
&config.components.l1_provider.remote_client_config,
290+
config.components.l1_provider.socket
291+
);
292+
293+
let mempool_client = create_client!(
294+
&config.components.mempool.execution_mode,
295+
LocalMempoolClient,
296+
RemoteMempoolClient,
297+
channels.take_mempool_tx(),
298+
&config.components.mempool.remote_client_config,
299+
config.components.mempool.socket
300+
);
301+
291302
let mempool_p2p_propagator_client = create_client!(
292303
&config.components.mempool_p2p.execution_mode,
293304
LocalMempoolP2pPropagatorClient,
@@ -315,23 +326,14 @@ pub fn create_node_clients(
315326
config.components.state_sync.socket
316327
);
317328

318-
let l1_provider_client = create_client!(
319-
&config.components.l1_provider.execution_mode,
320-
LocalL1ProviderClient,
321-
RemoteL1ProviderClient,
322-
channels.take_l1_provider_tx(),
323-
&config.components.l1_provider.remote_client_config,
324-
config.components.l1_provider.socket
325-
);
326-
327329
SequencerNodeClients {
328330
batcher_client,
329331
class_manager_client,
330-
mempool_client,
331332
gateway_client,
333+
l1_provider_client,
334+
mempool_client,
332335
mempool_p2p_propagator_client,
333336
sierra_compiler_client,
334337
state_sync_client,
335-
l1_provider_client,
336338
}
337339
}

0 commit comments

Comments
 (0)