Split the Roles in three types (#5520)

* Split the Roles bitfield in three

* Forgot to include some changes

* Fix cli test

* More test fixes

* Oh God, merging master broke other tests

* Didn't run the doctests

* Address review

* I'm trying to fix the build blindly because it's taking a good hour to compile on my machine

* Address some review

* Also update the peerset's API to make sense

* Fix peerset tests

* Fix browser node

* client: distinguish between local and network authority

Co-authored-by: André Silva <andre.beat@gmail.com>
This commit is contained in:
Pierre Krieger
2020-04-03 19:08:14 +02:00
committed by GitHub
parent 9dbcb11f66
commit 8c03a4fcef
44 changed files with 591 additions and 432 deletions
+10 -13
View File
@@ -32,7 +32,7 @@ use sp_blockchain::{
use sc_client_api::{BlockchainEvents, BlockImportNotification, FinalityNotifications, ImportNotifications, FinalityNotification, backend::{TransactionFor, AuxStore, Backend, Finalizer}, BlockBackend};
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
use sc_client::LongestChain;
use sc_network::config::Roles;
use sc_network::config::Role;
use sp_consensus::block_validation::DefaultBlockAnnounceValidator;
use sp_consensus::import_queue::{
BasicQueue, BoxJustificationImport, Verifier, BoxFinalityProofImport,
@@ -557,17 +557,17 @@ pub trait TestNetFactory: Sized {
for i in 0..n {
trace!(target: "test_network", "Adding peer {}", i);
net.add_full_peer(&config);
net.add_full_peer();
}
net
}
fn add_full_peer(&mut self, config: &ProtocolConfig) {
self.add_full_peer_with_states(config, None)
fn add_full_peer(&mut self) {
self.add_full_peer_with_states(None)
}
/// Add a full peer.
fn add_full_peer_with_states(&mut self, config: &ProtocolConfig, keep_blocks: Option<u32>) {
fn add_full_peer_with_states(&mut self, keep_blocks: Option<u32>) {
let test_client_builder = match keep_blocks {
Some(keep_blocks) => TestClientBuilder::with_pruning_window(keep_blocks),
None => TestClientBuilder::with_default_backend(),
@@ -586,7 +586,7 @@ pub trait TestNetFactory: Sized {
let verifier = self.make_verifier(
PeersClient::Full(client.clone(), backend.clone()),
config,
&Default::default(),
&data,
);
let verifier = VerifierAdapter::new(Arc::new(Mutex::new(Box::new(verifier) as Box<_>)));
@@ -601,7 +601,7 @@ pub trait TestNetFactory: Sized {
let listen_addr = build_multiaddr![Memory(rand::random::<u64>())];
let network = NetworkWorker::new(sc_network::config::Params {
roles: config.roles,
role: Role::Full,
executor: None,
network_config: NetworkConfiguration {
listen_addresses: vec![listen_addr.clone()],
@@ -644,10 +644,7 @@ pub trait TestNetFactory: Sized {
}
/// Add a light peer.
fn add_light_peer(&mut self, config: &ProtocolConfig) {
let mut config = config.clone();
config.roles = Roles::LIGHT;
fn add_light_peer(&mut self) {
let (c, backend) = substrate_test_runtime_client::new_light();
let client = Arc::new(c);
let (
@@ -660,7 +657,7 @@ pub trait TestNetFactory: Sized {
let verifier = self.make_verifier(
PeersClient::Light(client.clone(), backend.clone()),
&config,
&Default::default(),
&data,
);
let verifier = VerifierAdapter::new(Arc::new(Mutex::new(Box::new(verifier) as Box<_>)));
@@ -675,7 +672,7 @@ pub trait TestNetFactory: Sized {
let listen_addr = build_multiaddr![Memory(rand::random::<u64>())];
let network = NetworkWorker::new(sc_network::config::Params {
roles: config.roles,
role: Role::Light,
executor: None,
network_config: NetworkConfiguration {
listen_addresses: vec![listen_addr.clone()],
+8 -12
View File
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use sc_network::config::Roles;
use sp_consensus::BlockOrigin;
use std::time::Duration;
use futures::executor::block_on;
@@ -372,10 +371,8 @@ fn blocks_are_not_announced_by_light_nodes() {
// full peer0 is connected to light peer
// light peer1 is connected to full peer2
let mut light_config = ProtocolConfig::default();
light_config.roles = Roles::LIGHT;
net.add_full_peer(&ProtocolConfig::default());
net.add_light_peer(&light_config);
net.add_full_peer();
net.add_light_peer();
// Sync between 0 and 1.
net.peer(0).push_blocks(1, false);
@@ -384,7 +381,7 @@ fn blocks_are_not_announced_by_light_nodes() {
assert_eq!(net.peer(1).client.info().best_number, 1);
// Add another node and remove node 0.
net.add_full_peer(&ProtocolConfig::default());
net.add_full_peer();
net.peers.remove(0);
// Poll for a few seconds and make sure 1 and 2 (now 0 and 1) don't sync together.
@@ -465,7 +462,7 @@ fn can_not_sync_from_light_peer() {
// given the network with 1 full nodes (#0) and 1 light node (#1)
let mut net = TestNet::new(1);
net.add_light_peer(&Default::default());
net.add_light_peer();
// generate some blocks on #0
net.peer(0).push_blocks(1, false);
@@ -481,7 +478,7 @@ fn can_not_sync_from_light_peer() {
assert_eq!(light_info.best_hash, full0_info.best_hash);
// add new full client (#2) && remove #0
net.add_full_peer(&Default::default());
net.add_full_peer();
net.peers.remove(0);
// ensure that the #2 (now #1) fails to sync block #1 even after 5 seconds
@@ -511,7 +508,7 @@ fn light_peer_imports_header_from_announce() {
// given the network with 1 full nodes (#0) and 1 light node (#1)
let mut net = TestNet::new(1);
net.add_light_peer(&Default::default());
net.add_light_peer();
// let them connect to each other
net.block_until_sync();
@@ -583,9 +580,8 @@ fn can_sync_explicit_forks() {
fn syncs_header_only_forks() {
let _ = ::env_logger::try_init();
let mut net = TestNet::new(0);
let config = ProtocolConfig::default();
net.add_full_peer_with_states(&config, None);
net.add_full_peer_with_states(&config, Some(3));
net.add_full_peer_with_states(None);
net.add_full_peer_with_states(Some(3));
net.peer(0).push_blocks(2, false);
net.peer(1).push_blocks(2, false);