Skip to content

Commit

Permalink
let validator check network key
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu Zhang authored and Lu Zhang committed May 3, 2022
1 parent 4e03821 commit f51b8c5
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions sui/src/bin/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use sui::{
sui_commands::{genesis, make_server},
sui_config_dir, SUI_NETWORK_CONFIG,
};
use sui_types::base_types::encode_bytes_hex;
use sui_types::base_types::{decode_bytes_hex, SuiAddress};
use sui_types::base_types::{encode_bytes_hex, SuiAddress};
use sui_types::committee::Committee;
use tracing::{error, info};

Expand All @@ -31,14 +30,6 @@ struct ValidatorOpt {
#[clap(long)]
pub network_config_path: Option<PathBuf>,

/// Public key/address of the validator to start
#[clap(long, parse(try_from_str = decode_bytes_hex))]
address: Option<SuiAddress>,

/// Index in validator array of validator to start
#[clap(long)]
validator_idx: Option<usize>,

#[clap(long, help = "Specify host:port to listen on")]
listen_address: Option<String>,
}
Expand Down Expand Up @@ -70,23 +61,19 @@ async fn main() -> Result<(), anyhow::Error> {
}
};

let authority = if let Some(address) = cfg.address {
// Find the network config for this validator
network_config
.authorities
.iter()
.find(|x| SuiAddress::from(&x.public_key) == address)
.ok_or_else(|| {
anyhow!(
"Network configs must include config for address {}",
address
)
})?
} else if let Some(index) = cfg.validator_idx {
&network_config.authorities[index]
} else {
return Err(anyhow!("Must supply either --address of --validator-idx"));
};
let public_key_bytes = network_config.key_pair.public_key_bytes();
let address = SuiAddress::from(public_key_bytes);
// Find the network config for this validator
let authority = network_config
.authorities
.iter()
.find(|x| SuiAddress::from(&x.public_key) == address)
.ok_or_else(|| {
anyhow!(
"Keypair (pub key: {:?}) in network config is not in the validator committee",
public_key_bytes,
)
})?;

let listen_address = cfg
.listen_address
Expand Down

0 comments on commit f51b8c5

Please sign in to comment.