1- use std:: collections:: { BTreeMap , BTreeSet , HashMap } ;
1+ use std:: collections:: { BTreeSet , HashMap } ;
22
33use apollo_infra:: component_client:: DEFAULT_RETRIES ;
44use apollo_node_config:: component_config:: ComponentConfig ;
@@ -10,19 +10,14 @@ use serde::Serialize;
1010use strum:: { Display , IntoEnumIterator } ;
1111use strum_macros:: { AsRefStr , EnumIter } ;
1212
13- use crate :: deployment_definitions:: {
14- ComponentConfigInService ,
15- InfraServicePort ,
16- INFRA_PORT_PLACEHOLDER ,
17- } ;
13+ use crate :: deployment_definitions:: { ComponentConfigInService , RETRIES_FOR_L1_SERVICES } ;
1814use crate :: scale_policy:: ScalePolicy ;
1915use crate :: service:: { GetComponentConfigs , NodeService , ServiceNameInner } ;
20- use crate :: utils:: validate_ports ;
16+ use crate :: utils:: InfraPortAllocator ;
2117
18+ // Number of infra-required ports for a distributed node service distribution.
2219pub const DISTRIBUTED_NODE_REQUIRED_PORTS_NUM : usize = 10 ;
2320
24- pub const RETRIES_FOR_L1_SERVICES : usize = 0 ;
25-
2621// TODO(Tsabary): define consts and functions whenever relevant.
2722
2823#[ derive( Clone , Copy , Debug , Display , PartialEq , Eq , Hash , Serialize , AsRefStr , EnumIter ) ]
@@ -50,45 +45,20 @@ impl From<DistributedNodeServiceName> for NodeService {
5045
5146impl GetComponentConfigs for DistributedNodeServiceName {
5247 fn get_component_configs ( ports : Option < Vec < u16 > > ) -> HashMap < NodeService , ComponentConfig > {
53- // TODO(Tsabary): style this code, i.e., no need to use a mutable map nor the for loop, and
54- // can simply collect the required values.
55- let mut service_ports: BTreeMap < InfraServicePort , u16 > = BTreeMap :: new ( ) ;
56- match ports {
57- Some ( ports) => {
58- // TODO(Nadin): This should compare against DistributedServicePort-specific infra
59- // ports, not all InfraServicePort variants.
60- validate_ports ( & ports, InfraServicePort :: iter ( ) . count ( ) ) ;
61- for ( service_port, port) in InfraServicePort :: iter ( ) . zip ( ports) {
62- service_ports. insert ( service_port, port) ;
63- }
64- }
65- None => {
66- for service_port in InfraServicePort :: iter ( ) {
67- service_ports. insert ( service_port, INFRA_PORT_PLACEHOLDER ) ;
68- }
69- }
70- } ;
71-
72- let batcher =
73- Self :: Batcher . component_config_pair ( service_ports[ & InfraServicePort :: Batcher ] ) ;
74- let class_manager = Self :: ClassManager
75- . component_config_pair ( service_ports[ & InfraServicePort :: ClassManager ] ) ;
76- let committer =
77- Self :: Committer . component_config_pair ( service_ports[ & InfraServicePort :: Committer ] ) ;
78- let gateway =
79- Self :: Gateway . component_config_pair ( service_ports[ & InfraServicePort :: Gateway ] ) ;
80- let l1_gas_price_provider =
81- Self :: L1 . component_config_pair ( service_ports[ & InfraServicePort :: L1GasPriceProvider ] ) ;
82- let l1_provider =
83- Self :: L1 . component_config_pair ( service_ports[ & InfraServicePort :: L1Provider ] ) ;
84- let mempool =
85- Self :: Mempool . component_config_pair ( service_ports[ & InfraServicePort :: Mempool ] ) ;
86- let sierra_compiler = Self :: SierraCompiler
87- . component_config_pair ( service_ports[ & InfraServicePort :: SierraCompiler ] ) ;
88- let signature_manager = Self :: SignatureManager
89- . component_config_pair ( service_ports[ & InfraServicePort :: SignatureManager ] ) ;
90- let state_sync =
91- Self :: StateSync . component_config_pair ( service_ports[ & InfraServicePort :: StateSync ] ) ;
48+ let mut infra_port_allocator =
49+ InfraPortAllocator :: new ( ports, DISTRIBUTED_NODE_REQUIRED_PORTS_NUM ) ;
50+ let batcher = Self :: Batcher . component_config_pair ( infra_port_allocator. next ( ) ) ;
51+ let class_manager = Self :: ClassManager . component_config_pair ( infra_port_allocator. next ( ) ) ;
52+ let committer = Self :: Committer . component_config_pair ( infra_port_allocator. next ( ) ) ;
53+ let gateway = Self :: Gateway . component_config_pair ( infra_port_allocator. next ( ) ) ;
54+ let l1_gas_price_provider = Self :: L1 . component_config_pair ( infra_port_allocator. next ( ) ) ;
55+ let l1_provider = Self :: L1 . component_config_pair ( infra_port_allocator. next ( ) ) ;
56+ let mempool = Self :: Mempool . component_config_pair ( infra_port_allocator. next ( ) ) ;
57+ let sierra_compiler =
58+ Self :: SierraCompiler . component_config_pair ( infra_port_allocator. next ( ) ) ;
59+ let signature_manager =
60+ Self :: SignatureManager . component_config_pair ( infra_port_allocator. next ( ) ) ;
61+ let state_sync = Self :: StateSync . component_config_pair ( infra_port_allocator. next ( ) ) ;
9262
9363 let mut component_config_map = HashMap :: < NodeService , ComponentConfig > :: new ( ) ;
9464 for inner_service_name in Self :: iter ( ) {
0 commit comments