Skip to content

Commit

Permalink
Fix errors after master rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Sep 5, 2020
1 parent 69b3219 commit cf5da09
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
7 changes: 5 additions & 2 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,17 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
///
/// See `Self::head` for more information.
pub fn head_beacon_block(&self) -> Result<SignedBeaconBlock<T::EthSpec>, Error> {
self.with_head(|s| s.beacon_block.clone())
self.with_head(|s| Ok(s.beacon_block.clone()))
}

/// Returns the beacon state at the head of the canonical chain.
///
/// See `Self::head` for more information.
pub fn head_beacon_state(&self) -> Result<BeaconState<T::EthSpec>, Error> {
self.with_head(|s| s.beacon_state.clone())
self.with_head(|s| {
Ok(s.beacon_state
.clone_with(CloneConfig::committee_caches_only()))
})
}

/// Returns info representing the head block and state.
Expand Down
5 changes: 4 additions & 1 deletion beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,10 @@ where
for (unaggregated_attestations, maybe_signed_aggregate) in attestations.into_iter() {
for (attestation, subnet_id) in unaggregated_attestations {
self.chain
.verify_unaggregated_attestation_for_gossip(attestation.clone(), subnet_id)
.verify_unaggregated_attestation_for_gossip(
attestation.clone(),
Some(subnet_id),
)
.unwrap()
.add_to_pool(&self.chain)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/state_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl StateId {
match &self.0 {
CoreStateId::Head => {
return chain
.map_head(|snapshot| func(&snapshot.beacon_state))
.with_head(|snapshot| Ok(func(&snapshot.beacon_state)))
.map_err(crate::reject::beacon_chain_error)?
}
_ => func(&self.state(chain)?),
Expand Down
20 changes: 12 additions & 8 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use beacon_chain::{
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, HarnessType},
test_utils::{
AttestationStrategy, BeaconChainHarness, BlockStrategy,
BlockingMigratorEphemeralHarnessType,
},
BeaconChain,
};
use environment::null_logger;
Expand All @@ -8,7 +11,6 @@ use http_api::{Config, Context};
use network::NetworkMessage;
use std::net::Ipv4Addr;
use std::sync::Arc;
use store::config::StoreConfig;
use tokio::sync::mpsc;
use tokio::sync::oneshot;
use types::{
Expand All @@ -35,7 +37,7 @@ const SKIPPED_SLOTS: &[u64] = &[
];

struct ApiTester {
chain: Arc<BeaconChain<HarnessType<E>>>,
chain: Arc<BeaconChain<BlockingMigratorEphemeralHarnessType<E>>>,
client: BeaconNodeClient,
next_block: SignedBeaconBlock<E>,
attestations: Vec<Attestation<E>>,
Expand All @@ -45,10 +47,9 @@ struct ApiTester {

impl ApiTester {
pub fn new() -> Self {
let harness = BeaconChainHarness::new(
let mut harness = BeaconChainHarness::new(
MainnetEthSpec,
generate_deterministic_keypairs(VALIDATOR_COUNT),
StoreConfig::default(),
);

harness.advance_slot();
Expand All @@ -67,7 +68,6 @@ impl ApiTester {
harness.advance_slot();
}

let (next_block, _next_state) = harness.get_block();
let head = harness.chain.head().unwrap();

assert_eq!(
Expand All @@ -76,6 +76,9 @@ impl ApiTester {
"precondition: current slot is one after head"
);

let (next_block, _next_state) =
harness.make_block(head.beacon_state.clone(), harness.chain.slot().unwrap());

let attestations = harness
.get_unaggregated_attestations(
&AttestationStrategy::AllValidators,
Expand Down Expand Up @@ -434,7 +437,7 @@ impl ApiTester {

pub async fn test_beacon_states_committees(self) -> Self {
for state_id in self.interesting_state_ids() {
let state_opt = self.get_state(state_id);
let mut state_opt = self.get_state(state_id);

let epoch = state_opt
.as_ref()
Expand All @@ -452,7 +455,8 @@ impl ApiTester {
continue;
}

let state = state_opt.as_ref().expect("result should be none");
let state = state_opt.as_mut().expect("result should be none");
state.build_all_committee_caches(&self.chain.spec).unwrap();
let committees = state
.get_beacon_committees_at_epoch(
RelativeEpoch::from_epoch(state.current_epoch(), epoch).unwrap(),
Expand Down

0 comments on commit cf5da09

Please sign in to comment.