Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
fix: take ages into account when calculating DkgKey
Browse files Browse the repository at this point in the history
This fixes the startup node promotion
  • Loading branch information
madadam committed Oct 27, 2020
1 parent 551c427 commit 824d229
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
30 changes: 28 additions & 2 deletions src/consensus/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ impl DkgKey {
// Calculate the hash without involving serialization to avoid having to return `Result`.
let mut hasher = Sha3::v256();

for name in elders_info.elders.keys() {
hasher.update(&name.0);
for peer in elders_info.elders.values() {
hasher.update(&peer.name().0);
hasher.update(&[peer.age()]);
}

hasher.update(&elders_info.prefix.name().0);
Expand Down Expand Up @@ -377,3 +378,28 @@ struct Observer {
section_key_index: u64,
accumulator: HashMap<Result<bls::PublicKey, ()>, HashSet<XorName>>,
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{section::test_utils::gen_addr, MIN_AGE};
use std::iter;
use xor_name::Prefix;

#[test]
fn dkg_key_is_affected_by_ages() {
let name = rand::random();
let addr = gen_addr();

let peer0 = Peer::new(name, addr, MIN_AGE);
let peer1 = Peer::new(name, addr, MIN_AGE + 1);

let elders_info0 = EldersInfo::new(iter::once(peer0), Prefix::default());
let elders_info1 = EldersInfo::new(iter::once(peer1), Prefix::default());

let key0 = DkgKey::new(&elders_info0);
let key1 = DkgKey::new(&elders_info1);

assert_ne!(key0, key1);
}
}
5 changes: 1 addition & 4 deletions tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ async fn test_section_bootstrapping() -> Result<()> {

// Test that the first `ELDER_SIZE` nodes in the network are promoted to elders.
#[tokio::test]
// FIXME: this test currently fails due to a bug somewhere in the DKG logic (probably). Fix it and
// then un-ignore this test.
#[ignore]
async fn test_first_elders() -> Result<()> {
async fn test_startup_elders() -> Result<()> {
let network_params = NetworkParams::default();
let network_size = 2;
let mut nodes = create_connected_nodes(network_size, network_params).await?;
Expand Down

0 comments on commit 824d229

Please sign in to comment.