Skip to content

Commit 1373dcf

Browse files
committed
Add validator-manager (#3502)
## Issue Addressed Addresses #2557 ## Proposed Changes Adds the `lighthouse validator-manager` command, which provides: - `lighthouse validator-manager create` - Creates a `validators.json` file and a `deposits.json` (same format as https://github.com/ethereum/staking-deposit-cli) - `lighthouse validator-manager import` - Imports validators from a `validators.json` file to the VC via the HTTP API. - `lighthouse validator-manager move` - Moves validators from one VC to the other, utilizing only the VC API. ## Additional Info In 98bcb94 I've reduced some VC `ERRO` and `CRIT` warnings to `WARN` or `DEBG` for the case where a pubkey is missing from the validator store. These were being triggered when we removed a validator but still had it in caches. It seems to me that `UnknownPubkey` will only happen in the case where we've removed a validator, so downgrading the logs is prudent. All the logs are `DEBG` apart from attestations and blocks which are `WARN`. I thought having *some* logging about this condition might help us down the track. In 856cd7e I've made the VC delete the corresponding password file when it's deleting a keystore. This seemed like nice hygiene. Notably, it'll only delete that password file after it scans the validator definitions and finds that no other validator is also using that password file.
1 parent 5ea7505 commit 1373dcf

File tree

69 files changed

+6058
-743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+6058
-743
lines changed

Cargo.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ members = [
8383
"validator_client",
8484
"validator_client/slashing_protection",
8585

86+
"validator_manager",
87+
8688
"watch",
8789
]
8890
resolver = "2"

account_manager/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ safe_arith = {path = "../consensus/safe_arith"}
2424
slot_clock = { path = "../common/slot_clock" }
2525
filesystem = { path = "../common/filesystem" }
2626
sensitive_url = { path = "../common/sensitive_url" }
27+
serde = { version = "1.0.116", features = ["derive"] }
28+
serde_json = "1.0.58"
2729

2830
[dev-dependencies]
2931
tempfile = "3.1.0"

account_manager/src/common.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,7 @@
1-
use account_utils::PlainText;
2-
use account_utils::{read_input_from_user, strip_off_newlines};
3-
use eth2_wallet::bip39::{Language, Mnemonic};
4-
use std::fs;
5-
use std::path::PathBuf;
6-
use std::str::from_utf8;
7-
use std::thread::sleep;
8-
use std::time::Duration;
1+
use account_utils::read_input_from_user;
92

10-
pub const MNEMONIC_PROMPT: &str = "Enter the mnemonic phrase:";
113
pub const WALLET_NAME_PROMPT: &str = "Enter wallet name:";
124

13-
pub fn read_mnemonic_from_cli(
14-
mnemonic_path: Option<PathBuf>,
15-
stdin_inputs: bool,
16-
) -> Result<Mnemonic, String> {
17-
let mnemonic = match mnemonic_path {
18-
Some(path) => fs::read(&path)
19-
.map_err(|e| format!("Unable to read {:?}: {:?}", path, e))
20-
.and_then(|bytes| {
21-
let bytes_no_newlines: PlainText = strip_off_newlines(bytes).into();
22-
let phrase = from_utf8(bytes_no_newlines.as_ref())
23-
.map_err(|e| format!("Unable to derive mnemonic: {:?}", e))?;
24-
Mnemonic::from_phrase(phrase, Language::English).map_err(|e| {
25-
format!(
26-
"Unable to derive mnemonic from string {:?}: {:?}",
27-
phrase, e
28-
)
29-
})
30-
})?,
31-
None => loop {
32-
eprintln!();
33-
eprintln!("{}", MNEMONIC_PROMPT);
34-
35-
let mnemonic = read_input_from_user(stdin_inputs)?;
36-
37-
match Mnemonic::from_phrase(mnemonic.as_str(), Language::English) {
38-
Ok(mnemonic_m) => {
39-
eprintln!("Valid mnemonic provided.");
40-
eprintln!();
41-
sleep(Duration::from_secs(1));
42-
break mnemonic_m;
43-
}
44-
Err(_) => {
45-
eprintln!("Invalid mnemonic");
46-
}
47-
}
48-
},
49-
};
50-
Ok(mnemonic)
51-
}
52-
535
/// Reads in a wallet name from the user. If the `--wallet-name` flag is provided, use it. Otherwise
546
/// read from an interactive prompt using tty unless the `--stdin-inputs` flag is provided.
557
pub fn read_wallet_name_from_cli(

account_manager/src/validator/import.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use account_utils::{
44
eth2_keystore::Keystore,
55
read_password_from_user,
66
validator_definitions::{
7-
recursively_find_voting_keystores, ValidatorDefinition, ValidatorDefinitions,
8-
CONFIG_FILENAME,
7+
recursively_find_voting_keystores, PasswordStorage, ValidatorDefinition,
8+
ValidatorDefinitions, CONFIG_FILENAME,
99
},
1010
ZeroizeString,
1111
};
@@ -277,7 +277,9 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
277277
let suggested_fee_recipient = None;
278278
let validator_def = ValidatorDefinition::new_keystore_with_password(
279279
&dest_keystore,
280-
password_opt,
280+
password_opt
281+
.map(PasswordStorage::ValidatorDefinitions)
282+
.unwrap_or(PasswordStorage::None),
281283
graffiti,
282284
suggested_fee_recipient,
283285
None,

account_manager/src/validator/recover.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use super::create::STORE_WITHDRAW_FLAG;
2-
use crate::common::read_mnemonic_from_cli;
32
use crate::validator::create::COUNT_FLAG;
43
use crate::wallet::create::STDIN_INPUTS_FLAG;
54
use crate::SECRETS_DIR_FLAG;
65
use account_utils::eth2_keystore::{keypair_from_secret, Keystore, KeystoreBuilder};
7-
use account_utils::random_password;
6+
use account_utils::{random_password, read_mnemonic_from_cli};
87
use clap::{App, Arg, ArgMatches};
98
use directory::ensure_dir_exists;
109
use directory::{parse_path_or_default_with_flag, DEFAULT_SECRET_DIR};

account_manager/src/wallet/recover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::common::read_mnemonic_from_cli;
21
use crate::wallet::create::{create_wallet_from_mnemonic, STDIN_INPUTS_FLAG};
32
use crate::wallet::create::{HD_TYPE, NAME_FLAG, PASSWORD_FLAG, TYPE_FLAG};
3+
use account_utils::read_mnemonic_from_cli;
44
use clap::{App, Arg, ArgMatches};
55
use std::path::PathBuf;
66

book/src/SUMMARY.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* [Run a Node](./run_a_node.md)
1313
* [Become a Validator](./mainnet-validator.md)
1414
* [Validator Management](./validator-management.md)
15+
* [The `validator-manager` Command](./validator-manager.md)
16+
* [Creating validators](./validator-manager-create.md)
17+
* [Moving validators](./validator-manager-move.md)
1518
* [Slashing Protection](./slashing-protection.md)
1619
* [Voluntary Exits](./voluntary-exit.md)
1720
* [Partial Withdrawals](./partial-withdrawal.md)
@@ -41,7 +44,7 @@
4144
* [Remote Signing with Web3Signer](./validator-web3signer.md)
4245
* [Database Configuration](./advanced_database.md)
4346
* [Database Migrations](./database-migrations.md)
44-
* [Key Management](./key-management.md)
47+
* [Key Management (Deprecated)](./key-management.md)
4548
* [Key Recovery](./key-recovery.md)
4649
* [Advanced Networking](./advanced_networking.md)
4750
* [Running a Slasher](./slasher.md)

book/src/key-management.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
# Key Management
1+
# Key Management (Deprecated)
22

33
[launchpad]: https://launchpad.ethereum.org/
44

5-
>
6-
> **Note: While Lighthouse is able to generate the validator keys and the deposit data file to submit to the deposit contract, we strongly recommend using the [staking-deposit-cli](https://github.com/ethereum/staking-deposit-cli) to create validators keys and the deposit data file. This is because the [staking-deposit-cli](https://github.com/ethereum/staking-deposit-cli) has the option to assign a withdrawal address during the key generation process, while Lighthouse wallet will always generate keys with withdrawal credentials of type 0x00. This means that users who created keys using Lighthouse will have to update their withdrawal credentials in the future to enable withdrawals. In addition, Lighthouse generates the deposit data file in the form of `*.rlp`, which cannot be uploaded to the [Staking launchpad][launchpad] that accepts only `*.json` file. This means that users have to directly interact with the deposit contract to be able to submit the deposit if they were to generate the files using Lighthouse.**
5+
**⚠️ The information on this page refers to tooling and process that have been deprecated. Please read the "Deprecation Notice". ⚠️**
6+
7+
## Deprecation Notice
8+
9+
This page recommends the use of the `lighthouse account-manager` tool to create
10+
validators. This tool will always generate keys with the withdrawal credentials
11+
of type `0x00`. This means the users who created keys using `lighthouse
12+
account-manager` will have to update their withdrawal credentials in a
13+
separate step to receive staking rewards.
14+
15+
In addition, Lighthouse generates the deposit data file in the form of `*.rlp`,
16+
which cannot be uploaded to the [Staking launchpad][launchpad] that accepts only
17+
`*.json` file. This means that users have to directly interact with the deposit
18+
contract to be able to submit the deposit if they were to generate the files
19+
using Lighthouse.
20+
21+
Rather than continuing to read this page, we recommend users visit either:
22+
23+
- The [Staking Launchpad][launchpad] for detailed, beginner-friendly instructions.
24+
- The [staking-deposit-cli](https://github.com/ethereum/staking-deposit-cli) for a CLI tool used by the [Staking Launchpad][launchpad].
25+
- The [validator-manager documentation](./validator-manager.md) for a Lighthouse-specific tool for streamlined validator management tools.
26+
27+
## The `lighthouse account-manager`
728

829
Lighthouse uses a _hierarchical_ key management system for producing validator
930
keys. It is hierarchical because each validator key can be _derived_ from a

book/src/validator-management.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ standard directories and do not start their `lighthouse vc` with the
1313
this document. However, users with more complex needs may find this document
1414
useful.
1515

16+
The [lighthouse validator-manager](./validator-manager.md) command can be used
17+
to create and import validators to a Lighthouse VC. It can also be used to move
18+
validators between two Lighthouse VCs.
19+
1620
## Introducing the `validator_definitions.yml` file
1721

1822
The `validator_definitions.yml` file is located in the `validator-dir`, which

0 commit comments

Comments
 (0)