Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[WIP] Enable validators to find and connect to other validators #3247

Closed
wants to merge 11 commits into from

Conversation

mxinden
Copy link
Contributor

@mxinden mxinden commented Jul 30, 2019

The goal of this pull request is to enable Substrate validators to directly connect to other validators. With this pull request a validator does two things:

  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 validators

    1. Retrieve the current set of authorities (currently only consensus, not finality)
    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

The first point Making itself discoverable fixes #3247.

Pull request status:

Work in progress

To do:

  • Code style, especially function complexity through indentation
  • Error handling / logging
  • Authority key retrieval abstraction (Supporting hot-swappable crypto-primitive changes)
  • Redo commit history (before removing [WIP] tag)

Instead of building the network future via an independent function
`build_network_future`, follow the convention introduced through
`components.rs/OffchainWorker` and have `build_network_future` implement
a trait.
The runtime SessionApi enables users to retrieve the ids of the current
set of validators from the srml session module.
For a node to be able to learn its own authority id (public key) and to
be able to sign payloads for the DHT, the node needs to retrieve its
authority key. This is done via AuthorityKeyProvider.
The goal of the commit is to be able to retrieve the current set of
authorities without needing to know the concrete consensus mechanism in
place.

In order to achieve the above this commit introduces the
`core/consensus/common/primitives` crate, declaring the `ConsensusApi`
runtime API. In addition it implements the above mentioned trait
definition in `node/runtime` by returning the current authorities of the
BABE consensus mechanism.
When retrieving addresses of other validators via the DHT, make sure
they are within the current validator set and the payload is properly
signed with the authority key.
@mxinden mxinden added A3-in_progress Pull request is in progress. No review needed at this stage. I9-optimisation An enhancement to provide better overall performance in terms of time-to-completion for a task. M4-core labels Jul 30, 2019
@arkpar
Copy link
Member

arkpar commented Jul 30, 2019

This should use set_priority_group peerset API

@mxinden
Copy link
Contributor Author

mxinden commented Aug 7, 2019

Status: Waiting for #3296 as this pull request requires retrieving the current authority key.

@gavofyork gavofyork removed the I9-optimisation An enhancement to provide better overall performance in terms of time-to-completion for a task. label Aug 8, 2019
Copy link
Contributor

@andresilva andresilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick review.

status_sinks.lock().retain(|sink| sink.unbounded_send((status.clone(), state.clone())).is_ok());
}

let authorities = client.runtime_api().authorities(&BlockId::hash(client.info().chain.best_hash));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For GRANDPA we need to check the active authority set from the node state and not the runtime, it is tracked here. Maybe we can just pass a Fn() -> Vec<Authority> into this function and then build up the authorities externally (babe authorities + grandpa authorities).

@mxinden
Copy link
Contributor Author

mxinden commented Aug 21, 2019

Replaced by #3452.

@mxinden mxinden closed this Aug 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A3-in_progress Pull request is in progress. No review needed at this stage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants