spec v0.6.1: update per-epoch processing

This commit is contained in:
Michael Sproul
2019-05-21 11:47:52 +10:00
parent d3d2900a6a
commit 56424d94c6
4 changed files with 13 additions and 35 deletions

View File

@@ -248,7 +248,7 @@ impl ValidatorStatuses {
status.is_previous_epoch_target_attester = true;
}
if has_common_beacon_block_root(a, state, spec)? {
if has_common_beacon_block_root(a, state)? {
status.is_previous_epoch_head_attester = true;
}
}
@@ -298,8 +298,7 @@ impl ValidatorStatuses {
) -> Result<(), BeaconStateError> {
// Loop through each slot in the previous epoch.
for slot in state.previous_epoch().slot_iter(spec.slots_per_epoch) {
let crosslink_committees_at_slot =
state.get_crosslink_committees_at_slot(slot, spec)?;
let crosslink_committees_at_slot = state.get_crosslink_committees_at_slot(slot)?;
// Loop through each committee in the slot.
for c in crosslink_committees_at_slot {
@@ -352,7 +351,6 @@ fn target_matches_epoch_start_block<T: EthSpec>(
fn has_common_beacon_block_root<T: EthSpec>(
a: &PendingAttestation,
state: &BeaconState<T>,
spec: &ChainSpec,
) -> Result<bool, BeaconStateError> {
let attestation_slot = state.get_attestation_slot(&a.data)?;
let state_block_root = *state.get_block_root(attestation_slot)?;

View File

@@ -47,15 +47,16 @@ pub fn winning_root<T: EthSpec>(
.filter(|a| a.data.shard == shard)
.collect();
let shard_crosslinks = shard_attestations.iter().map(|att| {
(
let mut shard_crosslinks = Vec::with_capacity(shard_attestations.len());
for att in shard_attestations {
shard_crosslinks.push((
att,
state.get_crosslink_from_attestation_data(&att.data, spec),
)
});
state.get_crosslink_from_attestation_data(&att.data, spec)?,
));
}
let current_shard_crosslink_root = state.current_crosslinks[shard as usize].tree_hash_root();
let candidate_crosslinks = shard_crosslinks.filter(|(_, c)| {
let current_shard_crosslink_root = state.get_current_crosslink(shard)?.tree_hash_root();
let candidate_crosslinks = shard_crosslinks.into_iter().filter(|(_, c)| {
c.previous_crosslink_root.as_bytes() == &current_shard_crosslink_root[..]
|| c.tree_hash_root() == current_shard_crosslink_root
});
@@ -63,7 +64,7 @@ pub fn winning_root<T: EthSpec>(
// Build a map from candidate crosslink to attestations that support that crosslink.
let mut candidate_crosslink_map: HashMap<Crosslink, Vec<&PendingAttestation>> = HashMap::new();
for (&attestation, crosslink) in candidate_crosslinks {
for (attestation, crosslink) in candidate_crosslinks {
let supporting_attestations = candidate_crosslink_map
.entry(crosslink)
.or_insert_with(Vec::new);