mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 23:01:01 +00:00
core/authority-discovery: Enable authorities to discover each other (#3452)
With the *authority-discovery* module an authoritative node makes itself
discoverable and is able to discover other authorities. Once discovered, a node
can directly connect to other authorities instead of multi-hop gossiping
information.
1. **Making itself discoverable**
1. Retrieve its external addresses
2. Adds its network peer id to the addresses
3. Sign the above
4. Put the signature and the addresses on the libp2p Kademlia DHT
2. **Discovering other authorities**
1. Retrieve the current set of authorities
2. Start DHT queries for the ids of the authorities
3. Validate the signatures of the retrieved key value pairs
4. Add the retrieved external addresses as ~reserved~ priority nodes to the
peerset
* node/runtime: Add authority-discovery as session handler
The srml/authority-discovery module implements the OneSessionHandler in
order to keep its authority set in sync. This commit adds the module to
the set of session handlers.
* core/network: Make network worker return Dht events on poll
Instead of network worker implement the Future trait, have it implement
the Stream interface returning Dht events.
For now these events are ignored in build_network_future but will be
used by the core/authority-discovery module in subsequent commits.
* *: Add scaffolding and integration for core/authority-discovery module
* core/authority-discovery: Implement module logic itself
This commit is contained in:
@@ -19,9 +19,15 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use client::decl_runtime_apis;
|
||||
use codec::Codec;
|
||||
use rstd::vec::Vec;
|
||||
|
||||
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Hash))]
|
||||
pub struct Signature(pub Vec<u8>);
|
||||
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Hash))]
|
||||
pub struct AuthorityId(pub Vec<u8>);
|
||||
|
||||
decl_runtime_apis! {
|
||||
/// The authority discovery api.
|
||||
///
|
||||
@@ -29,21 +35,15 @@ decl_runtime_apis! {
|
||||
/// own authority identifier, to retrieve identifiers of the current authority
|
||||
/// set, as well as sign and verify Kademlia Dht external address payloads
|
||||
/// from and to other authorities.
|
||||
pub trait AuthorityDiscoveryApi<AuthorityId: Codec> {
|
||||
/// Returns own authority identifier iff it is part of the current authority
|
||||
/// set, otherwise this function returns None. The restriction might be
|
||||
/// softened in the future in case a consumer needs to learn own authority
|
||||
/// identifier.
|
||||
fn authority_id() -> Option<AuthorityId>;
|
||||
|
||||
pub trait AuthorityDiscoveryApi {
|
||||
/// Retrieve authority identifiers of the current authority set.
|
||||
fn authorities() -> Vec<AuthorityId>;
|
||||
|
||||
/// Sign the given payload with the private key corresponding to the given authority id.
|
||||
fn sign(payload: Vec<u8>, authority_id: AuthorityId) -> Option<Vec<u8>>;
|
||||
fn sign(payload: &Vec<u8>) -> Option<(Signature, AuthorityId)>;
|
||||
|
||||
/// Verify the given signature for the given payload with the given
|
||||
/// authority identifier.
|
||||
fn verify(payload: Vec<u8>, signature: Vec<u8>, authority_id: AuthorityId) -> bool;
|
||||
fn verify(payload: &Vec<u8>, signature: &Signature, authority_id: &AuthorityId) -> bool;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user