Skip to content

Commit

Permalink
Merge branch 'brent/remove-staking-address' (#687)
Browse files Browse the repository at this point in the history
* brent/remove-staking-address:
  remove staking rewards address from cli strings and docs strings
  wallet: remove validator rewards key
  client: remove staking rewards address from init-validator result
  [ci] wasm checksums update
  remove staking reward address from genesis toml files
  remove staking reward address from all code
  • Loading branch information
tzemanovic committed Oct 26, 2022
2 parents fcbf3e8 + 1374dae commit a8b577c
Show file tree
Hide file tree
Showing 24 changed files with 43 additions and 484 deletions.
27 changes: 5 additions & 22 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,8 @@ pub mod cmds {
fn def() -> App {
App::new(Self::CMD)
.about(
"Send a signed transaction to create a new validator and \
its staking reward account.",
"Send a signed transaction to create a new validator \
account.",
)
.add_args::<args::TxInitValidator>()
}
Expand Down Expand Up @@ -1232,9 +1232,9 @@ pub mod cmds {
fn def() -> App {
App::new(Self::CMD)
.about(
"Initialize genesis validator's address, staking reward \
address, consensus key, validator account key and \
staking rewards key and use it in the ledger's node.",
"Initialize genesis validator's address, consensus key \
and validator account key and use it in the ledger's \
node.",
)
.add_args::<args::InitGenesisValidator>()
}
Expand Down 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
68 changes: 4 additions & 64 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,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 @@ -175,7 +173,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 @@ -209,18 +206,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 @@ -251,51 +236,24 @@ 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));
let (mut ctx, initialized_accounts) =
process_tx(ctx, &tx_args, tx, Some(&source)).await;
if !tx_args.dry_run {
let (validator_address_alias, validator_address, rewards_address_alias) =
let (validator_address_alias, validator_address) =
match &initialized_accounts[..] {
// There should be 2 accounts, one for the validator itself, one
// for its staking reward address.
[account_1, account_2] => {
// We need to find out which address is which
let (validator_address, rewards_address) =
if rpc::is_validator(account_1, tx_args.ledger_address)
.await
{
(account_1, account_2)
} else {
(account_2, account_1)
};

// There should be 1 account for the validator itself
[validator_address] => {
let validator_address_alias = match tx_args
.initialized_account_alias
{
Expand Down Expand Up @@ -330,23 +288,7 @@ pub async fn submit_init_validator(
validator_address.encode()
);
}
let rewards_address_alias =
format!("{}-rewards", validator_address_alias);
if let Some(new_alias) = ctx.wallet.add_address(
rewards_address_alias.clone(),
rewards_address.clone(),
) {
println!(
"Added alias {} for address {}.",
new_alias,
rewards_address.encode()
);
}
(
validator_address_alias,
validator_address.clone(),
rewards_address_alias,
)
(validator_address_alias, validator_address.clone())
}
_ => {
eprintln!("Expected two accounts to be created");
Expand All @@ -367,10 +309,8 @@ pub async fn submit_init_validator(
"The validator's addresses and keys were stored in the wallet:"
);
println!(" Validator address \"{}\"", validator_address_alias);
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
32 changes: 2 additions & 30 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 @@ -898,9 +874,8 @@ fn init_established_account(
}
}

/// Initialize genesis validator's address, staking reward address,
/// consensus key, validator account key and staking rewards key and use
/// it in the ledger's node.
/// Initialize genesis validator's address, consensus key and validator account
/// key and use it in the ledger's node.
pub fn init_genesis_validator(
global_args: args::Global,
args::InitGenesisValidator {
Expand Down Expand Up @@ -940,9 +915,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
Loading

0 comments on commit a8b577c

Please sign in to comment.