From f35a33716be6b90e39d5f7bde6b00ec8fbfa7acd Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 21 Jan 2022 06:07:20 +0000 Subject: [PATCH] Quote validator indices when posting duties (#2943) ## Proposed Changes This PR establishes compatibility between Lighthouse's VC and Nimbus's BN. Lighthouse was previously `POST`ing unquoted lists of validator indices to the attester and sync duties endpoints which were (correctly) not accepted by Nimbus. These lists had slipped through the cracks because they didn't have an explicit wrapper type to add `serde` annotations to. I've added the `ValidatorIndexDataRef` newtype in order to implement the modified serialisation behaviour. ## Testing Combined with https://github.com/sigp/lighthouse/pull/2940, I've confirmed that this PR allows my Lighthouse VC on Prater to validate with the public Nimbus BN listed here: https://github.com/status-im/nimbus-eth2#quickly-test-your-tooling-against-nimbus. I haven't had a block proposal yet, but attestations and sync committee messages are working. ## Additional Info This may also provide compatibility with Prysm BNs but I haven't had a chance to test that yet. --- common/eth2/src/lib.rs | 16 ++++++++++++---- common/eth2/src/types.rs | 7 +++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/common/eth2/src/lib.rs b/common/eth2/src/lib.rs index bdad672866..153667d7e9 100644 --- a/common/eth2/src/lib.rs +++ b/common/eth2/src/lib.rs @@ -1256,8 +1256,12 @@ impl BeaconNodeHttpClient { .push("attester") .push(&epoch.to_string()); - self.post_with_timeout_and_response(path, &indices, self.timeouts.attester_duties) - .await + self.post_with_timeout_and_response( + path, + &ValidatorIndexDataRef(indices), + self.timeouts.attester_duties, + ) + .await } /// `POST validator/aggregate_and_proofs` @@ -1356,8 +1360,12 @@ impl BeaconNodeHttpClient { .push("sync") .push(&epoch.to_string()); - self.post_with_timeout_and_response(path, &indices, self.timeouts.sync_duties) - .await + self.post_with_timeout_and_response( + path, + &ValidatorIndexDataRef(indices), + self.timeouts.sync_duties, + ) + .await } } diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index 169a8de59e..a761b9ed12 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -591,6 +591,13 @@ pub struct ValidatorBalancesQuery { #[serde(transparent)] pub struct ValidatorIndexData(#[serde(with = "eth2_serde_utils::quoted_u64_vec")] pub Vec); +/// Borrowed variant of `ValidatorIndexData`, for serializing/sending. +#[derive(Clone, Copy, Serialize)] +#[serde(transparent)] +pub struct ValidatorIndexDataRef<'a>( + #[serde(serialize_with = "eth2_serde_utils::quoted_u64_vec::serialize")] pub &'a [u64], +); + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct AttesterData { pub pubkey: PublicKeyBytes,