Fork schedule api (#2525)
## Issue Addressed Resolves #2524 ## Proposed Changes - Return all known forks in the `/config/fork_schedule`, previously returned only the head of the chain's fork. - Deleted the `StateId::head` method because it was only previously used in this endpoint. Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
parent
bc0599246f
commit
5b8436e33f
@ -40,7 +40,7 @@ use tokio::sync::mpsc::UnboundedSender;
|
|||||||
use tokio_stream::{wrappers::BroadcastStream, StreamExt};
|
use tokio_stream::{wrappers::BroadcastStream, StreamExt};
|
||||||
use types::{
|
use types::{
|
||||||
Attestation, AttesterSlashing, BeaconStateError, CommitteeCache, ConfigAndPreset, Epoch,
|
Attestation, AttesterSlashing, BeaconStateError, CommitteeCache, ConfigAndPreset, Epoch,
|
||||||
EthSpec, ProposerSlashing, RelativeEpoch, SignedAggregateAndProof, SignedBeaconBlock,
|
EthSpec, ForkName, ProposerSlashing, RelativeEpoch, SignedAggregateAndProof, SignedBeaconBlock,
|
||||||
SignedContributionAndProof, SignedVoluntaryExit, Slot, SyncCommitteeMessage,
|
SignedContributionAndProof, SignedVoluntaryExit, Slot, SyncCommitteeMessage,
|
||||||
SyncContributionData,
|
SyncContributionData,
|
||||||
};
|
};
|
||||||
@ -1366,7 +1366,7 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* config/fork_schedule
|
* config
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let config_path = eth1_v1.and(warp::path("config"));
|
let config_path = eth1_v1.and(warp::path("config"));
|
||||||
@ -1378,9 +1378,11 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
.and(chain_filter.clone())
|
.and(chain_filter.clone())
|
||||||
.and_then(|chain: Arc<BeaconChain<T>>| {
|
.and_then(|chain: Arc<BeaconChain<T>>| {
|
||||||
blocking_json_task(move || {
|
blocking_json_task(move || {
|
||||||
StateId::head()
|
let forks = ForkName::list_all()
|
||||||
.fork(&chain)
|
.into_iter()
|
||||||
.map(|fork| api_types::GenericResponse::from(vec![fork]))
|
.filter_map(|fork_name| chain.spec.fork_for_name(fork_name))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
Ok(api_types::GenericResponse::from(forks))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -8,10 +8,6 @@ use types::{BeaconState, EthSpec, Fork, Hash256, Slot};
|
|||||||
pub struct StateId(CoreStateId);
|
pub struct StateId(CoreStateId);
|
||||||
|
|
||||||
impl StateId {
|
impl StateId {
|
||||||
pub fn head() -> Self {
|
|
||||||
Self(CoreStateId::Head)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn slot(slot: Slot) -> Self {
|
pub fn slot(slot: Slot) -> Self {
|
||||||
Self(CoreStateId::Slot(slot))
|
Self(CoreStateId::Slot(slot))
|
||||||
}
|
}
|
||||||
|
@ -1190,7 +1190,10 @@ impl ApiTester {
|
|||||||
pub async fn test_get_config_fork_schedule(self) -> Self {
|
pub async fn test_get_config_fork_schedule(self) -> Self {
|
||||||
let result = self.client.get_config_fork_schedule().await.unwrap().data;
|
let result = self.client.get_config_fork_schedule().await.unwrap().data;
|
||||||
|
|
||||||
let expected = vec![self.chain.head_info().unwrap().fork];
|
let expected: Vec<Fork> = ForkName::list_all()
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|fork| self.chain.spec.fork_for_name(fork))
|
||||||
|
.collect();
|
||||||
|
|
||||||
assert_eq!(result, expected);
|
assert_eq!(result, expected);
|
||||||
|
|
||||||
|
@ -237,6 +237,19 @@ impl ChainSpec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a full `Fork` struct for a given `ForkName` or `None` if the fork does not yet have
|
||||||
|
/// an activation epoch.
|
||||||
|
pub fn fork_for_name(&self, fork_name: ForkName) -> Option<Fork> {
|
||||||
|
let previous_fork_name = fork_name.previous_fork().unwrap_or(ForkName::Base);
|
||||||
|
let epoch = self.fork_epoch(fork_name)?;
|
||||||
|
|
||||||
|
Some(Fork {
|
||||||
|
previous_version: self.fork_version_for_name(previous_fork_name),
|
||||||
|
current_version: self.fork_version_for_name(fork_name),
|
||||||
|
epoch,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the domain number, unmodified by the fork.
|
/// Get the domain number, unmodified by the fork.
|
||||||
///
|
///
|
||||||
/// Spec v0.12.1
|
/// Spec v0.12.1
|
||||||
|
Loading…
Reference in New Issue
Block a user