Skip to content

Commit

Permalink
Revert common/eth2 to unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Jun 28, 2022
1 parent 61ff3b5 commit 4fa5be6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 86 deletions.
76 changes: 25 additions & 51 deletions common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_states_root(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticResponse<RootData>>, Error> {
) -> Result<Option<GenericResponse<RootData>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand All @@ -349,7 +349,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_states_fork(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticResponse<Fork>>, Error> {
) -> Result<Option<GenericResponse<Fork>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand All @@ -368,7 +368,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_states_finality_checkpoints(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticResponse<FinalityCheckpointsData>>, Error> {
) -> Result<Option<GenericResponse<FinalityCheckpointsData>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand All @@ -388,7 +388,7 @@ impl BeaconNodeHttpClient {
&self,
state_id: StateId,
ids: Option<&[ValidatorId]>,
) -> Result<Option<ExecutionOptimisticResponse<Vec<ValidatorBalanceData>>>, Error> {
) -> Result<Option<GenericResponse<Vec<ValidatorBalanceData>>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand Down Expand Up @@ -418,7 +418,7 @@ impl BeaconNodeHttpClient {
state_id: StateId,
ids: Option<&[ValidatorId]>,
statuses: Option<&[ValidatorStatus]>,
) -> Result<Option<ExecutionOptimisticResponse<Vec<ValidatorData>>>, Error> {
) -> Result<Option<GenericResponse<Vec<ValidatorData>>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand Down Expand Up @@ -458,7 +458,7 @@ impl BeaconNodeHttpClient {
slot: Option<Slot>,
index: Option<u64>,
epoch: Option<Epoch>,
) -> Result<Option<ExecutionOptimisticResponse<Vec<CommitteeData>>>, Error> {
) -> Result<Option<GenericResponse<Vec<CommitteeData>>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand Down Expand Up @@ -491,7 +491,7 @@ impl BeaconNodeHttpClient {
&self,
state_id: StateId,
epoch: Option<Epoch>,
) -> Result<ExecutionOptimisticResponse<SyncCommitteeByValidatorIndices>, Error> {
) -> Result<GenericResponse<SyncCommitteeByValidatorIndices>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand All @@ -516,7 +516,7 @@ impl BeaconNodeHttpClient {
&self,
state_id: StateId,
validator_id: &ValidatorId,
) -> Result<Option<ExecutionOptimisticResponse<ValidatorData>>, Error> {
) -> Result<Option<GenericResponse<ValidatorData>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand All @@ -537,7 +537,7 @@ impl BeaconNodeHttpClient {
&self,
slot: Option<Slot>,
parent_root: Option<Hash256>,
) -> Result<Option<ExecutionOptimisticResponse<Vec<BlockHeaderData>>>, Error> {
) -> Result<Option<GenericResponse<Vec<BlockHeaderData>>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand All @@ -564,7 +564,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_headers_block_id(
&self,
block_id: BlockId,
) -> Result<Option<ExecutionOptimisticResponse<BlockHeaderData>>, Error> {
) -> Result<Option<GenericResponse<BlockHeaderData>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand Down Expand Up @@ -633,7 +633,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_blocks<T: EthSpec>(
&self,
block_id: BlockId,
) -> Result<Option<ExecutionOptimisticForkVersionedResponse<SignedBeaconBlock<T>>>, Error> {
) -> Result<Option<ForkVersionedResponse<SignedBeaconBlock<T>>>, Error> {
let path = self.get_beacon_blocks_path(block_id)?;
let response = match self.get_response(path, |b| b).await.optional()? {
Some(res) => res,
Expand All @@ -642,31 +642,20 @@ impl BeaconNodeHttpClient {

// If present, use the fork provided in the headers to decode the block. Gracefully handle
// missing and malformed fork names by falling back to regular deserialisation.
let (block, version, execution_optimistic) = match response.fork_name_from_header() {
let (block, version) = match response.fork_name_from_header() {
Ok(Some(fork_name)) => {
let (data, (version, execution_optimistic)) =
map_fork_name_with!(fork_name, SignedBeaconBlock, {
let ExecutionOptimisticForkVersionedResponse {
version,
execution_optimistic,
data,
} = response.json().await?;
(data, (version, execution_optimistic))
});
(data, version, execution_optimistic)
map_fork_name_with!(fork_name, SignedBeaconBlock, {
let ForkVersionedResponse { version, data } = response.json().await?;
(data, version)
})
}
Ok(None) | Err(_) => {
let ExecutionOptimisticForkVersionedResponse {
version,
execution_optimistic,
data,
} = response.json().await?;
(data, version, execution_optimistic)
let ForkVersionedResponse { version, data } = response.json().await?;
(data, version)
}
};
Ok(Some(ExecutionOptimisticForkVersionedResponse {
Ok(Some(ForkVersionedResponse {
version,
execution_optimistic,
data: block,
}))
}
Expand Down Expand Up @@ -711,7 +700,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_blocks_root(
&self,
block_id: BlockId,
) -> Result<Option<ExecutionOptimisticResponse<RootData>>, Error> {
) -> Result<Option<GenericResponse<RootData>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand All @@ -730,7 +719,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_blocks_attestations<T: EthSpec>(
&self,
block_id: BlockId,
) -> Result<Option<ExecutionOptimisticResponse<Vec<Attestation<T>>>>, Error> {
) -> Result<Option<GenericResponse<Vec<Attestation<T>>>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand Down Expand Up @@ -1110,7 +1099,7 @@ impl BeaconNodeHttpClient {
pub async fn get_debug_beacon_states<T: EthSpec>(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticForkVersionedResponse<BeaconState<T>>>, Error> {
) -> Result<Option<ForkVersionedResponse<BeaconState<T>>>, Error> {
let path = self.get_debug_beacon_states_path(state_id)?;
self.get_opt(path).await
}
Expand All @@ -1119,7 +1108,7 @@ impl BeaconNodeHttpClient {
pub async fn get_debug_beacon_states_v1<T: EthSpec>(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticForkVersionedResponse<BeaconState<T>>>, Error> {
) -> Result<Option<ForkVersionedResponse<BeaconState<T>>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand Down Expand Up @@ -1147,24 +1136,9 @@ impl BeaconNodeHttpClient {
.transpose()
}

/// `GET v2/debug/beacon/heads`
/// `GET debug/beacon/heads`
pub async fn get_debug_beacon_heads(
&self,
) -> Result<GenericResponse<Vec<ChainHeadData>>, Error> {
let mut path = self.eth_path(V2)?;

path.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("debug")
.push("beacon")
.push("heads");

self.get(path).await
}

/// `GET v1/debug/beacon/heads` (LEGACY)
pub async fn get_debug_beacon_heads_v1(
&self,
) -> Result<GenericResponse<Vec<ChainHeadData>>, Error> {
let mut path = self.eth_path(V1)?;

Expand Down Expand Up @@ -1496,7 +1470,7 @@ impl BeaconNodeHttpClient {
&self,
epoch: Epoch,
indices: &[u64],
) -> Result<ExecutionOptimisticResponse<Vec<SyncDuty>>, Error> {
) -> Result<GenericResponse<Vec<SyncDuty>>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
Expand Down
35 changes: 0 additions & 35 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,6 @@ impl fmt::Display for StateId {
#[serde(bound = "T: Serialize + serde::de::DeserializeOwned")]
pub struct DutiesResponse<T: Serialize + serde::de::DeserializeOwned> {
pub dependent_root: Hash256,
pub execution_optimistic: bool,
pub data: T,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(bound = "T: Serialize + serde::de::DeserializeOwned")]
pub struct ExecutionOptimisticResponse<T: Serialize + serde::de::DeserializeOwned> {
pub execution_optimistic: bool,
pub data: T,
}

Expand All @@ -212,18 +204,6 @@ impl<T: Serialize + serde::de::DeserializeOwned> From<T> for GenericResponse<T>
}
}

impl<T: Serialize + serde::de::DeserializeOwned> GenericResponse<T> {
pub fn add_execution_optimistic(
self,
execution_optimistic: bool,
) -> ExecutionOptimisticResponse<T> {
ExecutionOptimisticResponse {
execution_optimistic,
data: self.data,
}
}
}

#[derive(Debug, PartialEq, Clone, Serialize)]
#[serde(bound = "T: Serialize")]
pub struct GenericResponseRef<'a, T: Serialize> {
Expand All @@ -236,14 +216,6 @@ impl<'a, T: Serialize> From<&'a T> for GenericResponseRef<'a, T> {
}
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct ExecutionOptimisticForkVersionedResponse<T> {
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<ForkName>,
pub execution_optimistic: bool,
pub data: T,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct ForkVersionedResponse<T> {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -523,8 +495,6 @@ pub struct DepositContractData {
pub struct ChainHeadData {
pub slot: Slot,
pub root: Hash256,
#[serde(skip_serializing_if = "Option::is_none")]
pub execution_optimistic: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -824,15 +794,13 @@ pub struct PeerCount {
pub struct SseBlock {
pub slot: Slot,
pub block: Hash256,
pub execution_optimistic: bool,
}

#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
pub struct SseFinalizedCheckpoint {
pub block: Hash256,
pub state: Hash256,
pub epoch: Epoch,
pub execution_optimistic: bool,
}

#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
Expand All @@ -843,7 +811,6 @@ pub struct SseHead {
pub current_duty_dependent_root: Hash256,
pub previous_duty_dependent_root: Hash256,
pub epoch_transition: bool,
pub execution_optimistic: bool,
}

#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
Expand All @@ -856,7 +823,6 @@ pub struct SseChainReorg {
pub new_head_block: Hash256,
pub new_head_state: Hash256,
pub epoch: Epoch,
pub execution_optimistic: bool,
}

#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
Expand All @@ -871,7 +837,6 @@ pub struct SseLateHead {
pub observed_delay: Option<Duration>,
pub imported_delay: Option<Duration>,
pub set_as_head_delay: Option<Duration>,
pub execution_optimistic: bool,
}

#[derive(PartialEq, Debug, Serialize, Clone)]
Expand Down

0 comments on commit 4fa5be6

Please sign in to comment.