mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
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 In98bcb947cI'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. In856cd7e37dI'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.
This commit is contained in:
@@ -71,6 +71,7 @@ pub mod sync_duty;
|
||||
pub mod validator;
|
||||
pub mod validator_subscription;
|
||||
pub mod voluntary_exit;
|
||||
pub mod withdrawal_credentials;
|
||||
#[macro_use]
|
||||
pub mod slot_epoch_macros;
|
||||
pub mod config_and_preset;
|
||||
@@ -189,6 +190,7 @@ pub use crate::validator_registration_data::*;
|
||||
pub use crate::validator_subscription::ValidatorSubscription;
|
||||
pub use crate::voluntary_exit::VoluntaryExit;
|
||||
pub use crate::withdrawal::Withdrawal;
|
||||
pub use crate::withdrawal_credentials::WithdrawalCredentials;
|
||||
|
||||
pub type CommitteeIndex = u64;
|
||||
pub type Hash256 = H256;
|
||||
|
||||
57
consensus/types/src/withdrawal_credentials.rs
Normal file
57
consensus/types/src/withdrawal_credentials.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use crate::*;
|
||||
use bls::get_withdrawal_credentials;
|
||||
|
||||
pub struct WithdrawalCredentials(Hash256);
|
||||
|
||||
impl WithdrawalCredentials {
|
||||
pub fn bls(withdrawal_public_key: &PublicKey, spec: &ChainSpec) -> Self {
|
||||
let withdrawal_credentials =
|
||||
get_withdrawal_credentials(withdrawal_public_key, spec.bls_withdrawal_prefix_byte);
|
||||
Self(Hash256::from_slice(&withdrawal_credentials))
|
||||
}
|
||||
|
||||
pub fn eth1(withdrawal_address: Address, spec: &ChainSpec) -> Self {
|
||||
let mut withdrawal_credentials = [0; 32];
|
||||
withdrawal_credentials[0] = spec.eth1_address_withdrawal_prefix_byte;
|
||||
withdrawal_credentials[12..].copy_from_slice(withdrawal_address.as_bytes());
|
||||
Self(Hash256::from_slice(&withdrawal_credentials))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WithdrawalCredentials> for Hash256 {
|
||||
fn from(withdrawal_credentials: WithdrawalCredentials) -> Self {
|
||||
withdrawal_credentials.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::test_utils::generate_deterministic_keypair;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
fn bls_withdrawal_credentials() {
|
||||
let spec = &MainnetEthSpec::default_spec();
|
||||
let keypair = generate_deterministic_keypair(0);
|
||||
let credentials = WithdrawalCredentials::bls(&keypair.pk, spec);
|
||||
let manually_generated_credentials =
|
||||
get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte);
|
||||
let hash: Hash256 = credentials.into();
|
||||
assert_eq!(hash[0], spec.bls_withdrawal_prefix_byte);
|
||||
assert_eq!(hash.as_bytes(), &manually_generated_credentials);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eth1_withdrawal_credentials() {
|
||||
let spec = &MainnetEthSpec::default_spec();
|
||||
let address = Address::from_str("0x25c4a76E7d118705e7Ea2e9b7d8C59930d8aCD3b").unwrap();
|
||||
let credentials = WithdrawalCredentials::eth1(address, spec);
|
||||
let hash: Hash256 = credentials.into();
|
||||
assert_eq!(
|
||||
hash,
|
||||
Hash256::from_str("0x01000000000000000000000025c4a76E7d118705e7Ea2e9b7d8C59930d8aCD3b")
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user