Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
hash randomness
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian committed Jun 17, 2021
1 parent e5c604f commit 24befd1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions node/network/gossip-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }

polkadot-node-network-protocol = { path = "../protocol" }
polkadot-node-subsystem = { path = "../../subsystem" }
Expand Down
8 changes: 6 additions & 2 deletions node/network/gossip-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async fn connect_to_authorities(
/// and form a matrix where each validator is connected to all validators in its row and column.
/// This is similar to [web3] research proposed topology, except for the groups are not parachain
/// groups (because not all validators are parachain validators and the group size is small),
/// but formed randomly via BABE randomness from the previous epoch.
/// but formed randomly via BABE randomness from two epochs ago.
/// This limits the amount of gossip peers to 2 * sqrt(len) and ensures the diameter of 2.
///
/// [web3]: https://research.web3.foundation/en/latest/polkadot/networking/3-avail-valid.html#topology
Expand All @@ -191,7 +191,11 @@ async fn update_gossip_topology(
RuntimeApiRequest::CurrentBabeEpoch(tx),
).into()).await;

rx.await??.randomness
let randomness = rx.await??.randomness;
let mut subject = [0u8; 40];
subject[..8].copy_from_slice(b"gossipsu");
subject[8..].copy_from_slice(&randomness);
sp_core::blake2_256(&subject)
};

// shuffle the indices
Expand Down
4 changes: 2 additions & 2 deletions node/network/gossip-support/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ fn authorities() -> Vec<AuthorityDiscoveryId> {

fn neighbors() -> Vec<AuthorityDiscoveryId> {
vec![
Sr25519Keyring::Bob.public().into(),
Sr25519Keyring::Charlie.public().into(),
Sr25519Keyring::One.public().into(),
Sr25519Keyring::Alice.public().into(),
Sr25519Keyring::Eve.public().into(),
]
}

Expand Down

0 comments on commit 24befd1

Please sign in to comment.