Update ShardAndCommittee per new spec
- `shard_id` -> `shard`
This commit is contained in:
parent
42e774cb48
commit
0536fb4a91
@ -1,6 +1,6 @@
|
|||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct ShardAndCommittee {
|
pub struct ShardAndCommittee {
|
||||||
pub shard_id: u16,
|
pub shard: u16,
|
||||||
pub committee: Vec<usize>
|
pub committee: Vec<usize>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ impl ShardAndCommittee {
|
|||||||
/// committee is an empty vector.
|
/// committee is an empty vector.
|
||||||
pub fn zero() -> Self {
|
pub fn zero() -> Self {
|
||||||
Self {
|
Self {
|
||||||
shard_id: 0,
|
shard: 0,
|
||||||
committee: vec![],
|
committee: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22,7 +22,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_shard_and_committee_zero() {
|
fn test_shard_and_committee_zero() {
|
||||||
let s = ShardAndCommittee::zero();
|
let s = ShardAndCommittee::zero();
|
||||||
assert_eq!(s.shard_id, 0);
|
assert_eq!(s.shard, 0);
|
||||||
assert_eq!(s.committee.len(), 0);
|
assert_eq!(s.committee.len(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,12 +86,12 @@ fn generate_cycle(
|
|||||||
let cycle = validator_indices.honey_badger_split(cycle_length)
|
let cycle = validator_indices.honey_badger_split(cycle_length)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, slot_indices)| {
|
.map(|(i, slot_indices)| {
|
||||||
let shard_id_start = crosslinking_shard_start + i * committees_per_slot / slots_per_committee;
|
let shard_start = crosslinking_shard_start + i * committees_per_slot / slots_per_committee;
|
||||||
slot_indices.honey_badger_split(committees_per_slot)
|
slot_indices.honey_badger_split(committees_per_slot)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(j, shard_indices)| {
|
.map(|(j, shard_indices)| {
|
||||||
ShardAndCommittee{
|
ShardAndCommittee{
|
||||||
shard_id: ((shard_id_start + j) % shard_count) as u16,
|
shard: ((shard_start + j) % shard_count) as u16,
|
||||||
committee: shard_indices.to_vec(),
|
committee: shard_indices.to_vec(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -141,8 +141,8 @@ mod tests {
|
|||||||
slot.iter()
|
slot.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.for_each(|(i, sac)| {
|
.for_each(|(i, sac)| {
|
||||||
println!("#{:?}\tshard_id={}\tcommittee.len()={}",
|
println!("#{:?}\tshard={}\tcommittee.len()={}",
|
||||||
&i, &sac.shard_id, &sac.committee.len())
|
&i, &sac.shard, &sac.committee.len())
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ mod tests {
|
|||||||
let mut flattened = vec![];
|
let mut flattened = vec![];
|
||||||
for slot in cycle.iter() {
|
for slot in cycle.iter() {
|
||||||
for sac in slot.iter() {
|
for sac in slot.iter() {
|
||||||
flattened.push(sac.shard_id as usize);
|
flattened.push(sac.shard as usize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flattened.dedup();
|
flattened.dedup();
|
||||||
@ -181,7 +181,7 @@ mod tests {
|
|||||||
for slot in cycle.iter() {
|
for slot in cycle.iter() {
|
||||||
let mut shards: Vec<usize> = vec![];
|
let mut shards: Vec<usize> = vec![];
|
||||||
for sac in slot.iter() {
|
for sac in slot.iter() {
|
||||||
shards.push(sac.shard_id as usize);
|
shards.push(sac.shard as usize);
|
||||||
}
|
}
|
||||||
shards_in_slots.push(shards);
|
shards_in_slots.push(shards);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user