client/authority-discovery: Introduce AuthorityDiscoveryService (#6760)

* client/authority-discovery: Rename AuthorityDiscovery to XXXWorker

* client/authority-discovery: Introduce AuthorityDiscoveryService

Add a basic `AuthorityDiscoveryService` implementation which enables
callers to get the addresses for a given `AuthorityId` from the local
cache.

* client/authority-discovery: Split into worker and service mod

Move `Service` and `Worker` to their own Rust modules resulting in the
following file structure.

├── build.rs
├── Cargo.toml
└── src
    ├── error.rs
    ├── lib.rs
    ├── service.rs
    ├── tests.rs
    ├── worker
    │   ├── addr_cache.rs
    │   ├── schema
    │   │   └── dht.proto
    │   └── tests.rs
    └── worker.rs

* client/authority-discovery: Cache PeerId -> AuthorityId mapping

* client/authority-discovery: Update priority group on interval

Instead of updating the authority discovery peerset priority group each
time a new DHT value is found, update it regularly on an interval.

This removes the need for deterministic random selection. Instead of
trying to return a random stable set of `Multiaddr`s, the `AddrCache`
now returns a random set on each call.

* client/authority-discovery: Implement Service::get_authority_id

* client/authority-discovery: Use HashMap instead of BTreeMap

* client/authority-discovery: Rework priority group interval

* client/authority-discovery: Fix comment

* bin/node/cli: Update authority discovery constructor

* client/authority-discovery: Fuse from_service receiver

* client/authority-discovery: Remove Rng import

* client/authority-discovery: Ignore Multiaddr without PeerId

* client/authority-discovery/service: Add note on returned None

* client/authority-discovery/addr_cache: Replace double clone with deref
This commit is contained in:
Max Inden
2020-08-12 16:16:40 +02:00
committed by GitHub
parent 93612c11f4
commit 2d5ec72331
10 changed files with 1846 additions and 1398 deletions
+2 -2
View File
@@ -266,7 +266,7 @@ pub fn new_full_base(
Event::Dht(e) => Some(e),
_ => None,
}}).boxed();
let authority_discovery = sc_authority_discovery::AuthorityDiscovery::new(
let (authority_discovery_worker, _service) = sc_authority_discovery::new_worker_and_service(
client.clone(),
network.clone(),
sentries,
@@ -275,7 +275,7 @@ pub fn new_full_base(
prometheus_registry.clone(),
);
task_manager.spawn_handle().spawn("authority-discovery", authority_discovery);
task_manager.spawn_handle().spawn("authority-discovery-worker", authority_discovery_worker);
}
// if the node isn't actively participating in consensus then it doesn't