Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove staking rewards address #687

Merged
merged 8 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/687-remove-staking-address.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- PoS: Removed staking reward addresses in preparation of auto-staked rewards
system. ([#687](https://github.com/anoma/namada/pull/687))
27 changes: 5 additions & 22 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,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 @@ -1194,9 +1194,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 @@ -1289,8 +1289,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 @@ -1528,10 +1526,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 @@ -1542,21 +1538,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 @@ -1578,10 +1570,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 @@ -1591,11 +1579,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 @@ -154,10 +154,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 @@ -169,7 +167,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 @@ -203,18 +200,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 @@ -245,51 +230,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 @@ -324,23 +282,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 @@ -361,10 +303,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