Do project-wide s/epoch_length/slots_per_epoch/g
This commit is contained in:
parent
a1af65ce1a
commit
663d39739f
@ -312,7 +312,7 @@ where
|
||||
.state
|
||||
.read()
|
||||
.get_block_root(
|
||||
justified_epoch.start_slot(self.spec.epoch_length),
|
||||
justified_epoch.start_slot(self.spec.slots_per_epoch),
|
||||
&self.spec,
|
||||
)
|
||||
.ok_or_else(|| Error::BadRecentBlockRoots)?;
|
||||
@ -333,7 +333,7 @@ where
|
||||
epoch_boundary_root,
|
||||
shard_block_root: Hash256::zero(),
|
||||
latest_crosslink: Crosslink {
|
||||
epoch: self.state.read().slot.epoch(self.spec.epoch_length),
|
||||
epoch: self.state.read().slot.epoch(self.spec.slots_per_epoch),
|
||||
shard_block_root: Hash256::zero(),
|
||||
},
|
||||
justified_epoch,
|
||||
|
@ -27,7 +27,7 @@ fork: tchaikovsky
|
||||
version: 1.0
|
||||
test_cases:
|
||||
- config:
|
||||
epoch_length: 64
|
||||
slots_per_epoch: 64
|
||||
deposits_for_chain_start: 1000
|
||||
num_slots: 64
|
||||
skip_slots: [2, 3]
|
||||
|
@ -11,7 +11,7 @@ fn mid_epoch_state_transition(c: &mut Criterion) {
|
||||
let validator_count = 1000;
|
||||
let mut rig = BeaconChainHarness::new(ChainSpec::foundation(), validator_count);
|
||||
|
||||
let epoch_depth = (rig.spec.epoch_length * 2) + (rig.spec.epoch_length / 2);
|
||||
let epoch_depth = (rig.spec.slots_per_epoch * 2) + (rig.spec.slots_per_epoch / 2);
|
||||
|
||||
for _ in 0..epoch_depth {
|
||||
rig.advance_chain_with_block();
|
||||
@ -19,7 +19,7 @@ fn mid_epoch_state_transition(c: &mut Criterion) {
|
||||
|
||||
let state = rig.beacon_chain.state.read().clone();
|
||||
|
||||
assert!((state.slot + 1) % rig.spec.epoch_length != 0);
|
||||
assert!((state.slot + 1) % rig.spec.slots_per_epoch != 0);
|
||||
|
||||
c.bench_function("mid-epoch state transition 10k validators", move |b| {
|
||||
let state = state.clone();
|
||||
@ -36,7 +36,7 @@ fn epoch_boundary_state_transition(c: &mut Criterion) {
|
||||
let validator_count = 10000;
|
||||
let mut rig = BeaconChainHarness::new(ChainSpec::foundation(), validator_count);
|
||||
|
||||
let epoch_depth = rig.spec.epoch_length * 2;
|
||||
let epoch_depth = rig.spec.slots_per_epoch * 2;
|
||||
|
||||
for _ in 0..(epoch_depth - 1) {
|
||||
rig.advance_chain_with_block();
|
||||
@ -44,7 +44,7 @@ fn epoch_boundary_state_transition(c: &mut Criterion) {
|
||||
|
||||
let state = rig.beacon_chain.state.read().clone();
|
||||
|
||||
assert_eq!((state.slot + 1) % rig.spec.epoch_length, 0);
|
||||
assert_eq!((state.slot + 1) % rig.spec.slots_per_epoch, 0);
|
||||
|
||||
c.bench(
|
||||
"routines",
|
||||
|
@ -5,7 +5,7 @@ fork: tchaikovsky
|
||||
version: 1.0
|
||||
test_cases:
|
||||
- config:
|
||||
epoch_length: 64
|
||||
slots_per_epoch: 64
|
||||
deposits_for_chain_start: 1000
|
||||
num_slots: 64
|
||||
skip_slots: [2, 3]
|
||||
|
@ -125,13 +125,13 @@ impl BeaconChainHarness {
|
||||
|
||||
let nth_slot = slot
|
||||
- slot
|
||||
.epoch(self.spec.epoch_length)
|
||||
.start_slot(self.spec.epoch_length);
|
||||
let nth_epoch = slot.epoch(self.spec.epoch_length) - self.spec.genesis_epoch;
|
||||
.epoch(self.spec.slots_per_epoch)
|
||||
.start_slot(self.spec.slots_per_epoch);
|
||||
let nth_epoch = slot.epoch(self.spec.slots_per_epoch) - self.spec.genesis_epoch;
|
||||
debug!(
|
||||
"Advancing BeaconChain to slot {}, epoch {} (epoch height: {}, slot {} in epoch.).",
|
||||
slot,
|
||||
slot.epoch(self.spec.epoch_length),
|
||||
slot.epoch(self.spec.slots_per_epoch),
|
||||
nth_epoch,
|
||||
nth_slot
|
||||
);
|
||||
|
@ -13,7 +13,7 @@ pub struct Config {
|
||||
/// Initial validators.
|
||||
pub deposits_for_chain_start: usize,
|
||||
/// Number of slots in an epoch.
|
||||
pub epoch_length: Option<u64>,
|
||||
pub slots_per_epoch: Option<u64>,
|
||||
/// Number of slots to build before ending execution.
|
||||
pub num_slots: u64,
|
||||
/// Number of slots that should be skipped due to inactive validator.
|
||||
@ -34,7 +34,7 @@ impl Config {
|
||||
Self {
|
||||
deposits_for_chain_start: as_usize(&yaml, "deposits_for_chain_start")
|
||||
.expect("Must specify validator count"),
|
||||
epoch_length: as_u64(&yaml, "epoch_length"),
|
||||
slots_per_epoch: as_u64(&yaml, "slots_per_epoch"),
|
||||
num_slots: as_u64(&yaml, "num_slots").expect("Must specify `config.num_slots`"),
|
||||
skip_slots: as_vec_u64(yaml, "skip_slots"),
|
||||
deposits: parse_deposits(&yaml),
|
||||
|
@ -54,12 +54,12 @@ impl TestCase {
|
||||
|
||||
/// Return a `ChainSpec::foundation()`.
|
||||
///
|
||||
/// If specified in `config`, returns it with a modified `epoch_length`.
|
||||
/// If specified in `config`, returns it with a modified `slots_per_epoch`.
|
||||
fn spec(&self) -> ChainSpec {
|
||||
let mut spec = ChainSpec::foundation();
|
||||
|
||||
if let Some(n) = self.config.epoch_length {
|
||||
spec.epoch_length = n;
|
||||
if let Some(n) = self.config.slots_per_epoch {
|
||||
spec.slots_per_epoch = n;
|
||||
}
|
||||
|
||||
spec
|
||||
@ -174,7 +174,7 @@ impl TestCase {
|
||||
|
||||
for state_check in state_checks {
|
||||
let adjusted_state_slot =
|
||||
state.slot - spec.genesis_epoch.start_slot(spec.epoch_length);
|
||||
state.slot - spec.genesis_epoch.start_slot(spec.slots_per_epoch);
|
||||
|
||||
if state_check.slot == adjusted_state_slot {
|
||||
state_check.assert_valid(state, spec);
|
||||
|
@ -36,13 +36,13 @@ impl StateCheck {
|
||||
///
|
||||
/// Panics with an error message if any test fails.
|
||||
pub fn assert_valid(&self, state: &BeaconState, spec: &ChainSpec) {
|
||||
let state_epoch = state.slot.epoch(spec.epoch_length);
|
||||
let state_epoch = state.slot.epoch(spec.slots_per_epoch);
|
||||
|
||||
info!("Running state check for slot height {}.", self.slot);
|
||||
|
||||
assert_eq!(
|
||||
self.slot,
|
||||
state.slot - spec.genesis_epoch.start_slot(spec.epoch_length),
|
||||
state.slot - spec.genesis_epoch.start_slot(spec.slots_per_epoch),
|
||||
"State slot is invalid."
|
||||
);
|
||||
|
||||
|
@ -29,7 +29,7 @@ fn it_can_produce_past_first_epoch_boundary() {
|
||||
|
||||
debug!("Harness built, tests starting..");
|
||||
|
||||
let blocks = harness.spec.epoch_length * 2 + 1;
|
||||
let blocks = harness.spec.slots_per_epoch * 2 + 1;
|
||||
|
||||
for i in 0..blocks {
|
||||
harness.advance_chain_with_block();
|
||||
|
@ -195,9 +195,9 @@ mod tests {
|
||||
let beacon_node = Arc::new(SimulatedBeaconNode::default());
|
||||
let signer = Arc::new(LocalSigner::new(Keypair::random()));
|
||||
|
||||
let mut duties = EpochMap::new(spec.epoch_length);
|
||||
let mut duties = EpochMap::new(spec.slots_per_epoch);
|
||||
let attest_slot = Slot::new(100);
|
||||
let attest_epoch = attest_slot / spec.epoch_length;
|
||||
let attest_epoch = attest_slot / spec.slots_per_epoch;
|
||||
let attest_shard = 12;
|
||||
duties.insert_attestation_shard(attest_slot, attest_shard);
|
||||
duties.set_validator_index(Some(2));
|
||||
@ -243,7 +243,7 @@ mod tests {
|
||||
);
|
||||
|
||||
// In an epoch without known duties...
|
||||
let slot = (attest_epoch + 1) * spec.epoch_length;
|
||||
let slot = (attest_epoch + 1) * spec.slots_per_epoch;
|
||||
slot_clock.set_slot(slot.into());
|
||||
assert_eq!(
|
||||
attester.poll(),
|
||||
|
@ -3,22 +3,22 @@ use std::collections::HashMap;
|
||||
use types::{Epoch, Slot};
|
||||
|
||||
pub struct EpochMap {
|
||||
epoch_length: u64,
|
||||
slots_per_epoch: u64,
|
||||
validator_index: Option<u64>,
|
||||
map: HashMap<Epoch, (Slot, u64)>,
|
||||
}
|
||||
|
||||
impl EpochMap {
|
||||
pub fn new(epoch_length: u64) -> Self {
|
||||
pub fn new(slots_per_epoch: u64) -> Self {
|
||||
Self {
|
||||
epoch_length,
|
||||
slots_per_epoch,
|
||||
validator_index: None,
|
||||
map: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert_attestation_shard(&mut self, slot: Slot, shard: u64) {
|
||||
let epoch = slot.epoch(self.epoch_length);
|
||||
let epoch = slot.epoch(self.slots_per_epoch);
|
||||
self.map.insert(epoch, (slot, shard));
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ impl EpochMap {
|
||||
|
||||
impl DutiesReader for EpochMap {
|
||||
fn attestation_shard(&self, slot: Slot) -> Result<Option<u64>, DutiesReaderError> {
|
||||
let epoch = slot.epoch(self.epoch_length);
|
||||
let epoch = slot.epoch(self.slots_per_epoch);
|
||||
|
||||
match self.map.get(&epoch) {
|
||||
Some((attest_slot, attest_shard)) if *attest_slot == slot => Ok(Some(*attest_shard)),
|
||||
|
@ -132,7 +132,7 @@ impl<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> BlockProducer<T, U
|
||||
fn produce_block(&mut self, slot: Slot) -> Result<PollOutcome, Error> {
|
||||
let randao_reveal = {
|
||||
// TODO: add domain, etc to this message. Also ensure result matches `into_to_bytes32`.
|
||||
let message = int_to_bytes32(slot.epoch(self.spec.epoch_length).as_u64());
|
||||
let message = int_to_bytes32(slot.epoch(self.spec.slots_per_epoch).as_u64());
|
||||
|
||||
match self
|
||||
.signer
|
||||
@ -233,9 +233,9 @@ mod tests {
|
||||
let beacon_node = Arc::new(SimulatedBeaconNode::default());
|
||||
let signer = Arc::new(LocalSigner::new(Keypair::random()));
|
||||
|
||||
let mut epoch_map = EpochMap::new(spec.epoch_length);
|
||||
let mut epoch_map = EpochMap::new(spec.slots_per_epoch);
|
||||
let produce_slot = Slot::new(100);
|
||||
let produce_epoch = produce_slot.epoch(spec.epoch_length);
|
||||
let produce_epoch = produce_slot.epoch(spec.slots_per_epoch);
|
||||
epoch_map.map.insert(produce_epoch, produce_slot);
|
||||
let epoch_map = Arc::new(epoch_map);
|
||||
|
||||
@ -280,7 +280,7 @@ mod tests {
|
||||
);
|
||||
|
||||
// In an epoch without known duties...
|
||||
let slot = (produce_epoch.as_u64() + 1) * spec.epoch_length;
|
||||
let slot = (produce_epoch.as_u64() + 1) * spec.slots_per_epoch;
|
||||
slot_clock.set_slot(slot);
|
||||
assert_eq!(
|
||||
block_proposer.poll(),
|
||||
|
@ -3,14 +3,14 @@ use std::collections::HashMap;
|
||||
use types::{Epoch, Slot};
|
||||
|
||||
pub struct EpochMap {
|
||||
epoch_length: u64,
|
||||
slots_per_epoch: u64,
|
||||
pub map: HashMap<Epoch, Slot>,
|
||||
}
|
||||
|
||||
impl EpochMap {
|
||||
pub fn new(epoch_length: u64) -> Self {
|
||||
pub fn new(slots_per_epoch: u64) -> Self {
|
||||
Self {
|
||||
epoch_length,
|
||||
slots_per_epoch,
|
||||
map: HashMap::new(),
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,7 @@ impl EpochMap {
|
||||
|
||||
impl DutiesReader for EpochMap {
|
||||
fn is_block_production_slot(&self, slot: Slot) -> Result<bool, DutiesReaderError> {
|
||||
let epoch = slot.epoch(self.epoch_length);
|
||||
let epoch = slot.epoch(self.slots_per_epoch);
|
||||
match self.map.get(&epoch) {
|
||||
Some(s) if *s == slot => Ok(true),
|
||||
Some(s) if *s != slot => Ok(false),
|
||||
|
@ -95,7 +95,7 @@ where
|
||||
|
||||
let active_validator_indices = get_active_validator_indices(
|
||||
¤t_state.validator_registry[..],
|
||||
block_slot.epoch(spec.epoch_length),
|
||||
block_slot.epoch(spec.slots_per_epoch),
|
||||
);
|
||||
|
||||
for index in active_validator_indices {
|
||||
|
@ -64,7 +64,7 @@ where
|
||||
|
||||
let active_validator_indices = get_active_validator_indices(
|
||||
¤t_state.validator_registry[..],
|
||||
block_slot.epoch(spec.epoch_length),
|
||||
block_slot.epoch(spec.slots_per_epoch),
|
||||
);
|
||||
|
||||
for index in active_validator_indices {
|
||||
|
@ -185,7 +185,7 @@ fn per_block_processing_signature_optional(
|
||||
proposer_slashing
|
||||
.proposal_data_1
|
||||
.slot
|
||||
.epoch(spec.epoch_length),
|
||||
.epoch(spec.slots_per_epoch),
|
||||
spec.domain_proposal
|
||||
)
|
||||
),
|
||||
@ -201,7 +201,7 @@ fn per_block_processing_signature_optional(
|
||||
proposer_slashing
|
||||
.proposal_data_2
|
||||
.slot
|
||||
.epoch(spec.epoch_length),
|
||||
.epoch(spec.slots_per_epoch),
|
||||
spec.domain_proposal
|
||||
)
|
||||
),
|
||||
@ -341,14 +341,14 @@ fn validate_attestation_signature_optional(
|
||||
) -> Result<(), AttestationValidationError> {
|
||||
trace!(
|
||||
"validate_attestation_signature_optional: attestation epoch: {}",
|
||||
attestation.data.slot.epoch(spec.epoch_length)
|
||||
attestation.data.slot.epoch(spec.slots_per_epoch)
|
||||
);
|
||||
ensure!(
|
||||
attestation.data.slot + spec.min_attestation_inclusion_delay <= state.slot,
|
||||
AttestationValidationError::IncludedTooEarly
|
||||
);
|
||||
ensure!(
|
||||
attestation.data.slot + spec.epoch_length >= state.slot,
|
||||
attestation.data.slot + spec.slots_per_epoch >= state.slot,
|
||||
AttestationValidationError::IncludedTooLate
|
||||
);
|
||||
if attestation.data.slot >= state.current_epoch_start_slot(spec) {
|
||||
@ -369,7 +369,7 @@ fn validate_attestation_signature_optional(
|
||||
attestation
|
||||
.data
|
||||
.justified_epoch
|
||||
.start_slot(spec.epoch_length),
|
||||
.start_slot(spec.slots_per_epoch),
|
||||
&spec
|
||||
)
|
||||
.ok_or(AttestationValidationError::NoBlockRoot)?,
|
||||
@ -377,7 +377,7 @@ fn validate_attestation_signature_optional(
|
||||
);
|
||||
let potential_crosslink = Crosslink {
|
||||
shard_block_root: attestation.data.shard_block_root,
|
||||
epoch: attestation.data.slot.epoch(spec.epoch_length),
|
||||
epoch: attestation.data.slot.epoch(spec.slots_per_epoch),
|
||||
};
|
||||
ensure!(
|
||||
(attestation.data.latest_crosslink
|
||||
@ -407,7 +407,7 @@ fn validate_attestation_signature_optional(
|
||||
PHASE_0_CUSTODY_BIT,
|
||||
get_domain(
|
||||
&state.fork,
|
||||
attestation.data.slot.epoch(spec.epoch_length),
|
||||
attestation.data.slot.epoch(spec.slots_per_epoch),
|
||||
spec.domain_attestation,
|
||||
)
|
||||
),
|
||||
|
@ -76,7 +76,7 @@ impl EpochProcessable for BeaconState {
|
||||
*/
|
||||
let active_validator_indices = get_active_validator_indices(
|
||||
&self.validator_registry,
|
||||
self.slot.epoch(spec.epoch_length),
|
||||
self.slot.epoch(spec.slots_per_epoch),
|
||||
);
|
||||
let current_total_balance = self.get_total_balance(&active_validator_indices[..], spec);
|
||||
|
||||
@ -90,7 +90,7 @@ impl EpochProcessable for BeaconState {
|
||||
.latest_attestations
|
||||
.par_iter()
|
||||
.filter(|a| {
|
||||
(a.data.slot / spec.epoch_length).epoch(spec.epoch_length)
|
||||
(a.data.slot / spec.slots_per_epoch).epoch(spec.slots_per_epoch)
|
||||
== self.current_epoch(spec)
|
||||
})
|
||||
.collect();
|
||||
@ -137,7 +137,7 @@ impl EpochProcessable for BeaconState {
|
||||
.par_iter()
|
||||
.filter(|a| {
|
||||
//TODO: ensure these saturating subs are correct.
|
||||
(a.data.slot / spec.epoch_length).epoch(spec.epoch_length)
|
||||
(a.data.slot / spec.slots_per_epoch).epoch(spec.slots_per_epoch)
|
||||
== self.previous_epoch(spec)
|
||||
})
|
||||
.collect();
|
||||
@ -320,12 +320,12 @@ impl EpochProcessable for BeaconState {
|
||||
let mut winning_root_for_shards: HashMap<u64, Result<WinningRoot, WinningRootError>> =
|
||||
HashMap::new();
|
||||
|
||||
// for slot in self.slot.saturating_sub(2 * spec.epoch_length)..self.slot {
|
||||
for slot in self.previous_epoch(spec).slot_iter(spec.epoch_length) {
|
||||
// for slot in self.slot.saturating_sub(2 * spec.slots_per_epoch)..self.slot {
|
||||
for slot in self.previous_epoch(spec).slot_iter(spec.slots_per_epoch) {
|
||||
trace!(
|
||||
"Finding winning root for slot: {} (epoch: {})",
|
||||
slot,
|
||||
slot.epoch(spec.epoch_length)
|
||||
slot.epoch(spec.slots_per_epoch)
|
||||
);
|
||||
|
||||
// Clone is used to remove the borrow. It becomes an issue later when trying to mutate
|
||||
@ -506,7 +506,7 @@ impl EpochProcessable for BeaconState {
|
||||
/*
|
||||
* Crosslinks
|
||||
*/
|
||||
for slot in self.previous_epoch(spec).slot_iter(spec.epoch_length) {
|
||||
for slot in self.previous_epoch(spec).slot_iter(spec.slots_per_epoch) {
|
||||
// Clone is used to remove the borrow. It becomes an issue later when trying to mutate
|
||||
// `self.balances`.
|
||||
let crosslink_committees_at_slot =
|
||||
@ -615,7 +615,7 @@ impl EpochProcessable for BeaconState {
|
||||
self.latest_attestations = self
|
||||
.latest_attestations
|
||||
.iter()
|
||||
.filter(|a| a.data.slot.epoch(spec.epoch_length) >= current_epoch)
|
||||
.filter(|a| a.data.slot.epoch(spec.slots_per_epoch) >= current_epoch)
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
|
@ -24,7 +24,7 @@ where
|
||||
previous_block_root: Hash256,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
if (self.slot + 1) % spec.epoch_length == 0 {
|
||||
if (self.slot + 1) % spec.slots_per_epoch == 0 {
|
||||
self.per_epoch_processing(spec)?;
|
||||
self.advance_caches();
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ impl BeaconState {
|
||||
///
|
||||
/// Spec v0.2.0
|
||||
pub fn current_epoch(&self, spec: &ChainSpec) -> Epoch {
|
||||
self.slot.epoch(spec.epoch_length)
|
||||
self.slot.epoch(spec.slots_per_epoch)
|
||||
}
|
||||
|
||||
/// The epoch prior to `self.current_epoch()`.
|
||||
@ -363,14 +363,14 @@ impl BeaconState {
|
||||
///
|
||||
/// Spec v0.2.0
|
||||
pub fn current_epoch_start_slot(&self, spec: &ChainSpec) -> Slot {
|
||||
self.current_epoch(spec).start_slot(spec.epoch_length)
|
||||
self.current_epoch(spec).start_slot(spec.slots_per_epoch)
|
||||
}
|
||||
|
||||
/// The first slot of the epoch preceeding the one corresponding to `self.slot`.
|
||||
///
|
||||
/// Spec v0.2.0
|
||||
pub fn previous_epoch_start_slot(&self, spec: &ChainSpec) -> Slot {
|
||||
self.previous_epoch(spec).start_slot(spec.epoch_length)
|
||||
self.previous_epoch(spec).start_slot(spec.slots_per_epoch)
|
||||
}
|
||||
|
||||
/// Return the number of committees in one epoch.
|
||||
@ -386,10 +386,10 @@ impl BeaconState {
|
||||
std::cmp::max(
|
||||
1,
|
||||
std::cmp::min(
|
||||
spec.shard_count / spec.epoch_length,
|
||||
active_validator_count as u64 / spec.epoch_length / spec.target_committee_size,
|
||||
spec.shard_count / spec.slots_per_epoch,
|
||||
active_validator_count as u64 / spec.slots_per_epoch / spec.target_committee_size,
|
||||
),
|
||||
) * spec.epoch_length
|
||||
) * spec.slots_per_epoch
|
||||
}
|
||||
|
||||
/// Shuffle ``validators`` into crosslink committees seeded by ``seed`` and ``epoch``.
|
||||
@ -520,11 +520,11 @@ impl BeaconState {
|
||||
slot: Slot,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<&CrosslinkCommittees, Error> {
|
||||
let epoch = slot.epoch(spec.epoch_length);
|
||||
let epoch = slot.epoch(spec.slots_per_epoch);
|
||||
let relative_epoch = self.relative_epoch(epoch, spec)?;
|
||||
let cache = self.cache(relative_epoch)?;
|
||||
|
||||
let slot_offset = slot - epoch.start_slot(spec.epoch_length);
|
||||
let slot_offset = slot - epoch.start_slot(spec.slots_per_epoch);
|
||||
|
||||
Ok(&cache.committees[slot_offset.as_usize()])
|
||||
}
|
||||
@ -565,7 +565,7 @@ impl BeaconState {
|
||||
registry_change: bool,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(u64, Hash256, Epoch, u64), Error> {
|
||||
let epoch = slot.epoch(spec.epoch_length);
|
||||
let epoch = slot.epoch(spec.slots_per_epoch);
|
||||
let current_epoch = self.current_epoch(spec);
|
||||
let previous_epoch = self.previous_epoch(spec);
|
||||
let next_epoch = self.next_epoch(spec);
|
||||
@ -639,8 +639,8 @@ impl BeaconState {
|
||||
let (committees_per_epoch, _seed, _shuffling_epoch, shuffling_start_shard) =
|
||||
self.get_committee_params_at_slot(slot, registry_change, spec)?;
|
||||
|
||||
let offset = slot.as_u64() % spec.epoch_length;
|
||||
let committees_per_slot = committees_per_epoch / spec.epoch_length;
|
||||
let offset = slot.as_u64() % spec.slots_per_epoch;
|
||||
let committees_per_slot = committees_per_epoch / spec.slots_per_epoch;
|
||||
let slot_start_shard =
|
||||
(shuffling_start_shard + committees_per_slot * offset) % spec.shard_count;
|
||||
|
||||
@ -835,7 +835,7 @@ impl BeaconState {
|
||||
proof_of_possession.verify(
|
||||
&proof_of_possession_data.hash_tree_root(),
|
||||
self.fork
|
||||
.get_domain(self.slot.epoch(spec.epoch_length), spec.domain_deposit),
|
||||
.get_domain(self.slot.epoch(spec.slots_per_epoch), spec.domain_deposit),
|
||||
&pubkey,
|
||||
)
|
||||
}
|
||||
@ -1296,7 +1296,7 @@ impl BeaconState {
|
||||
bitfield: &Bitfield,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Vec<usize>, Error> {
|
||||
let epoch = attestation_data.slot.epoch(spec.epoch_length);
|
||||
let epoch = attestation_data.slot.epoch(spec.slots_per_epoch);
|
||||
let relative_epoch = self.relative_epoch(epoch, spec)?;
|
||||
let cache = self.cache(relative_epoch)?;
|
||||
|
||||
|
@ -137,7 +137,7 @@ impl BeaconStateBuilder {
|
||||
pub fn teleport_to_end_of_epoch(&mut self, epoch: Epoch) {
|
||||
let state = self.state.as_mut().expect("Genesis required");
|
||||
|
||||
let slot = epoch.end_slot(self.spec.epoch_length);
|
||||
let slot = epoch.end_slot(self.spec.slots_per_epoch);
|
||||
|
||||
state.slot = slot;
|
||||
state.validator_registry_update_epoch = epoch - 1;
|
||||
@ -171,11 +171,11 @@ impl BeaconStateBuilder {
|
||||
let current_epoch = state.current_epoch(&self.spec);
|
||||
let previous_epoch = state.previous_epoch(&self.spec);
|
||||
let current_epoch_depth =
|
||||
(state.slot - current_epoch.end_slot(self.spec.epoch_length)).as_usize();
|
||||
(state.slot - current_epoch.end_slot(self.spec.slots_per_epoch)).as_usize();
|
||||
|
||||
let previous_epoch_slots = previous_epoch.slot_iter(self.spec.epoch_length);
|
||||
let previous_epoch_slots = previous_epoch.slot_iter(self.spec.slots_per_epoch);
|
||||
let current_epoch_slots = current_epoch
|
||||
.slot_iter(self.spec.epoch_length)
|
||||
.slot_iter(self.spec.slots_per_epoch)
|
||||
.take(current_epoch_depth);
|
||||
|
||||
for slot in previous_epoch_slots.chain(current_epoch_slots) {
|
||||
@ -219,7 +219,8 @@ fn committee_to_pending_attestation(
|
||||
custody_bitfield.set(i, true);
|
||||
}
|
||||
|
||||
let is_previous_epoch = state.slot.epoch(spec.epoch_length) != slot.epoch(spec.epoch_length);
|
||||
let is_previous_epoch =
|
||||
state.slot.epoch(spec.slots_per_epoch) != slot.epoch(spec.slots_per_epoch);
|
||||
|
||||
let justified_epoch = if is_previous_epoch {
|
||||
state.previous_justified_epoch
|
||||
@ -229,16 +230,16 @@ fn committee_to_pending_attestation(
|
||||
|
||||
let epoch_boundary_root = if is_previous_epoch {
|
||||
*state
|
||||
.get_block_root(previous_epoch.start_slot(spec.epoch_length), spec)
|
||||
.get_block_root(previous_epoch.start_slot(spec.slots_per_epoch), spec)
|
||||
.unwrap()
|
||||
} else {
|
||||
*state
|
||||
.get_block_root(current_epoch.start_slot(spec.epoch_length), spec)
|
||||
.get_block_root(current_epoch.start_slot(spec.slots_per_epoch), spec)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let justified_block_root = *state
|
||||
.get_block_root(justified_epoch.start_slot(spec.epoch_length), &spec)
|
||||
.get_block_root(justified_epoch.start_slot(spec.slots_per_epoch), &spec)
|
||||
.unwrap();
|
||||
|
||||
PendingAttestation {
|
||||
@ -250,7 +251,7 @@ fn committee_to_pending_attestation(
|
||||
epoch_boundary_root,
|
||||
shard_block_root: Hash256::zero(),
|
||||
latest_crosslink: Crosslink {
|
||||
epoch: slot.epoch(spec.epoch_length),
|
||||
epoch: slot.epoch(spec.slots_per_epoch),
|
||||
shard_block_root: Hash256::zero(),
|
||||
},
|
||||
justified_epoch,
|
||||
|
@ -32,14 +32,14 @@ impl EpochCache {
|
||||
spec: &ChainSpec,
|
||||
) -> Result<EpochCache, Error> {
|
||||
let mut epoch_committees: Vec<CrosslinkCommittees> =
|
||||
Vec::with_capacity(spec.epoch_length as usize);
|
||||
Vec::with_capacity(spec.slots_per_epoch as usize);
|
||||
let mut attestation_duty_map: AttestationDutyMap = HashMap::new();
|
||||
let mut shard_committee_index_map: ShardCommitteeIndexMap = HashMap::new();
|
||||
|
||||
let shuffling =
|
||||
state.get_shuffling_for_slot(epoch.start_slot(spec.epoch_length), false, spec)?;
|
||||
state.get_shuffling_for_slot(epoch.start_slot(spec.slots_per_epoch), false, spec)?;
|
||||
|
||||
for (epoch_committeess_index, slot) in epoch.slot_iter(spec.epoch_length).enumerate() {
|
||||
for (epoch_committeess_index, slot) in epoch.slot_iter(spec.slots_per_epoch).enumerate() {
|
||||
let slot_committees = state.calculate_crosslink_committees_at_slot(
|
||||
slot,
|
||||
false,
|
||||
|
@ -35,8 +35,8 @@ pub fn get_attestation_participants_consistency() {
|
||||
|
||||
for slot in state
|
||||
.slot
|
||||
.epoch(spec.epoch_length)
|
||||
.slot_iter(spec.epoch_length)
|
||||
.epoch(spec.slots_per_epoch)
|
||||
.slot_iter(spec.slots_per_epoch)
|
||||
{
|
||||
let committees = state.get_crosslink_committees_at_slot(slot, &spec).unwrap();
|
||||
|
||||
|
@ -38,14 +38,14 @@ impl ProposerSlashingBuilder {
|
||||
|
||||
proposal_1.signature = {
|
||||
let message = proposal_1.signed_root();
|
||||
let epoch = slot.epoch(spec.epoch_length);
|
||||
let epoch = slot.epoch(spec.slots_per_epoch);
|
||||
let domain = spec.domain_proposal;
|
||||
signer(proposer_index, &message[..], epoch, domain)
|
||||
};
|
||||
|
||||
proposal_2.signature = {
|
||||
let message = proposal_2.signed_root();
|
||||
let epoch = slot.epoch(spec.epoch_length);
|
||||
let epoch = slot.epoch(spec.slots_per_epoch);
|
||||
let domain = spec.domain_proposal;
|
||||
signer(proposer_index, &message[..], epoch, domain)
|
||||
};
|
||||
|
@ -24,7 +24,7 @@ impl SlashableAttestation {
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
pub fn is_double_vote(&self, other: &SlashableAttestation, spec: &ChainSpec) -> bool {
|
||||
self.data.slot.epoch(spec.epoch_length) == other.data.slot.epoch(spec.epoch_length)
|
||||
self.data.slot.epoch(spec.slots_per_epoch) == other.data.slot.epoch(spec.slots_per_epoch)
|
||||
}
|
||||
|
||||
/// Check if ``attestation_data_1`` surrounds ``attestation_data_2``.
|
||||
@ -33,8 +33,8 @@ impl SlashableAttestation {
|
||||
pub fn is_surround_vote(&self, other: &SlashableAttestation, spec: &ChainSpec) -> bool {
|
||||
let source_epoch_1 = self.data.justified_epoch;
|
||||
let source_epoch_2 = other.data.justified_epoch;
|
||||
let target_epoch_1 = self.data.slot.epoch(spec.epoch_length);
|
||||
let target_epoch_2 = other.data.slot.epoch(spec.epoch_length);
|
||||
let target_epoch_1 = self.data.slot.epoch(spec.slots_per_epoch);
|
||||
let target_epoch_2 = other.data.slot.epoch(spec.slots_per_epoch);
|
||||
|
||||
(source_epoch_1 < source_epoch_2) & (target_epoch_2 < target_epoch_1)
|
||||
}
|
||||
@ -151,7 +151,7 @@ mod tests {
|
||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||
let mut slashable_vote = SlashableAttestation::random_for_test(&mut rng);
|
||||
|
||||
slashable_vote.data.slot = Slot::new(slot_factor * spec.epoch_length);
|
||||
slashable_vote.data.slot = Slot::new(slot_factor * spec.slots_per_epoch);
|
||||
slashable_vote.data.justified_epoch = Epoch::new(justified_epoch);
|
||||
slashable_vote
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ impl Slot {
|
||||
Slot(slot)
|
||||
}
|
||||
|
||||
pub fn epoch(self, epoch_length: u64) -> Epoch {
|
||||
Epoch::from(self.0 / epoch_length)
|
||||
pub fn epoch(self, slots_per_epoch: u64) -> Epoch {
|
||||
Epoch::from(self.0 / slots_per_epoch)
|
||||
}
|
||||
|
||||
pub fn height(self, genesis_slot: Slot) -> SlotHeight {
|
||||
@ -57,24 +57,24 @@ impl Epoch {
|
||||
Epoch(u64::max_value())
|
||||
}
|
||||
|
||||
pub fn start_slot(self, epoch_length: u64) -> Slot {
|
||||
Slot::from(self.0.saturating_mul(epoch_length))
|
||||
pub fn start_slot(self, slots_per_epoch: u64) -> Slot {
|
||||
Slot::from(self.0.saturating_mul(slots_per_epoch))
|
||||
}
|
||||
|
||||
pub fn end_slot(self, epoch_length: u64) -> Slot {
|
||||
pub fn end_slot(self, slots_per_epoch: u64) -> Slot {
|
||||
Slot::from(
|
||||
self.0
|
||||
.saturating_add(1)
|
||||
.saturating_mul(epoch_length)
|
||||
.saturating_mul(slots_per_epoch)
|
||||
.saturating_sub(1),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn slot_iter(&self, epoch_length: u64) -> SlotIter {
|
||||
pub fn slot_iter(&self, slots_per_epoch: u64) -> SlotIter {
|
||||
SlotIter {
|
||||
current_iteration: 0,
|
||||
epoch: self,
|
||||
epoch_length,
|
||||
slots_per_epoch,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -82,17 +82,17 @@ impl Epoch {
|
||||
pub struct SlotIter<'a> {
|
||||
current_iteration: u64,
|
||||
epoch: &'a Epoch,
|
||||
epoch_length: u64,
|
||||
slots_per_epoch: u64,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for SlotIter<'a> {
|
||||
type Item = Slot;
|
||||
|
||||
fn next(&mut self) -> Option<Slot> {
|
||||
if self.current_iteration >= self.epoch_length {
|
||||
if self.current_iteration >= self.slots_per_epoch {
|
||||
None
|
||||
} else {
|
||||
let start_slot = self.epoch.start_slot(self.epoch_length);
|
||||
let start_slot = self.epoch.start_slot(self.slots_per_epoch);
|
||||
let previous = self.current_iteration;
|
||||
self.current_iteration += 1;
|
||||
Some(start_slot + previous)
|
||||
@ -119,18 +119,18 @@ mod epoch_tests {
|
||||
|
||||
#[test]
|
||||
fn slot_iter() {
|
||||
let epoch_length = 8;
|
||||
let slots_per_epoch = 8;
|
||||
|
||||
let epoch = Epoch::new(0);
|
||||
|
||||
let mut slots = vec![];
|
||||
for slot in epoch.slot_iter(epoch_length) {
|
||||
for slot in epoch.slot_iter(slots_per_epoch) {
|
||||
slots.push(slot);
|
||||
}
|
||||
|
||||
assert_eq!(slots.len(), epoch_length as usize);
|
||||
assert_eq!(slots.len(), slots_per_epoch as usize);
|
||||
|
||||
for i in 0..epoch_length {
|
||||
for i in 0..slots_per_epoch {
|
||||
assert_eq!(Slot::from(i), slots[i as usize])
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ impl SlotHeight {
|
||||
Slot::from(self.0.saturating_add(genesis_slot.as_u64()))
|
||||
}
|
||||
|
||||
pub fn epoch(self, genesis_slot: u64, epoch_length: u64) -> Epoch {
|
||||
Epoch::from(self.0.saturating_add(genesis_slot) / epoch_length)
|
||||
pub fn epoch(self, genesis_slot: u64, slots_per_epoch: u64) -> Epoch {
|
||||
Epoch::from(self.0.saturating_add(genesis_slot) / slots_per_epoch)
|
||||
}
|
||||
|
||||
pub fn max_value() -> SlotHeight {
|
||||
|
@ -32,14 +32,14 @@ pub enum EpochDutiesMapError {
|
||||
|
||||
/// Maps an `epoch` to some `EpochDuties` for a single validator.
|
||||
pub struct EpochDutiesMap {
|
||||
pub epoch_length: u64,
|
||||
pub slots_per_epoch: u64,
|
||||
pub map: RwLock<HashMap<Epoch, EpochDuties>>,
|
||||
}
|
||||
|
||||
impl EpochDutiesMap {
|
||||
pub fn new(epoch_length: u64) -> Self {
|
||||
pub fn new(slots_per_epoch: u64) -> Self {
|
||||
Self {
|
||||
epoch_length,
|
||||
slots_per_epoch,
|
||||
map: RwLock::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
@ -67,7 +67,7 @@ impl EpochDutiesMap {
|
||||
|
||||
impl DutiesReader for EpochDutiesMap {
|
||||
fn is_block_production_slot(&self, slot: Slot) -> Result<bool, DutiesReaderError> {
|
||||
let epoch = slot.epoch(self.epoch_length);
|
||||
let epoch = slot.epoch(self.slots_per_epoch);
|
||||
|
||||
let map = self.map.read().map_err(|_| DutiesReaderError::Poisoned)?;
|
||||
let duties = map
|
||||
|
@ -61,7 +61,7 @@ impl<T: SlotClock, U: BeaconNode> DutiesManager<T, U> {
|
||||
.map_err(|_| Error::SlotClockError)?
|
||||
.ok_or(Error::SlotUnknowable)?;
|
||||
|
||||
let epoch = slot.epoch(self.spec.epoch_length);
|
||||
let epoch = slot.epoch(self.spec.slots_per_epoch);
|
||||
|
||||
if let Some(duties) = self.beacon_node.request_shuffling(epoch, &self.pubkey)? {
|
||||
// If these duties were known, check to see if they're updates or identical.
|
||||
@ -112,7 +112,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn polling() {
|
||||
let spec = Arc::new(ChainSpec::foundation());
|
||||
let duties_map = Arc::new(EpochDutiesMap::new(spec.epoch_length));
|
||||
let duties_map = Arc::new(EpochDutiesMap::new(spec.slots_per_epoch));
|
||||
let keypair = Keypair::random();
|
||||
let slot_clock = Arc::new(TestingSlotClock::new(0));
|
||||
let beacon_node = Arc::new(TestBeaconNode::default());
|
||||
|
@ -111,7 +111,7 @@ fn main() {
|
||||
|
||||
for keypair in keypairs {
|
||||
info!(log, "Starting validator services"; "validator" => keypair.pk.concatenated_hex_id());
|
||||
let duties_map = Arc::new(EpochDutiesMap::new(spec.epoch_length));
|
||||
let duties_map = Arc::new(EpochDutiesMap::new(spec.slots_per_epoch));
|
||||
|
||||
// Spawn a new thread to maintain the validator's `EpochDuties`.
|
||||
let duties_manager_thread = {
|
||||
|
Loading…
Reference in New Issue
Block a user