Skip to content

Commit

Permalink
fixup after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkuo committed Feb 18, 2022
1 parent 4c387b0 commit 3c66a43
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ Example `genesis.conf`
{
"authorities": [
{
"address": "bd654f352c895d9ec14c491d3f2b4e1f98fb07323383bebe9f95ab625bff2fa0",
"key_pair": "DfwJMkbD877Xehkaa03aPTsP5f4CpSADNCfX3Iukku69ZU81LIldnsFMSR0/K04fmPsHMjODvr6flatiW/8voA==",
"key_pair": "xWhgxF5fagohi2V9jzUToxnhJbTwbtV2qX4dbMGXR7lORTBuDBe+ppFDnnHz8L/BcYHWO76EuQzUYe5pnpLsFQ==",
"host": "127.0.0.1",
"port": 10004,
"db_path": "./authorities_db/bd654f352c895d9ec14c491d3f2b4e1f98fb07323383bebe9f95ab625bff2fa0",
"port": 10000,
"db_path": "./authorities_db/4e45306e0c17bea691439e71f3f0bfc17181d63bbe84b90cd461ee699e92ec15",
"stake": 1
}
],
Expand Down
14 changes: 4 additions & 10 deletions sui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use sui_types::base_types::*;
use sui_types::crypto::KeyPair;
use sui_types::crypto::{get_key_pair, KeyPair};

use crate::utils::optional_address_as_hex;
use crate::utils::optional_address_from_hex;
Expand Down Expand Up @@ -55,14 +55,9 @@ impl<'de> Deserialize<'de> for AuthorityPrivateInfo {
where
D: serde::de::Deserializer<'de>,
{
let (new_address, new_key_pair) = get_key_pair();
let (_, new_key_pair) = get_key_pair();

let json = Value::deserialize(deserializer)?;
let address = if let Some(val) = json.get("address") {
address_from_hex(val).map_err(serde::de::Error::custom)?
} else {
new_address
};
let key_pair = if let Some(val) = json.get("key_pair") {
KeyPair::deserialize(val).map_err(serde::de::Error::custom)?
} else {
Expand All @@ -87,7 +82,7 @@ impl<'de> Deserialize<'de> for AuthorityPrivateInfo {
} else {
PathBuf::from(".")
.join(AUTHORITIES_DB_NAME)
.join(encode_address_hex(&address))
.join(encode_bytes_hex(key_pair.public_key_bytes()))
};
let stake = if let Some(val) = json.get("stake") {
usize::deserialize(val).map_err(serde::de::Error::custom)?
Expand All @@ -96,7 +91,6 @@ impl<'de> Deserialize<'de> for AuthorityPrivateInfo {
};

Ok(AuthorityPrivateInfo {
address,
key_pair,
host,
port,
Expand Down Expand Up @@ -242,7 +236,7 @@ impl GenesisConfig {
let mut authority = AuthorityPrivateInfo::deserialize(Value::String(String::new()))?;
authority.db_path = working_dir
.join(AUTHORITIES_DB_NAME)
.join(encode_address_hex(&authority.address));
.join(encode_bytes_hex(&authority.key_pair.public_key_bytes()));
authorities.push(authority)
}
let mut accounts = Vec::new();
Expand Down
9 changes: 4 additions & 5 deletions sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ use std::sync::Arc;
use structopt::StructOpt;
use sui_core::authority::{AuthorityState, AuthorityStore};
use sui_core::authority_server::AuthorityServer;
use sui_types::base_types::{
get_key_pair, SequenceNumber, SuiAddress, TransactionDigest, TxContext,
};
use sui_types::base_types::{SequenceNumber, SuiAddress, TransactionDigest, TxContext};

use sui_adapter::adapter::generate_package_id;
use sui_types::committee::Committee;
use sui_types::crypto::get_key_pair;
use sui_types::error::SuiResult;
use sui_types::object::Object;
use tracing::{error, info};
Expand Down Expand Up @@ -112,9 +111,9 @@ async fn genesis(
);

for authority in genesis_conf.authorities {
voting_right.insert(authority.address, authority.stake);
voting_right.insert(*authority.key_pair.public_key_bytes(), authority.stake);
authority_info.push(AuthorityInfo {
address: authority.address,
name: *authority.key_pair.public_key_bytes(),
host: authority.host.clone(),
base_port: authority.port,
});
Expand Down
3 changes: 2 additions & 1 deletion sui/src/unit_tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use sui::config::{
AUTHORITIES_DB_NAME,
};
use sui::wallet_commands::{WalletCommands, WalletContext};
use sui_types::base_types::{encode_address_hex, get_key_pair, ObjectID};
use sui_types::base_types::{encode_bytes_hex, ObjectID};
use sui_types::crypto::get_key_pair;
use tokio::task;
use tracing_test::traced_test;

Expand Down
12 changes: 5 additions & 7 deletions sui/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fs::File;
use std::io::BufReader;
use std::net::TcpListener;
use std::path::{Path, PathBuf};
use sui_types::base_types::{decode_address_hex, encode_address_hex, PublicKeyBytes};
use sui_types::base_types::{decode_bytes_hex, encode_bytes_hex, SuiAddress};
use tracing::log::trace;

pub const DEFAULT_STARTING_PORT: u16 = 10000;
Expand Down Expand Up @@ -75,26 +75,24 @@ impl PortAllocator {
}

pub fn optional_address_as_hex<S>(
key: &Option<PublicKeyBytes>,
key: &Option<SuiAddress>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
serializer.serialize_str(
&*key
.map(|addr| encode_address_hex(&addr))
.map(|addr| encode_bytes_hex(&addr))
.unwrap_or_else(|| "".to_string()),
)
}

pub fn optional_address_from_hex<'de, D>(
deserializer: D,
) -> Result<Option<PublicKeyBytes>, D::Error>
pub fn optional_address_from_hex<'de, D>(deserializer: D) -> Result<Option<SuiAddress>, D::Error>
where
D: serde::de::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
let value = decode_address_hex(&s).map_err(serde::de::Error::custom)?;
let value = decode_bytes_hex(&s).map_err(serde::de::Error::custom)?;
Ok(Some(value))
}
2 changes: 1 addition & 1 deletion sui_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ impl AuthorityState {
pub async fn new_with_genesis_modules(
committee: Committee,
name: AuthorityName,
secret: StableSyncSigner,
secret: StableSyncAuthoritySigner,
store: Arc<AuthorityStore>,
) -> Self {
let (genesis_modules, native_functions) = genesis::clone_genesis_data();
Expand Down

0 comments on commit 3c66a43

Please sign in to comment.