Skip to content

Commit

Permalink
remove staking reward address from all code
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Oct 25, 2022
1 parent 99945f7 commit 063d2ed
Show file tree
Hide file tree
Showing 18 changed files with 13 additions and 395 deletions.
17 changes: 0 additions & 17 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,8 +1328,6 @@ pub mod args {
const RAW_ADDRESS: Arg<Address> = arg("address");
const RAW_ADDRESS_OPT: ArgOpt<Address> = RAW_ADDRESS.opt();
const RAW_PUBLIC_KEY_OPT: ArgOpt<common::PublicKey> = arg_opt("public-key");
const REWARDS_CODE_PATH: ArgOpt<PathBuf> = arg_opt("rewards-code-path");
const REWARDS_KEY: ArgOpt<WalletPublicKey> = arg_opt("rewards-key");
const SCHEME: ArgDefault<SchemeType> =
arg_default("scheme", DefaultFn(|| SchemeType::Ed25519));
const SIGNER: ArgOpt<WalletAddress> = arg_opt("signer");
Expand Down Expand Up @@ -1567,10 +1565,8 @@ pub mod args {
pub scheme: SchemeType,
pub account_key: Option<WalletPublicKey>,
pub consensus_key: Option<WalletKeypair>,
pub rewards_account_key: Option<WalletPublicKey>,
pub protocol_key: Option<WalletPublicKey>,
pub validator_vp_code_path: Option<PathBuf>,
pub rewards_vp_code_path: Option<PathBuf>,
pub unsafe_dont_encrypt: bool,
}

Expand All @@ -1581,21 +1577,17 @@ pub mod args {
let scheme = SCHEME.parse(matches);
let account_key = VALIDATOR_ACCOUNT_KEY.parse(matches);
let consensus_key = VALIDATOR_CONSENSUS_KEY.parse(matches);
let rewards_account_key = REWARDS_KEY.parse(matches);
let protocol_key = PROTOCOL_KEY.parse(matches);
let validator_vp_code_path = VALIDATOR_CODE_PATH.parse(matches);
let rewards_vp_code_path = REWARDS_CODE_PATH.parse(matches);
let unsafe_dont_encrypt = UNSAFE_DONT_ENCRYPT.parse(matches);
Self {
tx,
source,
scheme,
account_key,
consensus_key,
rewards_account_key,
protocol_key,
validator_vp_code_path,
rewards_vp_code_path,
unsafe_dont_encrypt,
}
}
Expand All @@ -1617,10 +1609,6 @@ pub mod args {
"A consensus key for the validator account. A new one \
will be generated if none given.",
))
.arg(REWARDS_KEY.def().about(
"A public key for the staking reward account. A new one \
will be generated if none given.",
))
.arg(PROTOCOL_KEY.def().about(
"A public key for signing protocol transactions. A new \
one will be generated if none given.",
Expand All @@ -1630,11 +1618,6 @@ pub mod args {
for the validator account. Uses the default validator VP \
if none specified.",
))
.arg(REWARDS_CODE_PATH.def().about(
"The path to the validity predicate WASM code to be used \
for the staking reward account. Uses the default staking \
reward VP if none specified.",
))
.arg(UNSAFE_DONT_ENCRYPT.def().about(
"UNSAFE: Do not encrypt the generated keypairs. Do not \
use this for keys used in a live network.",
Expand Down
32 changes: 0 additions & 32 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,8 @@ pub async fn submit_init_validator(
scheme,
account_key,
consensus_key,
rewards_account_key,
protocol_key,
validator_vp_code_path,
rewards_vp_code_path,
unsafe_dont_encrypt,
}: args::TxInitValidator,
) {
Expand All @@ -174,7 +172,6 @@ pub async fn submit_init_validator(

let validator_key_alias = format!("{}-key", alias);
let consensus_key_alias = format!("{}-consensus-key", alias);
let rewards_key_alias = format!("{}-rewards-key", alias);
let account_key = ctx.get_opt_cached(&account_key).unwrap_or_else(|| {
println!("Generating validator account key...");
ctx.wallet
Expand Down Expand Up @@ -208,18 +205,6 @@ pub async fn submit_init_validator(
.1
});

let rewards_account_key =
ctx.get_opt_cached(&rewards_account_key).unwrap_or_else(|| {
println!("Generating staking reward account key...");
ctx.wallet
.gen_key(
scheme,
Some(rewards_key_alias.clone()),
unsafe_dont_encrypt,
)
.1
.ref_to()
});
let protocol_key = ctx.get_opt_cached(&protocol_key);

if protocol_key.is_none() {
Expand Down Expand Up @@ -250,30 +235,14 @@ pub async fn submit_init_validator(
safe_exit(1)
}
}
let rewards_vp_code = rewards_vp_code_path
.map(|path| ctx.read_wasm(path))
.unwrap_or_else(|| ctx.read_wasm(VP_USER_WASM));
// Validate the rewards VP code
if let Err(err) = vm::validate_untrusted_wasm(&rewards_vp_code) {
eprintln!(
"Staking reward account validity predicate code validation failed \
with {}",
err
);
if !tx_args.force {
safe_exit(1)
}
}
let tx_code = ctx.read_wasm(TX_INIT_VALIDATOR_WASM);

let data = InitValidator {
account_key,
consensus_key: consensus_key.ref_to(),
rewards_account_key,
protocol_key,
dkg_key,
validator_vp_code,
rewards_vp_code,
};
let data = data.try_to_vec().expect("Encoding tx data shouldn't fail");
let tx = Tx::new(tx_code, Some(data));
Expand Down Expand Up @@ -369,7 +338,6 @@ pub async fn submit_init_validator(
println!(" Staking reward address \"{}\"", rewards_address_alias);
println!(" Validator account key \"{}\"", validator_key_alias);
println!(" Consensus key \"{}\"", consensus_key_alias);
println!(" Staking reward key \"{}\"", rewards_key_alias);
println!(
"The ledger node has been setup to use this validator's address \
and consensus key."
Expand Down
27 changes: 0 additions & 27 deletions apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,7 @@ pub fn init_network(

// Generate account and reward addresses
let address = address::gen_established_address("validator account");
let reward_address =
address::gen_established_address("validator reward account");
config.address = Some(address.to_string());
config.staking_reward_address = Some(reward_address.to_string());

// Generate the consensus, account and reward keys, unless they're
// pre-defined.
Expand Down Expand Up @@ -518,24 +515,6 @@ pub fn init_network(
keypair.ref_to()
});

let staking_reward_pk = try_parse_public_key(
format!("validator {name} staking reward key"),
&config.staking_reward_public_key,
)
.unwrap_or_else(|| {
let alias = format!("{}-reward-key", name);
println!(
"Generating validator {} staking reward account key...",
name
);
let (_alias, keypair) = wallet.gen_key(
SchemeType::Ed25519,
Some(alias),
unsafe_dont_encrypt,
);
keypair.ref_to()
});

let protocol_pk = try_parse_public_key(
format!("validator {name} protocol key"),
&config.protocol_public_key,
Expand Down Expand Up @@ -583,8 +562,6 @@ pub fn init_network(
Some(genesis_config::HexString(consensus_pk.to_string()));
config.account_public_key =
Some(genesis_config::HexString(account_pk.to_string()));
config.staking_reward_public_key =
Some(genesis_config::HexString(staking_reward_pk.to_string()));

config.protocol_public_key =
Some(genesis_config::HexString(protocol_pk.to_string()));
Expand All @@ -593,7 +570,6 @@ pub fn init_network(

// Write keypairs to wallet
wallet.add_address(name.clone(), address);
wallet.add_address(format!("{}-reward", &name), reward_address);

wallet.save().unwrap();
});
Expand Down Expand Up @@ -940,9 +916,6 @@ pub fn init_genesis_validator(
account_public_key: Some(HexString(
pre_genesis.account_key.ref_to().to_string(),
)),
staking_reward_public_key: Some(HexString(
pre_genesis.rewards_key.ref_to().to_string(),
)),
protocol_public_key: Some(HexString(
pre_genesis
.store
Expand Down
52 changes: 1 addition & 51 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,13 @@ pub mod genesis_config {
pub consensus_public_key: Option<HexString>,
// Public key for validator account. (default: generate)
pub account_public_key: Option<HexString>,
// Public key for staking reward account. (default: generate)
pub staking_reward_public_key: Option<HexString>,
// Public protocol signing key for validator account. (default:
// generate)
pub protocol_public_key: Option<HexString>,
// Public DKG session key for validator account. (default: generate)
pub dkg_public_key: Option<HexString>,
// Validator address (default: generate).
pub address: Option<String>,
// Staking reward account address (default: generate).
pub staking_reward_address: Option<String>,
// Total number of tokens held at genesis.
// XXX: u64 doesn't work with toml-rs!
pub tokens: Option<u64>,
Expand All @@ -178,8 +174,6 @@ pub mod genesis_config {
pub non_staked_balance: Option<u64>,
// Filename of validator VP. (default: default validator VP)
pub validator_vp: Option<String>,
// Filename of staking reward account VP. (default: user VP)
pub staking_reward_vp: Option<String>,
// IP:port of the validator. (used in generation only)
pub net_address: Option<String>,
/// Tendermint node key is used to derive Tendermint node ID for node
Expand Down Expand Up @@ -277,30 +271,18 @@ pub mod genesis_config {
) -> Validator {
let validator_vp_name = config.validator_vp.as_ref().unwrap();
let validator_vp_config = wasm.get(validator_vp_name).unwrap();
let reward_vp_name = config.staking_reward_vp.as_ref().unwrap();
let reward_vp_config = wasm.get(reward_vp_name).unwrap();

Validator {
pos_data: GenesisValidator {
address: Address::decode(&config.address.as_ref().unwrap())
.unwrap(),
staking_reward_address: Address::decode(
&config.staking_reward_address.as_ref().unwrap(),
)
.unwrap(),
tokens: token::Amount::whole(config.tokens.unwrap_or_default()),
consensus_key: config
.consensus_public_key
.as_ref()
.unwrap()
.to_public_key()
.unwrap(),
staking_reward_key: config
.staking_reward_public_key
.as_ref()
.unwrap()
.to_public_key()
.unwrap(),
},
account_key: config
.account_public_key
Expand Down Expand Up @@ -330,16 +312,6 @@ pub mod genesis_config {
.unwrap()
.to_sha256_bytes()
.unwrap(),
reward_vp_code_path: reward_vp_config.filename.to_owned(),
reward_vp_sha256: reward_vp_config
.sha256
.clone()
.unwrap_or_else(|| {
eprintln!("Unknown validator VP WASM sha256");
cli::safe_exit(1);
})
.to_sha256_bytes()
.unwrap(),
}
}

Expand Down Expand Up @@ -658,10 +630,6 @@ pub struct Validator {
pub validator_vp_code_path: String,
/// Expected SHA-256 hash of the validator VP
pub validator_vp_sha256: [u8; 32],
/// Staking reward account code WASM
pub reward_vp_code_path: String,
/// Expected SHA-256 hash of the staking reward VP
pub reward_vp_sha256: [u8; 32],
}

#[derive(
Expand Down Expand Up @@ -736,23 +704,13 @@ pub fn genesis() -> Genesis {
// `tests::gen_genesis_validator` below.
let consensus_keypair = wallet::defaults::validator_keypair();
let account_keypair = wallet::defaults::validator_keypair();
let ed_staking_reward_keypair = ed25519::SecretKey::try_from_slice(&[
61, 198, 87, 204, 44, 94, 234, 228, 217, 72, 245, 27, 40, 2, 151, 174,
24, 247, 69, 6, 9, 30, 44, 16, 88, 238, 77, 162, 243, 125, 240, 206,
])
.unwrap();
let staking_reward_keypair =
common::SecretKey::try_from_sk(&ed_staking_reward_keypair).unwrap();
let address = wallet::defaults::validator_address();
let staking_reward_address = Address::decode("atest1v4ehgw36xcersvee8qerxd35x9prsw2xg5erxv6pxfpygd2x89z5xsf5xvmnysejgv6rwd2rnj2avt").unwrap();
let (protocol_keypair, dkg_keypair) = wallet::defaults::validator_keys();
let validator = Validator {
pos_data: GenesisValidator {
address,
staking_reward_address,
tokens: token::Amount::whole(200_000),
consensus_key: consensus_keypair.ref_to(),
staking_reward_key: staking_reward_keypair.ref_to(),
},
account_key: account_keypair.ref_to(),
protocol_key: protocol_keypair.ref_to(),
Expand All @@ -761,8 +719,6 @@ pub fn genesis() -> Genesis {
// TODO replace with https://github.com/anoma/anoma/issues/25)
validator_vp_code_path: vp_user_path.into(),
validator_vp_sha256: Default::default(),
reward_vp_code_path: vp_user_path.into(),
reward_vp_sha256: Default::default(),
};
let parameters = Parameters {
epoch_duration: EpochDuration {
Expand Down Expand Up @@ -853,24 +809,18 @@ pub mod tests {
use crate::wallet;

/// Run `cargo test gen_genesis_validator -- --nocapture` to generate a
/// new genesis validator address, staking reward address and keypair.
/// new genesis validator address and keypair.
#[test]
fn gen_genesis_validator() {
let address = gen_established_address();
let staking_reward_address = gen_established_address();
let mut rng: ThreadRng = thread_rng();
let keypair: common::SecretKey =
ed25519::SigScheme::generate(&mut rng).try_to_sk().unwrap();
let kp_arr = keypair.try_to_vec().unwrap();
let staking_reward_keypair: common::SecretKey =
ed25519::SigScheme::generate(&mut rng).try_to_sk().unwrap();
let srkp_arr = staking_reward_keypair.try_to_vec().unwrap();
let (protocol_keypair, dkg_keypair) =
wallet::defaults::validator_keys();
println!("address: {}", address);
println!("staking_reward_address: {}", staking_reward_address);
println!("keypair: {:?}", kp_arr);
println!("staking_reward_keypair: {:?}", srkp_arr);
println!("protocol_keypair: {:?}", protocol_keypair);
println!("dkg_keypair: {:?}", dkg_keypair.try_to_vec().unwrap());
}
Expand Down
Loading

0 comments on commit 063d2ed

Please sign in to comment.