Skip to content

Commit 8ad295d

Browse files
authored
Launch beacon portal network (#725)
1 parent fcaa4b1 commit 8ad295d

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ tempfile = "3.3.0"
3535
tokio = { version = "1.14.0", features = ["full"] }
3636
tracing = "0.1.36"
3737
tracing-subscriber = "0.3.15"
38+
trin-beacon = { path = "trin-beacon" }
3839
trin-bridge = { path = "trin-bridge" }
3940
trin-history = { path = "trin-history" }
4041
trin-state = { path = "trin-state" }

newsfragments/725.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Launch beacon portal network without RPC support

portalnet/src/events.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub struct PortalnetEvents {
1515
pub history_overlay_sender: Option<mpsc::UnboundedSender<TalkRequest>>,
1616
/// Send overlay `TalkReq` to state network
1717
pub state_overlay_sender: Option<mpsc::UnboundedSender<TalkRequest>>,
18+
/// Send overlay `TalkReq` to beacon network
19+
pub beacon_overlay_sender: Option<mpsc::UnboundedSender<TalkRequest>>,
1820
/// Send TalkReq events with "utp" protocol id to `UtpListener`
1921
pub utp_talk_reqs: mpsc::UnboundedSender<TalkRequest>,
2022
}
@@ -24,12 +26,14 @@ impl PortalnetEvents {
2426
talk_req_receiver: mpsc::Receiver<TalkRequest>,
2527
history_overlay_sender: Option<mpsc::UnboundedSender<TalkRequest>>,
2628
state_overlay_sender: Option<mpsc::UnboundedSender<TalkRequest>>,
29+
beacon_overlay_sender: Option<mpsc::UnboundedSender<TalkRequest>>,
2730
utp_talk_reqs: mpsc::UnboundedSender<TalkRequest>,
2831
) -> Self {
2932
Self {
3033
talk_req_receiver,
3134
history_overlay_sender,
3235
state_overlay_sender,
36+
beacon_overlay_sender,
3337
utp_talk_reqs,
3438
}
3539
}
@@ -56,7 +60,19 @@ impl PortalnetEvents {
5660
);
5761
}
5862
}
59-
None => warn!("History event handler not initialized!"),
63+
None => error!("History event handler not initialized!"),
64+
};
65+
}
66+
ProtocolId::Beacon => {
67+
match &self.beacon_overlay_sender {
68+
Some(tx) => {
69+
if let Err(err) = tx.send(request) {
70+
error!(
71+
"Error sending discv5 talk request to beacon network: {err}"
72+
);
73+
}
74+
}
75+
None => error!("Beacon event handler not initialized!"),
6076
};
6177
}
6278
ProtocolId::State => {
@@ -66,12 +82,12 @@ impl PortalnetEvents {
6682
error!("Error sending discv5 talk request to state network: {err}");
6783
}
6884
}
69-
None => warn!("State event handler not initialized!"),
85+
None => error!("State event handler not initialized!"),
7086
};
7187
}
7288
ProtocolId::Utp => {
7389
if let Err(err) = self.utp_talk_reqs.send(request) {
74-
warn!(%err, "Error forwarding talk request to uTP socket");
90+
error!(%err, "Error forwarding talk request to uTP socket");
7591
}
7692
}
7793
_ => {

src/lib.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;
1920
use trin_history::initialize_history_network;
2021
use 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+
};
2225
use trin_types::jsonrpc::request::HistoryJsonRpcRequest;
2326
use trin_types::provider::TrustedProvider;
2427
use 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
}

trin-types/src/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub const DEFAULT_MASTER_ACC_PATH: &str = "validation_assets/merge_macc.bin";
1111
pub const DEFAULT_WEB3_IPC_PATH: &str = "/tmp/trin-jsonrpc.ipc";
1212
pub const DEFAULT_WEB3_HTTP_ADDRESS: &str = "http://127.0.0.1:8545/";
1313
const DEFAULT_DISCOVERY_PORT: &str = "9000";
14+
pub const BEACON_NETWORK: &str = "beacon";
1415
pub const HISTORY_NETWORK: &str = "history";
1516
pub const STATE_NETWORK: &str = "state";
1617
const DEFAULT_SUBNETWORKS: &str = "history";

0 commit comments

Comments
 (0)