Skip to content

Commit

Permalink
[tooling] Ensure ExtractPeer creates upstream peers
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored and aptos-bot committed Apr 6, 2022
1 parent 7d3d662 commit cf77dd6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion config/management/operational/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl GenerateKey {
}
}

/// Extracts an upstream peer config from a key
#[derive(Debug, StructOpt)]
pub struct ExtractPeersFromKeys {
#[structopt(long, parse(try_from_str = parse_public_keys_hex))]
Expand Down Expand Up @@ -144,6 +145,7 @@ impl ExtractPeersFromKeys {
}
}

/// Extracts an upstream peer config from a file
#[derive(Debug, StructOpt)]
pub struct ExtractPeerFromFile {
/// Location to read the key
Expand All @@ -169,6 +171,7 @@ impl ExtractPeerFromFile {
}
}

/// Extracts an upstream peer config from storage
#[derive(Debug, StructOpt)]
pub struct ExtractPeerFromStorage {
#[structopt(flatten)]
Expand Down Expand Up @@ -209,7 +212,7 @@ fn peer_from_public_key(public_key: x25519::PublicKey) -> (AccountAddress, Peer)
public_keys.insert(public_key);
(
peer_id,
Peer::new(Vec::new(), public_keys, PeerRole::Downstream),
Peer::new(Vec::new(), public_keys, PeerRole::Upstream),
)
}

Expand Down
7 changes: 5 additions & 2 deletions crates/aptos/src/op/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl FromStr for KeyPairType {
}
}

/// CLI tool for extracting full peer information from a given public key file
/// CLI tool for extracting full peer information for an upstream peer
#[derive(Debug, Parser)]
pub struct ExtractPeer {
/// Public key input file name.
Expand Down Expand Up @@ -317,5 +317,8 @@ fn build_peer_from_public_key(public_key: x25519::PublicKey) -> (AccountAddress,
let peer_id = from_identity_public_key(public_key);
let mut public_keys = HashSet::new();
public_keys.insert(public_key);
(peer_id, Peer::new(Vec::new(), public_keys, PeerRole::Known))
(
peer_id,
Peer::new(Vec::new(), public_keys, PeerRole::Upstream),
)
}
2 changes: 1 addition & 1 deletion testsuite/smoke-test/src/operational_tooling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ async fn test_extract_peers_from_keys() {

assert_eq!(1, keys.len());
assert!(keys.contains(&key));
assert_eq!(PeerRole::Downstream, peer.role);
assert_eq!(PeerRole::Upstream, peer.role);
assert!(peer.addresses.is_empty());
}
}
Expand Down

0 comments on commit cf77dd6

Please sign in to comment.