Skip to content

Commit

Permalink
fix(core)!: sort validate set by shard key (#4952)
Browse files Browse the repository at this point in the history
Description
---
Sorts VN set by shard id before returning it

Motivation and Context
---
Ref tari-project/rfcs#73

How Has This Been Tested?
---
Tests updated
  • Loading branch information
sdbondi authored Nov 24, 2022
1 parent 3021c1e commit 349d429
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ impl<'a, Txn: Deref<Target = ConstTransaction<'a>>> ValidatorNodeStore<'a, Txn>
i += 1;
}

Ok(nodes.into_iter().flatten().collect())
let mut vn_set = nodes.into_iter().flatten().collect::<Vec<_>>();
vn_set.sort_by(|(_, a), (_, b)| a.cmp(b));
Ok(vn_set)
}

pub fn get_shard_key(
Expand Down Expand Up @@ -259,6 +261,7 @@ mod tests {
.unwrap();
nodes.push((public_key, shard_key));
}
nodes.sort_by(|(_, a), (_, b)| a.cmp(b));
nodes
}

Expand Down Expand Up @@ -345,9 +348,8 @@ mod tests {

let set = store.get_vn_set(1, 5).unwrap();
// s1 and s2 have replaced the previous shard keys, and are now ordered last since they come after node2
assert_eq!(set[0], nodes[2]);
assert_eq!(set[1], (nodes[0].0.clone(), s0));
assert_eq!(set[2], (nodes[1].0.clone(), make_hash(s1)));
assert_eq!(set.len(), 3);
assert_eq!(set.iter().filter(|s| s.0 == nodes[1].0).count(), 1);
}
}

Expand Down

0 comments on commit 349d429

Please sign in to comment.