Fix error in /consensus/individual_votes (#859)
* Add patch and commented-out tests * Delete commented-out tests
This commit is contained in:
parent
5a6e90428b
commit
5c397c49d8
@ -156,12 +156,16 @@ pub fn post_individual_votes<T: BeaconChainTypes>(
|
|||||||
// This is the last slot of the given epoch (one prior to the first slot of the next epoch).
|
// This is the last slot of the given epoch (one prior to the first slot of the next epoch).
|
||||||
let target_slot = (epoch + 1).start_slot(T::EthSpec::slots_per_epoch()) - 1;
|
let target_slot = (epoch + 1).start_slot(T::EthSpec::slots_per_epoch()) - 1;
|
||||||
|
|
||||||
let (_root, state) = state_at_slot(&beacon_chain, target_slot)?;
|
let (_root, mut state) = state_at_slot(&beacon_chain, target_slot)?;
|
||||||
let spec = &beacon_chain.spec;
|
let spec = &beacon_chain.spec;
|
||||||
|
|
||||||
let mut validator_statuses = ValidatorStatuses::new(&state, spec)?;
|
let mut validator_statuses = ValidatorStatuses::new(&state, spec)?;
|
||||||
validator_statuses.process_attestations(&state, spec)?;
|
validator_statuses.process_attestations(&state, spec)?;
|
||||||
|
|
||||||
|
state.update_pubkey_cache().map_err(|e| {
|
||||||
|
ApiError::ServerError(format!("Unable to build pubkey cache: {:?}", e))
|
||||||
|
})?;
|
||||||
|
|
||||||
body.pubkeys
|
body.pubkeys
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|pubkey| {
|
.map(|pubkey| {
|
||||||
|
@ -45,6 +45,7 @@ pub use beacon::{
|
|||||||
ValidatorRequest, ValidatorResponse,
|
ValidatorRequest, ValidatorResponse,
|
||||||
};
|
};
|
||||||
pub use config::Config;
|
pub use config::Config;
|
||||||
|
pub use consensus::{IndividualVote, IndividualVotesRequest, IndividualVotesResponse};
|
||||||
pub use validator::{ValidatorDutiesRequest, ValidatorDuty};
|
pub use validator::{ValidatorDutiesRequest, ValidatorDuty};
|
||||||
|
|
||||||
pub type BoxFut = Box<dyn Future<Item = Response<Body>, Error = ApiError> + Send>;
|
pub type BoxFut = Box<dyn Future<Item = Response<Body>, Error = ApiError> + Send>;
|
||||||
|
@ -15,15 +15,16 @@ use std::marker::PhantomData;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use types::{
|
use types::{
|
||||||
Attestation, AttesterSlashing, BeaconBlock, BeaconState, CommitteeIndex, Epoch, EthSpec, Fork,
|
Attestation, AttesterSlashing, BeaconBlock, BeaconState, CommitteeIndex, Epoch, EthSpec, Fork,
|
||||||
Hash256, ProposerSlashing, PublicKey, Signature, SignedBeaconBlock, Slot,
|
Hash256, ProposerSlashing, PublicKey, PublicKeyBytes, Signature, SignedBeaconBlock, Slot,
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub use operation_pool::PersistedOperationPool;
|
pub use operation_pool::PersistedOperationPool;
|
||||||
pub use proto_array_fork_choice::core::ProtoArray;
|
pub use proto_array_fork_choice::core::ProtoArray;
|
||||||
pub use rest_api::{
|
pub use rest_api::{
|
||||||
CanonicalHeadResponse, Committee, HeadBeaconBlock, ValidatorDutiesRequest, ValidatorDuty,
|
CanonicalHeadResponse, Committee, HeadBeaconBlock, IndividualVotesRequest,
|
||||||
ValidatorRequest, ValidatorResponse,
|
IndividualVotesResponse, ValidatorDutiesRequest, ValidatorDuty, ValidatorRequest,
|
||||||
|
ValidatorResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Setting a long timeout for debug ensures that crypto-heavy operations can still succeed.
|
// Setting a long timeout for debug ensures that crypto-heavy operations can still succeed.
|
||||||
@ -107,6 +108,10 @@ impl<E: EthSpec> HttpClient<E> {
|
|||||||
Advanced(self.clone())
|
Advanced(self.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn consensus(&self) -> Consensus<E> {
|
||||||
|
Consensus(self.clone())
|
||||||
|
}
|
||||||
|
|
||||||
fn url(&self, path: &str) -> Result<Url, Error> {
|
fn url(&self, path: &str) -> Result<Url, Error> {
|
||||||
self.url.join(path).map_err(|e| e.into())
|
self.url.join(path).map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
@ -605,6 +610,47 @@ impl<E: EthSpec> Advanced<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides the functions on the `/consensus` endpoint of the node.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Consensus<E>(HttpClient<E>);
|
||||||
|
|
||||||
|
impl<E: EthSpec> Consensus<E> {
|
||||||
|
fn url(&self, path: &str) -> Result<Url, Error> {
|
||||||
|
self.0
|
||||||
|
.url("consensus/")
|
||||||
|
.and_then(move |url| url.join(path).map_err(Error::from))
|
||||||
|
.map_err(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets a `IndividualVote` for each of the given `pubkeys`.
|
||||||
|
pub fn get_individual_votes(
|
||||||
|
&self,
|
||||||
|
epoch: Epoch,
|
||||||
|
pubkeys: Vec<PublicKeyBytes>,
|
||||||
|
) -> impl Future<Item = IndividualVotesResponse, Error = Error> {
|
||||||
|
let client = self.0.clone();
|
||||||
|
let req_body = IndividualVotesRequest { epoch, pubkeys };
|
||||||
|
|
||||||
|
self.url("individual_votes")
|
||||||
|
.into_future()
|
||||||
|
.and_then(move |url| client.json_post::<_>(url, req_body))
|
||||||
|
.and_then(|response| error_for_status(response).map_err(Error::from))
|
||||||
|
.and_then(|mut success| success.json().map_err(Error::from))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets a `VoteCount` for the given `epoch`.
|
||||||
|
pub fn get_vote_count(
|
||||||
|
&self,
|
||||||
|
epoch: Epoch,
|
||||||
|
) -> impl Future<Item = IndividualVotesResponse, Error = Error> {
|
||||||
|
let client = self.0.clone();
|
||||||
|
let query_params = vec![("epoch".into(), format!("{}", epoch.as_u64()))];
|
||||||
|
self.url("vote_count")
|
||||||
|
.into_future()
|
||||||
|
.and_then(move |url| client.json_get(url, query_params))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(bound = "T: EthSpec")]
|
#[serde(bound = "T: EthSpec")]
|
||||||
pub struct BlockResponse<T: EthSpec> {
|
pub struct BlockResponse<T: EthSpec> {
|
||||||
|
Loading…
Reference in New Issue
Block a user