Skip to content

Commit

Permalink
client/authority-discovery: Introduce AuthorityDiscoveryService (pari…
Browse files Browse the repository at this point in the history
…tytech#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
  • Loading branch information
mxinden authored Aug 12, 2020
1 parent c495f89 commit 473a23f
Show file tree
Hide file tree
Showing 10 changed files with 1,844 additions and 1,396 deletions.
4 changes: 2 additions & 2 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/authority-discovery/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
prost_build::compile_protos(&["src/schema/dht.proto"], &["src/schema"]).unwrap();
prost_build::compile_protos(&["src/worker/schema/dht.proto"], &["src/worker/schema"]).unwrap();
}
205 changes: 0 additions & 205 deletions client/authority-discovery/src/addr_cache.rs

This file was deleted.

Loading

0 comments on commit 473a23f

Please sign in to comment.