Update CrystallizedState as per new spec.

This commit is contained in:
Paul Hauner 2018-10-20 17:15:53 +11:00
parent de8b84f9cd
commit a8d2b20570
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 17 additions and 58 deletions

View File

@ -2,7 +2,8 @@ use super::Hash256;
#[derive(Clone)] #[derive(Clone)]
pub struct CrosslinkRecord { pub struct CrosslinkRecord {
pub dynasty: u64, pub recently_changed: bool,
pub slot: u64,
pub hash: Hash256, pub hash: Hash256,
} }
@ -10,7 +11,8 @@ impl CrosslinkRecord {
/// Generates a new instance where `dynasty` and `hash` are both zero. /// Generates a new instance where `dynasty` and `hash` are both zero.
pub fn zero() -> Self { pub fn zero() -> Self {
Self { Self {
dynasty: 0, recently_changed: false,
slot: 0,
hash: Hash256::zero(), hash: Hash256::zero(),
} }
} }
@ -23,7 +25,8 @@ mod tests {
#[test] #[test]
fn test_crosslink_record_zero() { fn test_crosslink_record_zero() {
let c = CrosslinkRecord::zero(); let c = CrosslinkRecord::zero();
assert_eq!(c.dynasty, 0); assert_eq!(c.recently_changed, false);
assert_eq!(c.slot, 0);
assert!(c.hash.is_zero()); assert!(c.hash.is_zero());
} }
} }

View File

@ -1,65 +1,21 @@
use super::validator_record::ValidatorRecord; use super::validator_record::ValidatorRecord;
use super::crosslink_record::CrosslinkRecord; use super::crosslink_record::CrosslinkRecord;
use super::shard_and_committee::ShardAndCommittee; use super::shard_and_committee::ShardAndCommittee;
use super::ethereum_types::U256;
use super::Hash256; use super::Hash256;
pub struct CrystallizedState { pub struct CrystallizedState {
pub validator_set_change_slot: u64,
pub validators: Vec<ValidatorRecord>, pub validators: Vec<ValidatorRecord>,
pub epoch_number: u64, pub crosslinks: Vec<CrosslinkRecord>,
pub indicies_for_heights: Vec<ShardAndCommittee>, pub last_state_recalculation_slot: u64,
pub last_justified_slot: u64,
pub justified_streak: u16,
pub last_finalized_slot: u64, pub last_finalized_slot: u64,
pub current_dynasty: u64, pub last_justified_slot: u64,
pub crosslinking_shard_start: u16, pub justified_streak: u64,
pub crosslink_records: Vec<CrosslinkRecord>, pub shard_and_committee_for_slots: Vec<Vec<ShardAndCommittee>>,
pub total_deposits: U256, pub deposits_penalized_in_period: u32,
pub dynasty_seed: Hash256, pub validator_set_delta_hash_chain: Hash256,
pub dynasty_seed_last_reset: u64, pub pre_fork_version: u32,
} pub post_fork_version: u32,
pub fork_slot_number: u32,
impl CrystallizedState {
/// Returns a new instance where all fields are either zero or an
/// empty vector.
pub fn zero() -> Self {
Self {
validators: vec![],
epoch_number: 0,
indicies_for_heights: vec![],
last_justified_slot: 0,
justified_streak: 0,
last_finalized_slot: 0,
current_dynasty: 0,
crosslinking_shard_start: 0,
crosslink_records: vec![],
total_deposits: U256::zero(),
dynasty_seed: Hash256::zero(),
dynasty_seed_last_reset: 0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cry_state_zero() {
let c = CrystallizedState::zero();
assert_eq!(c.validators.len(), 0);
assert_eq!(c.epoch_number, 0);
assert_eq!(c.indicies_for_heights.len(), 0);
assert_eq!(c.last_justified_slot, 0);
assert_eq!(c.justified_streak, 0);
assert_eq!(c.last_finalized_slot, 0);
assert_eq!(c.current_dynasty, 0);
assert_eq!(c.crosslinking_shard_start, 0);
assert_eq!(c.crosslink_records.len(), 0);
assert!(c.total_deposits.is_zero());
assert!(c.dynasty_seed.is_zero());
assert_eq!(c.dynasty_seed_last_reset, 0);
}
} }