MCPcopy Create free account
hub / github.com/base/base / execute

Method execute

crates/execution/cli/src/commands/p2p/bootnode.rs:48–132  ·  view source on GitHub ↗

Execute the bootnode command.

(self)

Source from the content-addressed store, hash-verified

46impl Command {
47 /// Execute the bootnode command.
48 pub async fn execute(self) -> eyre::Result<()> {
49 info!(v4_addr = %self.v4_addr, v5_addr = %self.v5_addr, nat = %self.nat, v5 = self.v5, "Bootnode starting");
50
51 // discv4
52 let sk = self.network_secret()?;
53 let v4_node_record = NodeRecord::from_secret_key(self.v4_addr, &sk);
54 let config = self.discv4_config();
55 let nat = self.nat.clone();
56 let (_discv4, mut discv4_service) =
57 Discv4::bind(self.v4_addr, v4_node_record, sk, config).await?;
58 info!(v4_node_record = ?v4_node_record, enode = %v4_node_record, "Started discv4");
59 let mut discv4_updates = discv4_service.update_stream();
60 discv4_service.spawn();
61
62 // discv5
63 let mut discv5_updates = None;
64 let mut _discv5 = None;
65
66 if self.v5 {
67 info!("Initializing discv5");
68 let config = self.discv5_config();
69 let (discv5, updates) = Discv5::start(&sk, config).await?;
70
71 // The upstream reth bootnode skips NAT resolution for discv5, leaving the ENR with
72 // no IP address. Peers receiving the ENR cannot send WHOAREYOU back because they
73 // have no address to target. Resolve the external IP and update the ENR here.
74 match external_addr_with(nat).await {
75 Some(external_ip) => {
76 let socket = SocketAddr::new(external_ip, self.v5_addr.port());
77 discv5.with_discv5(|d| d.update_local_enr_socket(socket, false));
78 }
79 None => {
80 warn!(
81 addr = %self.v5_addr,
82 "Could not resolve external IP via NAT; discv5 ENR has no IP and may not be reachable"
83 );
84 }
85 }
86
87 info!(enr = %discv5.local_enr(), "Started discv5");
88
89 discv5_updates = Some(updates);
90 _discv5 = Some(discv5);
91 }
92
93 loop {
94 select! {
95 update = discv4_updates.next() => {
96 match update {
97 Some(DiscoveryUpdate::Added(record)) => {
98 info!(peer_id = ?record.id, "discv4 peer added");
99 }
100 Some(DiscoveryUpdate::Removed(peer_id)) => {
101 info!(peer_id = ?peer_id, "discv4 peer removed");
102 }
103 Some(_) => {}
104 None => {
105 info!("discv4 update stream ended");

Callers

nothing calls this directly

Calls 6

network_secretMethod · 0.80
discv4_configMethod · 0.80
newFunction · 0.50
cloneMethod · 0.45
spawnMethod · 0.45
discv5_configMethod · 0.45

Tested by

no test coverage detected