From 24befd12073bfcaeed54825cab4b408d25c5faf9 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Thu, 17 Jun 2021 21:37:38 +0200 Subject: [PATCH] hash randomness --- node/network/gossip-support/Cargo.toml | 1 + node/network/gossip-support/src/lib.rs | 8 ++++++-- node/network/gossip-support/src/tests.rs | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/node/network/gossip-support/Cargo.toml b/node/network/gossip-support/Cargo.toml index 42751909eea2..bd223e6e7c8b 100644 --- a/node/network/gossip-support/Cargo.toml +++ b/node/network/gossip-support/Cargo.toml @@ -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" } diff --git a/node/network/gossip-support/src/lib.rs b/node/network/gossip-support/src/lib.rs index 32016ee2fc74..5f0564b6d025 100644 --- a/node/network/gossip-support/src/lib.rs +++ b/node/network/gossip-support/src/lib.rs @@ -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 @@ -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 diff --git a/node/network/gossip-support/src/tests.rs b/node/network/gossip-support/src/tests.rs index 2944936dfb2d..7f96f4caf7ac 100644 --- a/node/network/gossip-support/src/tests.rs +++ b/node/network/gossip-support/src/tests.rs @@ -122,9 +122,9 @@ fn authorities() -> Vec { fn neighbors() -> Vec { vec![ - Sr25519Keyring::Bob.public().into(), - Sr25519Keyring::Charlie.public().into(), Sr25519Keyring::One.public().into(), + Sr25519Keyring::Alice.public().into(), + Sr25519Keyring::Eve.public().into(), ] }