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

Validator manager commands for the Keymanager APIs #6261

Open
wants to merge 86 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
0fa74cd
Validator manager commands for standard key-manager APIs
pahor167 Mar 4, 2024
f6d11bc
Merge latest unstable
chong-he Jul 29, 2024
83967a5
Fix Some in lib.rs
chong-he Jul 31, 2024
bf6e3b7
Replace Arg::with_name with Arg::new
chong-he Jul 31, 2024
1337a2f
Update takes_value
chong-he Jul 31, 2024
1082426
Remove clap::App
chong-he Jul 31, 2024
526603c
Change App to Command
chong-he Jul 31, 2024
0075fdd
Add command in use
chong-he Jul 31, 2024
6803092
Remove generic in ArgMatches
chong-he Jul 31, 2024
1630435
Fix matches.get_flag
chong-he Aug 1, 2024
1c8b3b3
Fixes
chong-he Aug 1, 2024
b80d16e
fix error handling
chong-he Aug 1, 2024
509d590
SetTrue in import
chong-he Aug 2, 2024
bb283a2
Fix
chong-he Aug 2, 2024
e1452f8
Fix builder-proposal flag (will delete the flag later)
chong-he Aug 2, 2024
e0918a8
Minor fix
chong-he Aug 2, 2024
97afc09
Fix prefer_builder_proposals
chong-he Aug 2, 2024
2212dd4
Remove unwrap
chong-he Aug 5, 2024
47382a7
Error handling from Michael
chong-he Aug 6, 2024
5f56ba5
Add cli help text
chong-he Aug 7, 2024
c6c8954
Use None in import to simplify
chong-he Aug 7, 2024
82d578f
Delete unwrap
chong-he Aug 7, 2024
d71cca9
Revert flags option
chong-he Aug 7, 2024
98ac81b
Simplify help command code
chong-he Aug 7, 2024
ad7cb23
Remove flag header in move
chong-he Aug 7, 2024
2f9f0dd
Merge remote-tracking branch 'origin/unstable' into pahor/validator-m…
michaelsproul Aug 8, 2024
6069c94
Add log in VC when keystore is deleted
chong-he Aug 12, 2024
ff0c841
Delete duplicated log when validator does not exist
chong-he Aug 12, 2024
0e4e9a4
Simplify log code
chong-he Aug 12, 2024
eadec07
Rename remove to delete
chong-he Aug 13, 2024
97196cc
cargo-fmt
chong-he Aug 13, 2024
6fb9f83
Try to remove a function
chong-he Aug 13, 2024
bed168c
make-cli
chong-he Aug 13, 2024
a55cc5b
Error handling
chong-he Aug 13, 2024
b5b9537
Merge branch 'vm' of https://github.com/chong-he/lighthouse into vm
chong-he Aug 13, 2024
100ee22
Update CLI hel text
chong-he Aug 13, 2024
610f971
make-cli
chong-he Aug 13, 2024
64a4f67
Fix checks
chong-he Aug 15, 2024
9ba60be
Merge branch 'vm' of https://github.com/chong-he/lighthouse into vm
chong-he Aug 15, 2024
e079eb4
Try to fix check errors
chong-he Aug 15, 2024
2228463
Fix test
chong-he Aug 15, 2024
e101583
Remove changes
chong-he Aug 15, 2024
617273f
Update flag name
chong-he Aug 16, 2024
369bae5
CLI display order
chong-he Aug 16, 2024
c24e779
Move builde_proposals flag
chong-he Aug 16, 2024
3e6c8cb
Add doc
chong-he Aug 16, 2024
7a21d40
mdlint
chong-he Aug 16, 2024
794aa39
Update validator_manager/src/list_validators.rs
chong-he Sep 4, 2024
ce7e573
Delete empty line
chong-he Sep 4, 2024
5f0c4ee
Fix list
chong-he Sep 4, 2024
a874551
Simplify delete
chong-he Sep 4, 2024
4726501
Add support to delete more validators
chong-he Sep 9, 2024
062613e
Fix test
chong-he Sep 9, 2024
7d727e9
Rename response
chong-he Sep 9, 2024
3df5a37
Add (s)
chong-he Sep 9, 2024
f4ecc33
Add test to delete multiple validators
chong-he Sep 10, 2024
a0f8599
Book and cli
chong-he Sep 10, 2024
894d8f9
Make cli
chong-he Sep 10, 2024
f6f6d16
Only log when keystore is deleted
chong-he Sep 10, 2024
d8b6142
Revise deletion log
chong-he Sep 11, 2024
9ad2e64
Add validator pubkey to error message
chong-he Sep 11, 2024
da6a100
Merge import
chong-he Sep 18, 2024
2d7858c
Thank you Mac
chong-he Sep 18, 2024
5de071e
Test
chong-he Sep 18, 2024
061f0d8
Add flags
chong-he Sep 18, 2024
184e28f
Error handling for password
chong-he Sep 18, 2024
7f2152b
make cli
chong-he Sep 19, 2024
7d978ac
Merge remote-tracking branch 'origin/unstable' into vm
chong-he Sep 19, 2024
65e93c8
make cli
chong-he Sep 19, 2024
b62bc49
Fix test
chong-he Sep 19, 2024
a2d9e29
Merge branch 'vm' of https://github.com/chong-he/lighthouse into vm
chong-he Sep 19, 2024
9daff6f
Fix test
chong-he Sep 19, 2024
3f97acd
vm test
chong-he Sep 19, 2024
795e1df
Debug trait thank you Michael
chong-he Sep 19, 2024
8fba16a
Fix test
chong-he Sep 19, 2024
8a3aa07
Merge branch 'unstable' into vm
chong-he Sep 19, 2024
10883a5
test
chong-he Sep 19, 2024
858dac5
testing
chong-he Sep 19, 2024
0e37ad8
Combine import validator(s)
chong-he Sep 20, 2024
aeb91c7
make cli
chong-he Sep 20, 2024
e81dfa3
Add requires
chong-he Sep 20, 2024
4c6ae73
Update book
chong-he Sep 20, 2024
779eca1
mdlint
chong-he Sep 20, 2024
3e97c75
Only show import log when import is successful
chong-he Sep 20, 2024
df599ca
delete testing
chong-he Sep 20, 2024
895c6cd
Test for standard format
chong-he Sep 20, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [The `validator-manager` Command](./validator-manager.md)
* [Creating validators](./validator-manager-create.md)
* [Moving validators](./validator-manager-move.md)
* [Managing validators](./validator-manager-api.md)
* [Slashing Protection](./slashing-protection.md)
* [Voluntary Exits](./voluntary-exit.md)
* [Partial Withdrawals](./partial-withdrawal.md)
Expand Down
5 changes: 5 additions & 0 deletions book/src/help_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Commands:
"create-validators" command. This command only supports validators
signing via a keystore on the local file system (i.e., not Web3Signer
validators).
list
Lists all validators in a validator client using the HTTP API.
delete
Deletes one or more validators from a validator client using the HTTP
API.
help
Print this message or the help of the given subcommand(s)

Expand Down
23 changes: 23 additions & 0 deletions book/src/help_vm_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ command.
Usage: lighthouse validator_manager import [OPTIONS] --validators-file <PATH_TO_JSON_FILE>

Options:
--builder-boost-factor <UINT64>
When provided, the imported validator will use this percentage
multiplier to apply to the builder's payload value when choosing
between a builder payload header and payload from the local execution
node.
-d, --datadir <DIR>
Used to specify a custom root data directory for lighthouse keys and
databases. Defaults to $HOME/.lighthouse/{network} where network is
Expand All @@ -17,6 +22,10 @@ Options:
Specifies the verbosity level used when emitting logs to the terminal.
[default: info] [possible values: info, debug, trace, warn, error,
crit]
--gas-limit <UINT64>
When provided, the imported validator will use this gas limit. It is
recommended to leave this as the default value by not specifying this
flag.
--genesis-state-url <URL>
A URL of a beacon-API compatible server from which to download the
genesis state. Checkpoint sync server URLs can generally be used with
Expand Down Expand Up @@ -50,6 +59,11 @@ Options:
--network <network>
Name of the Eth2 chain Lighthouse will sync and follow. [possible
values: mainnet, gnosis, chiado, sepolia, holesky]
--password <STRING>
Password of the keystore file.
--prefer-builder-proposals
When provided, the imported validator will always prefer blocks
constructed by builders, regardless of payload value.
--safe-slots-to-import-optimistically <INTEGER>
Used to coordinate manual overrides of the
SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY parameter. This flag should only
Expand All @@ -58,6 +72,9 @@ Options:
attack at the PoS transition block. Incorrect use of this flag can
cause your node to possibly accept an invalid chain or sync more
slowly. Be extremely careful with this flag.
--suggested-fee-recipient <ETH1_ADDRESS>
When provided, the imported validator will use the suggested fee
recipient. Omit this flag to use the default value from the VC.
-t, --testnet-dir <DIR>
Path to directory containing eth2_testnet specs. Defaults to a
hard-coded Lighthouse testnet. Only effective if there is no existing
Expand Down Expand Up @@ -95,6 +112,9 @@ Options:
http://localhost:5062]

Flags:
--builder-proposals
When provided, the imported validator will attempt to create blocks
via builder rather than the local EL.
--disable-log-timestamp
If present, do not include timestamps in logging output.
--disable-malloc-tuning
Expand All @@ -121,6 +141,9 @@ Flags:
contain sensitive information about your validator and so this flag
should be used with caution. For Windows users, the log file
permissions will be inherited from the parent folder.
--standard-format
Use this flag when the validator keystore files are generated using
staking-deposit-cli or ethstaker-deposit-cli.
--stdin-inputs
If present, read all user inputs from stdin instead of tty.
```
Expand Down
39 changes: 39 additions & 0 deletions book/src/validator-manager-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Managing Validators

The `lighthouse validator-manager` supports the [Keymanager API](https://ethereum.github.io/keymanager-APIs/#/) to list, import and delete keystores via the HTTP API. This requires the validator client running with the flag `--http`.

## Delete

The `delete` command deletes one or more validators from the validator client. It will also modify the `validator_definitions.yml` file automatically so there is no manual action required from the user after the delete. To `delete`:

```bash
lighthouse vm delete --vc-token <API-TOKEN-PATH> --validators pubkey1, pubkey2
```

Example:

```bash
lighthouse vm remove --vc-token ~/.lighthouse/mainnet/validators/api-token.txt --validators 0x8885c29b8f88ee9b9a37b480fd4384fed74bda33d85bc8171a904847e65688b6c9bb4362d6597fd30109fb2def6c3ae4, 0xa262dae3dcd2b2e280af534effa16bedb27c06f2959e114d53bd2a248ca324a018dc73179899a066149471a94a1bc92f
```

## Import

The `import` command imports validator keystores generated by the staking-deposit-cli. To import validator keystore:

```bash
lighthouse vm import --standard-format --vc-token <API-TOKEN-PATH> --validators-file /path/to/json --password keystore_password
```

Example:

```
lighthouse vm import --standard-format --vc-token ~/.lighthouse/mainnet/validators/api-token.txt --validator-file keystore.json --password keystore_password
```

## List

To list the validators running on the validator client:

```bash
lighthouse vm list --vc-token ~/.lighthouse/mainnet/validators/api-token.txt
```
2 changes: 2 additions & 0 deletions book/src/validator-manager-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ lighthouse \
> Be sure to remove `./validators.json` after the import is successful since it
> contains unencrypted validator keystores.

> Note: To import validators with validator-manager using keystore files created using the staking deposit cli, refer to [Managing Validators](./validator-manager-api.md#import).

## Detailed Guide

This guide will create two validators and import them to a VC. For simplicity,
Expand Down
13 changes: 12 additions & 1 deletion common/account_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ use eth2_wallet::{
use filesystem::{create_with_600_perms, Error as FsError};
use rand::{distributions::Alphanumeric, Rng};
use serde::{Deserialize, Serialize};
use std::fs::{self, File};
use std::io;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::str::from_utf8;
use std::thread::sleep;
use std::time::Duration;
use std::{
fs::{self, File},
str::FromStr,
};
use zeroize::Zeroize;

pub mod validator_definitions;
Expand Down Expand Up @@ -215,6 +218,14 @@ pub fn mnemonic_from_phrase(phrase: &str) -> Result<Mnemonic, String> {
#[serde(transparent)]
pub struct ZeroizeString(String);

impl FromStr for ZeroizeString {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.to_owned()))
}
}

impl From<String> for ZeroizeString {
fn from(s: String) -> Self {
Self(s)
Expand Down
16 changes: 16 additions & 0 deletions lighthouse/tests/validator_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ pub fn validator_import_defaults() {
vc_url: SensitiveUrl::parse("http://localhost:5062").unwrap(),
vc_token_path: PathBuf::from("./token.json"),
ignore_duplicates: false,
password: None,
fee_recipient: None,
builder_boost_factor: None,
gas_limit: None,
builder_proposals: Some(false),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to let this to be Some(false) for the comparison to be equal. Not sure if this is ok?
The same goes for prefer_builder_proposals field

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is because of here.

We set it in the config directly as Some(get_flag) so in the case the flag is missing it will be set to Some(false).
Unless I'm missing something, I think this should probably just be a parse_optional like the other fields in the config.

enabled: None,
prefer_builder_proposals: Some(false),
standard_format: false,
};
assert_eq!(expected, config);
});
Expand All @@ -220,6 +228,14 @@ pub fn validator_import_misc_flags() {
vc_url: SensitiveUrl::parse("http://localhost:5062").unwrap(),
vc_token_path: PathBuf::from("./token.json"),
ignore_duplicates: true,
password: None,
fee_recipient: None,
builder_boost_factor: None,
gas_limit: None,
builder_proposals: Some(false),
enabled: None,
prefer_builder_proposals: Some(false),
standard_format: false,
};
assert_eq!(expected, config);
});
Expand Down
37 changes: 30 additions & 7 deletions validator_client/src/http_api/keystores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
)));
}

info!(
log,
"Importing keystores via standard HTTP API";
"count" => request.keystores.len(),
);

// Import slashing protection data before keystores, so that new keystores don't start signing
// without it. Do not return early on failure, propagate the failure to each key.
let slashing_protection_status =
Expand Down Expand Up @@ -156,6 +150,19 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
statuses.push(status);
}

let successful_import = statuses
.iter()
.filter(|status| matches!(status.status, ImportKeystoreStatus::Imported))
.count();

if successful_import > 0 {
info!(
log,
"Imported keystores via standard HTTP API";
"count" => successful_import,
);
}

Ok(ImportKeystoresResponse { data: statuses })
}

Expand Down Expand Up @@ -238,7 +245,23 @@ pub fn delete<T: SlotClock + 'static, E: EthSpec>(
task_executor: TaskExecutor,
log: Logger,
) -> Result<DeleteKeystoresResponse, Rejection> {
let export_response = export(request, validator_store, task_executor, log)?;
let export_response = export(request, validator_store, task_executor, log.clone())?;

// Check the status is Deleted to confirm deletion is successful, then only display the log
let successful_deletion = export_response
.data
.iter()
.filter(|response| matches!(response.status.status, DeleteKeystoreStatus::Deleted))
.count();

if successful_deletion > 0 {
info!(
log,
"Deleted keystore via standard HTTP API";
"count" => successful_deletion,
);
}

Ok(DeleteKeystoresResponse {
data: export_response
.data
Expand Down
1 change: 1 addition & 0 deletions validator_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tree_hash = { workspace = true }
eth2 = { workspace = true }
hex = { workspace = true }
tokio = { workspace = true }
derivative = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }
Expand Down
9 changes: 0 additions & 9 deletions validator_manager/src/create_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ pub fn cli_app() -> Command {
Another, optional JSON file is created which contains a list of validator \
deposits in the same format as the \"ethereum/staking-deposit-cli\" tool.",
)
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER),
)
.arg(
Arg::new(OUTPUT_PATH_FLAG)
.long(OUTPUT_PATH_FLAG)
Expand Down
Loading
Loading