@@ -16,9 +16,12 @@ use portalnet::{
1616 types:: messages:: PortalnetConfig ,
1717 utils:: db:: { configure_node_data_dir, configure_trin_data_dir} ,
1818} ;
19+ use trin_beacon:: initialize_beacon_network;
1920use trin_history:: initialize_history_network;
2021use trin_state:: initialize_state_network;
21- use trin_types:: cli:: { TrinConfig , Web3TransportType , HISTORY_NETWORK , STATE_NETWORK } ;
22+ use trin_types:: cli:: {
23+ TrinConfig , Web3TransportType , BEACON_NETWORK , HISTORY_NETWORK , STATE_NETWORK ,
24+ } ;
2225use trin_types:: jsonrpc:: request:: HistoryJsonRpcRequest ;
2326use trin_types:: provider:: TrustedProvider ;
2427use trin_utils:: version:: get_trin_version;
@@ -94,6 +97,21 @@ pub async fn run_trin(
9497 ( None , None , None , None )
9598 } ;
9699
100+ // Initialize trin-beacon sub-network service and event handlers, if selected
101+ let ( beacon_handler, beacon_network_task, beacon_event_tx, _beacon_jsonrpc_tx) =
102+ if trin_config. networks . iter ( ) . any ( |val| val == BEACON_NETWORK ) {
103+ initialize_beacon_network (
104+ & discovery,
105+ Arc :: clone ( & utp_socket) ,
106+ portalnet_config. clone ( ) ,
107+ storage_config. clone ( ) ,
108+ header_oracle. clone ( ) ,
109+ )
110+ . await ?
111+ } else {
112+ ( None , None , None , None )
113+ } ;
114+
97115 // Initialize chain history sub-network service and event handlers, if selected
98116 let ( history_handler, history_network_task, history_event_tx, history_jsonrpc_tx) =
99117 if trin_config
@@ -125,13 +143,17 @@ pub async fn run_trin(
125143 if let Some ( handler) = history_handler {
126144 tokio:: spawn ( async move { handler. handle_client_queries ( ) . await } ) ;
127145 }
146+ if let Some ( handler) = beacon_handler {
147+ tokio:: spawn ( async move { handler. handle_client_queries ( ) . await } ) ;
148+ }
128149
129150 // Spawn main portal events handler
130151 tokio:: spawn ( async move {
131152 let events = PortalnetEvents :: new (
132153 talk_req_rx,
133154 history_event_tx,
134155 state_event_tx,
156+ beacon_event_tx,
135157 utp_talk_reqs_tx,
136158 )
137159 . await ;
@@ -144,6 +166,9 @@ pub async fn run_trin(
144166 if let Some ( network) = state_network_task {
145167 tokio:: spawn ( async { network. await } ) ;
146168 }
169+ if let Some ( network) = beacon_network_task {
170+ tokio:: spawn ( async { network. await } ) ;
171+ }
147172
148173 Ok ( rpc_handle?)
149174}
0 commit comments