mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 10:11:44 +00:00
Update pool/attestations and committees endpoints (#1899)
## Issue Addressed
Catching up on a few eth2 spec updates:
## Proposed Changes
- adding query params to the `GET pool/attestations` endpoint
- allowing the `POST pool/attestations` endpoint to accept an array of attestations
- batching attestation submission
- moving `epoch` from a path param to a query param in the `committees` endpoint
## Additional Info
Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -301,15 +301,15 @@ impl BeaconNodeHttpClient {
|
||||
self.get_opt(path).await
|
||||
}
|
||||
|
||||
/// `GET beacon/states/{state_id}/committees?slot,index`
|
||||
/// `GET beacon/states/{state_id}/committees?slot,index,epoch`
|
||||
///
|
||||
/// Returns `Ok(None)` on a 404 error.
|
||||
pub async fn get_beacon_states_committees(
|
||||
&self,
|
||||
state_id: StateId,
|
||||
epoch: Epoch,
|
||||
slot: Option<Slot>,
|
||||
index: Option<u64>,
|
||||
epoch: Option<Epoch>,
|
||||
) -> Result<Option<GenericResponse<Vec<CommitteeData>>>, Error> {
|
||||
let mut path = self.eth_path()?;
|
||||
|
||||
@@ -318,8 +318,7 @@ impl BeaconNodeHttpClient {
|
||||
.push("beacon")
|
||||
.push("states")
|
||||
.push(&state_id.to_string())
|
||||
.push("committees")
|
||||
.push(&epoch.to_string());
|
||||
.push("committees");
|
||||
|
||||
if let Some(slot) = slot {
|
||||
path.query_pairs_mut()
|
||||
@@ -331,6 +330,11 @@ impl BeaconNodeHttpClient {
|
||||
.append_pair("index", &index.to_string());
|
||||
}
|
||||
|
||||
if let Some(epoch) = epoch {
|
||||
path.query_pairs_mut()
|
||||
.append_pair("epoch", &epoch.to_string());
|
||||
}
|
||||
|
||||
self.get_opt(path).await
|
||||
}
|
||||
|
||||
@@ -479,7 +483,7 @@ impl BeaconNodeHttpClient {
|
||||
/// `POST beacon/pool/attestations`
|
||||
pub async fn post_beacon_pool_attestations<T: EthSpec>(
|
||||
&self,
|
||||
attestation: &Attestation<T>,
|
||||
attestations: &[Attestation<T>],
|
||||
) -> Result<(), Error> {
|
||||
let mut path = self.eth_path()?;
|
||||
|
||||
@@ -489,14 +493,23 @@ impl BeaconNodeHttpClient {
|
||||
.push("pool")
|
||||
.push("attestations");
|
||||
|
||||
self.post(path, attestation).await?;
|
||||
let response = self
|
||||
.client
|
||||
.post(path)
|
||||
.json(attestations)
|
||||
.send()
|
||||
.await
|
||||
.map_err(Error::Reqwest)?;
|
||||
ok_or_indexed_error(response).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `GET beacon/pool/attestations`
|
||||
/// `GET beacon/pool/attestations?slot,committee_index`
|
||||
pub async fn get_beacon_pool_attestations<T: EthSpec>(
|
||||
&self,
|
||||
slot: Option<Slot>,
|
||||
committee_index: Option<u64>,
|
||||
) -> Result<GenericResponse<Vec<Attestation<T>>>, Error> {
|
||||
let mut path = self.eth_path()?;
|
||||
|
||||
@@ -506,6 +519,16 @@ impl BeaconNodeHttpClient {
|
||||
.push("pool")
|
||||
.push("attestations");
|
||||
|
||||
if let Some(slot) = slot {
|
||||
path.query_pairs_mut()
|
||||
.append_pair("slot", &slot.to_string());
|
||||
}
|
||||
|
||||
if let Some(index) = committee_index {
|
||||
path.query_pairs_mut()
|
||||
.append_pair("committee_index", &index.to_string());
|
||||
}
|
||||
|
||||
self.get(path).await
|
||||
}
|
||||
|
||||
|
||||
@@ -349,6 +349,13 @@ impl fmt::Display for ValidatorStatus {
|
||||
pub struct CommitteesQuery {
|
||||
pub slot: Option<Slot>,
|
||||
pub index: Option<u64>,
|
||||
pub epoch: Option<Epoch>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct AttestationPoolQuery {
|
||||
pub slot: Option<Slot>,
|
||||
pub committee_index: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user