Skip to content

Commit

Permalink
Age version
Browse files Browse the repository at this point in the history
  • Loading branch information
AgeManning committed Jul 20, 2023
1 parent e806b18 commit 006d0e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
10 changes: 4 additions & 6 deletions beacon_node/lighthouse_network/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,8 @@ where

fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) {
match event {
FromSwarm::ConnectionClosed(_) => {
// TODO(@divma): do we want to initiate a shutdown here?
}
FromSwarm::ConnectionEstablished(_)
FromSwarm::ConnectionClosed(_)
| FromSwarm::ConnectionEstablished(_)
| FromSwarm::AddressChange(_)
| FromSwarm::DialFailure(_)
| FromSwarm::ListenFailure(_)
Expand All @@ -277,7 +275,7 @@ where
| FromSwarm::ExternalAddrExpired(_)
| FromSwarm::ExternalAddrConfirmed(_) => {
// Rpc Behaviour does not act on these swarm events. We use a comprehensive match
// statement tu ensure future events are dealt with appropiately.
// statement to ensure future events are dealt with appropriately.
}
}
}
Expand Down Expand Up @@ -408,4 +406,4 @@ where

slog::Result::Ok(())
}
}
}
39 changes: 18 additions & 21 deletions beacon_node/lighthouse_network/src/service/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,36 +102,33 @@ pub fn load_private_key(config: &NetworkConfig, log: &slog::Logger) -> Keypair {
Err(_) => debug!(log, "Could not read network key file"),
Ok(_) => {
// only accept secp256k1 keys for now
if let Ok(secret_key) = secp256k1::SecretKey::try_from_bytes(&mut key_bytes) {
let kp: secp256k1::Keypair = secret_key.into();
if let Ok(kp) = Keypair::from_protobuf_encoding(&key_bytes) {
debug!(log, "Loaded network key from disk.");
return kp.into();
return kp;
} else {
debug!(log, "Network key file is not a valid secp256k1 key");
debug!(
log,
"Network key file is not a valid protobuf encoded secp256k1 key"
);
}
}
}
}

// if a key could not be loaded from disk, generate a new one and save it
let local_private_key = secp256k1::Keypair::generate();
// TODO(@divma): generate the spcific key type first and then convert it to the wrapper type. This
// avoids the clone and the awkward double conversion
let local_private_key = Keypair::generate_secp256k1();
let _ = std::fs::create_dir_all(&config.network_dir);
match File::create(network_key_f.clone())
.and_then(|mut f| f.write_all(&local_private_key.secret().to_bytes()))
{
Ok(_) => {
debug!(log, "New network key generated and written to disk");
}
Err(e) => {
warn!(
log,
"Could not write node key to file: {:?}. error: {}", network_key_f, e
);
}
match File::create(network_key_f.clone()) {
Ok(mut file) => match local_private_key.to_protobuf_encoding() {
Ok(mut private_key_bytes) => match file.write_all(&mut private_key_bytes) {
Ok(_) => debug!(log, "New network key generated and written to disk"),
Err(e) => warn!(log, "Failed to write network key to disk"; "error" =>e),
},
Err(e) => warn!(log, "Failed to encode network key"; "error" => ?e),
},
Err(e) => warn!(log, "Failed to open network key file"; "error" => e),
}
local_private_key.into()
local_private_key
}

/// Generate authenticated XX Noise config from identity keys
Expand Down Expand Up @@ -269,4 +266,4 @@ pub(crate) fn save_metadata_to_disk<E: EthSpec>(
);
}
}
}
}

0 comments on commit 006d0e1

Please sign in to comment.