WIP trash changes
This commit is contained in:
parent
ac51d7be3b
commit
13ec3d125e
@ -22,6 +22,7 @@ fnv = "1.0"
|
||||
hashing = { path = "../utils/hashing" }
|
||||
int_to_bytes = { path = "../utils/int_to_bytes" }
|
||||
integer-sqrt = "0.1"
|
||||
itertools = "0.8"
|
||||
log = "0.4"
|
||||
merkle_proof = { path = "../utils/merkle_proof" }
|
||||
ssz = { path = "../utils/ssz" }
|
||||
|
@ -2,11 +2,12 @@
|
||||
mod macros;
|
||||
|
||||
pub mod common;
|
||||
pub mod get_genesis_state;
|
||||
pub mod per_block_processing;
|
||||
//pub mod get_genesis_state;
|
||||
//pub mod per_block_processing;
|
||||
pub mod per_epoch_processing;
|
||||
pub mod per_slot_processing;
|
||||
//pub mod per_slot_processing;
|
||||
|
||||
/*
|
||||
pub use get_genesis_state::get_genesis_state;
|
||||
pub use per_block_processing::{
|
||||
errors::{BlockInvalid, BlockProcessingError},
|
||||
@ -14,3 +15,4 @@ pub use per_block_processing::{
|
||||
};
|
||||
pub use per_epoch_processing::{errors::EpochProcessingError, per_epoch_processing};
|
||||
pub use per_slot_processing::{per_slot_processing, Error as SlotProcessingError};
|
||||
*/
|
||||
|
@ -1,24 +1,24 @@
|
||||
use apply_rewards::apply_rewards;
|
||||
use apply_rewards::process_rewards_and_penalties;
|
||||
use errors::EpochProcessingError as Error;
|
||||
use process_ejections::process_ejections;
|
||||
use process_exit_queue::process_exit_queue;
|
||||
use process_slashings::process_slashings;
|
||||
use registry_updates::process_registry_updates;
|
||||
use std::collections::HashMap;
|
||||
use tree_hash::TreeHash;
|
||||
use types::*;
|
||||
use update_registry_and_shuffling_data::update_registry_and_shuffling_data;
|
||||
use validator_statuses::{TotalBalances, ValidatorStatuses};
|
||||
use winning_root::{winning_root, WinningRoot};
|
||||
|
||||
pub mod apply_rewards;
|
||||
pub mod errors;
|
||||
pub mod get_attestation_participants;
|
||||
pub mod get_attesting_indices;
|
||||
pub mod inclusion_distance;
|
||||
pub mod process_ejections;
|
||||
pub mod process_exit_queue;
|
||||
pub mod process_slashings;
|
||||
pub mod registry_updates;
|
||||
pub mod tests;
|
||||
pub mod update_registry_and_shuffling_data;
|
||||
pub mod validator_statuses;
|
||||
pub mod winning_root;
|
||||
|
||||
@ -54,7 +54,7 @@ pub fn per_epoch_processing(state: &mut BeaconState, spec: &ChainSpec) -> Result
|
||||
maybe_reset_eth1_period(state, spec);
|
||||
|
||||
// Rewards and Penalities.
|
||||
apply_rewards(
|
||||
process_rewards_and_penalties(
|
||||
state,
|
||||
&mut validator_statuses,
|
||||
&winning_root_for_shards,
|
||||
@ -65,11 +65,7 @@ pub fn per_epoch_processing(state: &mut BeaconState, spec: &ChainSpec) -> Result
|
||||
process_ejections(state, spec)?;
|
||||
|
||||
// Validator Registry.
|
||||
update_registry_and_shuffling_data(
|
||||
state,
|
||||
validator_statuses.total_balances.current_epoch,
|
||||
spec,
|
||||
)?;
|
||||
process_registry_updates(state, validator_statuses.total_balances.current_epoch, spec)?;
|
||||
|
||||
// Slashings and exit queue.
|
||||
process_slashings(state, validator_statuses.total_balances.current_epoch, spec)?;
|
||||
@ -88,6 +84,7 @@ pub fn per_epoch_processing(state: &mut BeaconState, spec: &ChainSpec) -> Result
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
pub fn maybe_reset_eth1_period(state: &mut BeaconState, spec: &ChainSpec) {
|
||||
/* FIXME(sproul)
|
||||
let next_epoch = state.next_epoch(spec);
|
||||
let voting_period = spec.epochs_per_eth1_voting_period;
|
||||
|
||||
@ -99,6 +96,7 @@ pub fn maybe_reset_eth1_period(state: &mut BeaconState, spec: &ChainSpec) {
|
||||
}
|
||||
state.eth1_data_votes = vec![];
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/// Update the following fields on the `BeaconState`:
|
||||
@ -132,8 +130,6 @@ pub fn process_justification_and_finalization(
|
||||
state.previous_justified_root = state.current_justified_root;
|
||||
state.justification_bitfield <<= 1;
|
||||
|
||||
let previous_epoch_matching_target_balance = total_balances.previous_epoch_target_attesters;
|
||||
|
||||
if total_balances.previous_epoch_target_attesters * 3 >= total_balances.previous_epoch * 2 {
|
||||
state.current_justified_epoch = previous_epoch;
|
||||
state.current_justified_root =
|
||||
@ -176,42 +172,33 @@ pub fn process_justification_and_finalization(
|
||||
|
||||
/// Updates the following fields on the `BeaconState`:
|
||||
///
|
||||
/// - `latest_crosslinks`
|
||||
/// - `previous_crosslinks`
|
||||
/// - `current_crosslinks`
|
||||
///
|
||||
/// Also returns a `WinningRootHashSet` for later use during epoch processing.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.1
|
||||
pub fn process_crosslinks(
|
||||
state: &mut BeaconState,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<WinningRootHashSet, Error> {
|
||||
let mut winning_root_for_shards: WinningRootHashSet = HashMap::new();
|
||||
|
||||
let previous_and_current_epoch_slots: Vec<Slot> = state
|
||||
.previous_epoch(spec)
|
||||
.slot_iter(spec.slots_per_epoch)
|
||||
.chain(state.current_epoch(spec).slot_iter(spec.slots_per_epoch))
|
||||
.collect();
|
||||
state.previous_crosslinks = state.current_crosslinks.clone();
|
||||
|
||||
for slot in previous_and_current_epoch_slots {
|
||||
// Clone removes the borrow which becomes an issue when mutating `state.balances`.
|
||||
let crosslink_committees_at_slot =
|
||||
state.get_crosslink_committees_at_slot(slot, spec)?.clone();
|
||||
for epoch in vec![state.previous_epoch(spec), state.current_epoch(spec)] {
|
||||
for offset in 0..state.get_epoch_committee_count(epoch, spec) {
|
||||
let shard = (state.get_epoch_start_shard(epoch, spec) + offset) % spec.shard_count;
|
||||
let crosslink_committee = state.get_crosslink_committee(epoch, shard, spec)?;
|
||||
|
||||
for c in crosslink_committees_at_slot {
|
||||
let shard = c.shard as u64;
|
||||
|
||||
let winning_root = winning_root(state, shard, spec)?;
|
||||
let winning_root = winning_root(state, shard, epoch, spec)?;
|
||||
|
||||
if let Some(winning_root) = winning_root {
|
||||
let total_committee_balance = state.get_total_balance(&c.committee, spec)?;
|
||||
let total_committee_balance =
|
||||
state.get_total_balance(&crosslink_committee.committee, spec)?;
|
||||
|
||||
// TODO: I think this has a bug.
|
||||
if (3 * winning_root.total_attesting_balance) >= (2 * total_committee_balance) {
|
||||
state.latest_crosslinks[shard as usize] = Crosslink {
|
||||
epoch: slot.epoch(spec.slots_per_epoch),
|
||||
crosslink_data_root: winning_root.crosslink_data_root,
|
||||
}
|
||||
if 3 * winning_root.total_attesting_balance >= 2 * total_committee_balance {
|
||||
state.current_crosslinks[shard as usize] = winning_root.crosslink.clone();
|
||||
}
|
||||
winning_root_for_shards.insert(shard, winning_root);
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use super::errors::InclusionError;
|
||||
use super::get_attestation_participants::get_attestation_participants;
|
||||
use types::*;
|
||||
|
||||
/// Returns the distance between the first included attestation for some validator and this
|
||||
@ -13,7 +12,9 @@ pub fn inclusion_distance(
|
||||
spec: &ChainSpec,
|
||||
) -> Result<u64, InclusionError> {
|
||||
let attestation = earliest_included_attestation(state, attestations, validator_index, spec)?;
|
||||
Ok((attestation.inclusion_slot - attestation.data.slot).as_u64())
|
||||
// Ok((attestation.inclusion_slot - attestation.data.slot).as_u64())
|
||||
// FIXME(sproul)
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// Returns the slot of the earliest included attestation for some validator.
|
||||
@ -25,8 +26,11 @@ pub fn inclusion_slot(
|
||||
validator_index: usize,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Slot, InclusionError> {
|
||||
/*
|
||||
let attestation = earliest_included_attestation(state, attestations, validator_index, spec)?;
|
||||
Ok(attestation.inclusion_slot)
|
||||
*/
|
||||
unimplemented!("FIXME(sproul) inclusion slot")
|
||||
}
|
||||
|
||||
/// Finds the earliest included attestation for some validator.
|
||||
@ -38,6 +42,9 @@ fn earliest_included_attestation(
|
||||
validator_index: usize,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<PendingAttestation, InclusionError> {
|
||||
// FIXME(sproul)
|
||||
unimplemented!()
|
||||
/*
|
||||
let mut included_attestations = vec![];
|
||||
|
||||
for (i, a) in attestations.iter().enumerate() {
|
||||
@ -53,4 +60,5 @@ fn earliest_included_attestation(
|
||||
.min_by_key(|i| attestations[**i].inclusion_slot)
|
||||
.ok_or_else(|| InclusionError::NoAttestationsForValidator)?;
|
||||
Ok(attestations[*earliest_attestation_index].clone())
|
||||
*/
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::common::exit_validator;
|
||||
// use crate::common::exit_validator;
|
||||
use types::{BeaconStateError as Error, *};
|
||||
|
||||
/// Iterate through the validator registry and eject active validators with balance below
|
||||
@ -12,7 +12,7 @@ pub fn process_ejections(state: &mut BeaconState, spec: &ChainSpec) -> Result<()
|
||||
.get_cached_active_validator_indices(RelativeEpoch::Current, spec)?
|
||||
.iter()
|
||||
.filter_map(|&i| {
|
||||
if state.validator_balances[i as usize] < spec.ejection_balance {
|
||||
if state.balances[i as usize] < spec.ejection_balance {
|
||||
Some(i)
|
||||
} else {
|
||||
None
|
||||
@ -21,7 +21,8 @@ pub fn process_ejections(state: &mut BeaconState, spec: &ChainSpec) -> Result<()
|
||||
.collect();
|
||||
|
||||
for validator_index in exitable {
|
||||
exit_validator(state, validator_index, spec)?
|
||||
// FIXME(sproul)
|
||||
// exit_validator(state, validator_index, spec)?
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -22,9 +22,11 @@ pub fn process_exit_queue(state: &mut BeaconState, spec: &ChainSpec) {
|
||||
eligable_indices.sort_by_key(|i| state.validator_registry[*i].exit_epoch);
|
||||
|
||||
for (dequeues, index) in eligable_indices.iter().enumerate() {
|
||||
/* FIXME(sproul)
|
||||
if dequeues as u64 >= spec.max_exit_dequeues_per_epoch {
|
||||
break;
|
||||
}
|
||||
*/
|
||||
prepare_validator_for_withdrawal(state, *index, spec);
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,10 @@ pub fn process_slashings(
|
||||
let penalty = std::cmp::max(
|
||||
effective_balance * std::cmp::min(total_penalities * 3, current_total_balance)
|
||||
/ current_total_balance,
|
||||
effective_balance / spec.min_penalty_quotient,
|
||||
effective_balance / 1, /* FIXME(sproul): spec.min_penalty_quotient, */
|
||||
);
|
||||
|
||||
state.validator_balances[index] -= penalty;
|
||||
state.balances[index] -= penalty;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![cfg(test)]
|
||||
#![cfg(all(not(test), test))]
|
||||
|
||||
use super::*;
|
||||
use crate::test_utils::*;
|
||||
|
Loading…
Reference in New Issue
Block a user