Skip to content

Commit

Permalink
[aptos-cli] Add account address to genesis information
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored and aptos-bot committed May 10, 2022
1 parent 1323615 commit 449fba2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
22 changes: 17 additions & 5 deletions crates/aptos/src/genesis/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use aptos_types::{
network_address::{DnsName, NetworkAddress, Protocol},
transaction::authenticator::AuthenticationKey,
};
use move_core_types::account_address::AccountAddress;
use serde::{Deserialize, Serialize};
use std::{
convert::TryFrom,
Expand Down Expand Up @@ -52,6 +53,8 @@ impl Layout {
///
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ValidatorConfiguration {
/// Account address
pub account_address: AccountAddress,
/// Key used for signing in consensus
pub consensus_key: Ed25519PublicKey,
/// Key used for signing transactions with the account
Expand All @@ -66,8 +69,10 @@ pub struct ValidatorConfiguration {
pub stake_amount: u64,
}

impl From<ValidatorConfiguration> for Validator {
fn from(config: ValidatorConfiguration) -> Self {
impl TryFrom<ValidatorConfiguration> for Validator {
type Error = CliError;

fn try_from(config: ValidatorConfiguration) -> Result<Self, CliError> {
let auth_key = AuthenticationKey::ed25519(&config.account_key);
let validator_addresses = vec![config
.validator_host
Expand All @@ -81,16 +86,23 @@ impl From<ValidatorConfiguration> for Validator {
vec![]
};

Validator {
address: auth_key.derived_address(),
let derived_address = auth_key.derived_address();
if config.account_address != derived_address {
return Err(CliError::CommandArgumentError(format!(
"AccountAddress {} does not match account key derived one {}",
config.account_address, derived_address
)));
}
Ok(Validator {
address: derived_address,
consensus_pubkey: config.consensus_key.to_bytes().to_vec(),
operator_address: auth_key.derived_address(),
network_address: bcs::to_bytes(&validator_addresses).unwrap(),
full_node_network_address: bcs::to_bytes(&full_node_addresses).unwrap(),
operator_auth_key: auth_key,
auth_key,
stake_amount: config.stake_amount,
}
})
}
}

Expand Down
14 changes: 11 additions & 3 deletions crates/aptos/src/genesis/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
CliCommand,
};
use aptos_crypto::{ed25519::Ed25519PrivateKey, x25519, PrivateKey};
use aptos_types::transaction::authenticator::AuthenticationKey;
use async_trait::async_trait;
use clap::Parser;
use std::path::PathBuf;
Expand Down Expand Up @@ -83,10 +84,17 @@ impl CliCommand<()> for SetValidatorConfiguration {
let network_key: x25519::PrivateKey =
EncodingType::Hex.load_key(NETWORK_KEY_FILE, &network_key_path)?;

let account_key = account_key.public_key();
let consensus_key = consensus_key.public_key();
let network_key = network_key.public_key();
let auth_key = AuthenticationKey::ed25519(&account_key);
let account_address = auth_key.derived_address();

let credentials = ValidatorConfiguration {
consensus_key: consensus_key.public_key(),
account_key: account_key.public_key(),
network_key: network_key.public_key(),
account_address,
consensus_key,
account_key,
network_key,
validator_host: self.validator_host,
full_node_host: self.full_node_host,
stake_amount: self.stake_amount,
Expand Down
4 changes: 2 additions & 2 deletions crates/aptos/src/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use aptos_vm::AptosVM;
use aptosdb::AptosDB;
use async_trait::async_trait;
use clap::Parser;
use std::path::PathBuf;
use std::{convert::TryInto, path::PathBuf};
use storage_interface::DbReaderWriter;
use vm_genesis::Validator;

Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn fetch_genesis_info(git_options: GitOptions) -> CliTypedResult<GenesisInfo

let mut validators = Vec::new();
for user in &layout.users {
validators.push(client.get::<ValidatorConfiguration>(user)?.into());
validators.push(client.get::<ValidatorConfiguration>(user)?.try_into()?);
}

let modules = client.get_modules("framework")?;
Expand Down

0 comments on commit 449fba2

Please sign in to comment.