Skip to content

Commit

Permalink
Update to match latest upstream spec
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Nov 5, 2021
1 parent d0259b4 commit 44e2df8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
6 changes: 0 additions & 6 deletions common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ impl fmt::Display for Error {
}
}

impl From<reqwest::Error> for Error {
fn from(error: reqwest::Error) -> Self {
Error::Reqwest(error)
}
}

/// A struct to define a variety of different timeouts for different validator tasks to ensure
/// proper fallback behaviour.
#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion common/eth2/src/lighthouse_vc/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl ValidatorClientHttpClient {
.ok()
.and_then(|bytes| {
let sig = Signature::parse_der(&bytes).ok()?;
Some(libsecp256k1::verify(&message, &sig, &server_pubkey))
Some(libsecp256k1::verify(&message, &sig, server_pubkey))
})
.filter(|is_valid| *is_valid)
.ok_or(Error::InvalidSignatureHeader)?;
Expand Down
10 changes: 6 additions & 4 deletions common/eth2/src/lighthouse_vc/std_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ pub struct AuthResponse {

#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct ListKeystoresResponse {
pub keystores: Vec<SingleKeystoreResponse>,
pub data: Vec<SingleKeystoreResponse>,
}

#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct SingleKeystoreResponse {
pub validating_pubkey: PublicKeyBytes,
pub derivation_path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub readonly: Option<bool>,
}

#[derive(Deserialize, Serialize)]
pub struct ImportKeystoresRequest {
pub keystores: Vec<Keystore>,
pub keystores_password: ZeroizeString,
pub passwords: Vec<ZeroizeString>,
pub slashing_protection: Option<Interchange>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ImportKeystoresResponse {
pub statuses: Vec<Status<ImportKeystoreStatus>>,
pub data: Vec<Status<ImportKeystoreStatus>>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down Expand Up @@ -70,7 +72,7 @@ pub struct DeleteKeystoresRequest {

#[derive(Debug, Deserialize, Serialize)]
pub struct DeleteKeystoresResponse {
pub statuses: Vec<Status<DeleteKeystoreStatus>>,
pub data: Vec<Status<DeleteKeystoreStatus>>,
pub slashing_protection: Interchange,
}

Expand Down
16 changes: 11 additions & 5 deletions validator_client/src/http_api/keystores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ pub fn list<T: SlotClock + 'static, E: EthSpec>(
SingleKeystoreResponse {
validating_pubkey,
derivation_path,
readonly: None,
}
})
.collect::<Vec<_>>();

ListKeystoresResponse { keystores }
ListKeystoresResponse { data: keystores }
}

pub fn import<T: SlotClock + 'static, E: EthSpec>(
Expand Down Expand Up @@ -97,13 +98,18 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
// Import each keystore. Some keystores may fail to be imported, so we record a status for each.
let mut statuses = Vec::with_capacity(request.keystores.len());

for keystore in request.keystores {
// FIXME(sproul): check and test different length keystores vs passwords
for (keystore, password) in request
.keystores
.into_iter()
.zip(request.passwords.into_iter())
{
let pubkey_str = keystore.pubkey().to_string();

let status = if let Some(runtime) = runtime.upgrade() {
match import_single_keystore(
keystore,
request.keystores_password.clone(),
password,
validator_dir.clone(),
&validator_store,
runtime,
Expand All @@ -128,7 +134,7 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
statuses.push(status);
}

Ok(ImportKeystoresResponse { statuses })
Ok(ImportKeystoresResponse { data: statuses })
}

fn import_single_keystore<T: SlotClock + 'static, E: EthSpec>(
Expand Down Expand Up @@ -210,7 +216,7 @@ pub fn delete<T: SlotClock + 'static, E: EthSpec>(
})?;

Ok(DeleteKeystoresResponse {
statuses,
data: statuses,
slashing_protection,
})
}
Expand Down
22 changes: 11 additions & 11 deletions validator_client/src/http_api/tests/keystores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn check_get_response<'a>(
response: &ListKeystoresResponse,
expected_keystores: impl IntoIterator<Item = &'a Keystore>,
) {
for (ks1, ks2) in response.keystores.iter().zip_eq(expected_keystores) {
for (ks1, ks2) in response.data.iter().zip_eq(expected_keystores) {
assert_eq!(ks1.validating_pubkey, keystore_pubkey(ks2));
assert_eq!(ks1.derivation_path, ks2.path());
}
Expand All @@ -58,7 +58,7 @@ fn check_import_response<'a>(
response: &ImportKeystoresResponse,
expected_statuses: impl IntoIterator<Item = ImportKeystoreStatus>,
) {
for (status, expected_status) in response.statuses.iter().zip_eq(expected_statuses) {
for (status, expected_status) in response.data.iter().zip_eq(expected_statuses) {
assert_eq!(
status.status, expected_status,
"message: {:?}",
Expand All @@ -71,7 +71,7 @@ fn check_delete_response<'a>(
response: &DeleteKeystoresResponse,
expected_statuses: impl IntoIterator<Item = DeleteKeystoreStatus>,
) {
for (status, expected_status) in response.statuses.iter().zip_eq(expected_statuses) {
for (status, expected_status) in response.data.iter().zip_eq(expected_statuses) {
assert_eq!(
status.status, expected_status,
"message: {:?}",
Expand Down Expand Up @@ -99,7 +99,7 @@ fn get_auth_no_token() {
fn get_empty_keystores() {
run_test(|tester| async move {
let res = tester.client.get_keystores().await.unwrap();
assert_eq!(res, ListKeystoresResponse { keystores: vec![] });
assert_eq!(res, ListKeystoresResponse { data: vec![] });
})
}

Expand All @@ -115,7 +115,7 @@ fn import_new_keystores() {
.client
.post_keystores(&ImportKeystoresRequest {
keystores: keystores.clone(),
keystores_password: password,
passwords: vec![password.clone(); keystores.len()],
slashing_protection: None,
})
.await
Expand All @@ -140,7 +140,7 @@ fn import_only_duplicate_keystores() {

let req = ImportKeystoresRequest {
keystores: keystores.clone(),
keystores_password: password,
passwords: vec![password.clone(); keystores.len()],
slashing_protection: None,
};

Expand Down Expand Up @@ -182,13 +182,13 @@ fn import_some_duplicate_keystores() {

let req1 = ImportKeystoresRequest {
keystores: keystores1.clone(),
keystores_password: password.clone(),
passwords: vec![password.clone(); keystores1.len()],
slashing_protection: None,
};

let req2 = ImportKeystoresRequest {
keystores: keystores_all.clone(),
keystores_password: password,
passwords: vec![password.clone(); keystores_all.len()],
slashing_protection: None,
};

Expand Down Expand Up @@ -291,7 +291,7 @@ fn delete_concurrent_with_signing() {
.client
.post_keystores(&ImportKeystoresRequest {
keystores: keystores.clone(),
keystores_password: password,
passwords: vec![password.clone(); keystores.len()],
slashing_protection: None,
})
.await
Expand Down Expand Up @@ -353,7 +353,7 @@ fn delete_concurrent_with_signing() {
.await
.unwrap();

for status in delete_res.statuses.iter() {
for status in delete_res.data.iter() {
assert_ne!(status.status, DeleteKeystoreStatus::Error);
}

Expand Down Expand Up @@ -402,7 +402,7 @@ fn delete_then_reimport() {
// 1. Import all keystores.
let import_req = ImportKeystoresRequest {
keystores: keystores.clone(),
keystores_password: password,
passwords: vec![password.clone(); keystores.len()],
slashing_protection: None,
};
let import_res = tester.client.post_keystores(&import_req).await.unwrap();
Expand Down

0 comments on commit 44e2df8

Please sign in to comment.