Add an account command to enable/disable validators (#2386)

## Issue Addressed

Resolves #2322 

## Proposed Changes

Adds a `modify` command to `lighthouse account validator` with subcommands to enable and disable specific or all pubkeys.
This commit is contained in:
Pawan Dhananjay
2021-06-16 09:16:51 +00:00
parent 3b600acdc5
commit dffe31c312
3 changed files with 139 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ use account_manager::{
validator::{
create::*,
import::{self, CMD as IMPORT_CMD},
modify::{ALL, CMD as MODIFY_CMD, DISABLE, ENABLE, PUBKEY_FLAG},
CMD as VALIDATOR_CMD,
},
wallet::{
@@ -475,10 +476,21 @@ fn validator_import_launchpad() {
// Validator should be registered with slashing protection.
check_slashing_protection(&dst_dir, std::iter::once(keystore.public_key().unwrap()));
// Disable all the validators in validator_definition.
output_result(
validator_cmd()
.arg(format!("--{}", VALIDATOR_DIR_FLAG))
.arg(dst_dir.path().as_os_str())
.arg(MODIFY_CMD)
.arg(DISABLE)
.arg(format!("--{}", ALL)),
)
.unwrap();
let defs = ValidatorDefinitions::open(&dst_dir).unwrap();
let expected_def = ValidatorDefinition {
enabled: true,
let mut expected_def = ValidatorDefinition {
enabled: false,
description: "".into(),
graffiti: None,
voting_public_key: keystore.public_key().unwrap(),
@@ -490,7 +502,28 @@ fn validator_import_launchpad() {
};
assert!(
defs.as_slice() == &[expected_def],
defs.as_slice() == &[expected_def.clone()],
"validator defs file should be accurate"
);
// Enable keystore validator again
output_result(
validator_cmd()
.arg(format!("--{}", VALIDATOR_DIR_FLAG))
.arg(dst_dir.path().as_os_str())
.arg(MODIFY_CMD)
.arg(ENABLE)
.arg(format!("--{}", PUBKEY_FLAG))
.arg(format!("{}", keystore.public_key().unwrap())),
)
.unwrap();
let defs = ValidatorDefinitions::open(&dst_dir).unwrap();
expected_def.enabled = true;
assert!(
defs.as_slice() == &[expected_def.clone()],
"validator defs file should be accurate"
);
}