Do project-wide s/epoch_length/slots_per_epoch/g

This commit is contained in:
Paul Hauner
2019-03-04 17:51:54 +11:00
parent a1af65ce1a
commit 663d39739f
29 changed files with 113 additions and 112 deletions

View File

@@ -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,

View File

@@ -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]

View File

@@ -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",

View File

@@ -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]

View File

@@ -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
);

View File

@@ -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),

View File

@@ -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);

View File

@@ -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."
);

View File

@@ -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();