ChainSafe / ChainSafe/gossamer

`Worker` implementation

Open
#4,622 0 comments 0 reactions 1 assignee Claimed by @freddyli7 View on GitHub
Dominant language
Go
Stars
454
Forks
144
PR merge metrics
No merged PRs in 30d

Description

## From design doc:
## `Worker`

An authority discovery [`Worker`] can publish the local node's addresses as well as discover
those of other nodes via a [Kademlia DHT](https://pl-launchpad.io/curriculum/libp2p/dht/).

When constructing the worker via constructor, we can specify the [`Role`]. The [`Role`] enum has two values: `PublishAndDiscover` and `Discover`.

### `Role::PublishAndDiscover`

If the worker is constructed with the `PublishAndDiscover` role, it will
- Retrieve its external addresses (including peer id).
- Get the list of keys owned by the local node participating in the current authority set.
- Sign the addresses with the keys.
- Put addresses and signature as a record with the authority id as a key on the Kademlia DHT.

### `Role::Discover`

If the worker is constructed with either `PublishAndDiscover` or `Discover` role, it will:
- Retrieve the current and next set of authorities.
- Start DHT queries for the ids of the authorities.
- Validate the signatures of the retrieved key value pairs.
- Add the retrieved external addresses as priority nodes to the network peerset.
- Allow querying of the collected addresses via the accompanying [`Service`].

## Acceptance Criteria
- Implement `Worker` utilizing dependencies
- Support `Service` pattern. Graceful shutdown.
- Unit tests

[`Worker`]:https://github.com/paritytech/polkadot-sdk/blob/4b054c60b1641612ef0a76dcc75eed5dd23a18cf/substrate/client/authority-discovery/src/worker.rs#L233
[`Service`]:https://github.com/paritytech/polkadot-sdk/blob/414a8fc2eda3bb72e30cefdba628cf6c361cd6e1/substrate/client/authority-discovery/src/service.rs#L34
[`Role`]:https://github.com/paritytech/polkadot-sdk/blob/4b054c60b1641612ef0a76dcc75eed5dd23a18cf/substrate/client/authority-discovery/src/worker.rs#L86
[`AuthorityDiscovery`]:https://github.com/paritytech/polkadot-sdk/blob/4b054c60b1641612ef0a76dcc75eed5dd23a18cf/substrate/client/authority-discovery/src/worker.rs#L205
[`ProvideRuntimeApi`]:https://github.com/paritytech/polkadot-sdk/blob/c5444f381fdba68aa9cb73b39cc63f34604da156/substrate/primitives/api/src/lib.rs#L750
[`HeaderBackend`]:https://github.com/paritytech/polkadot-sdk/blob/fdb4554e26ebdd4d729158501a3ddb3c6ebdfb6f/substrate/primitives/blockchain/src/backend.rs#L37
[`NetworkProvider`]:https://github.com/paritytech/polkadot-sdk/blob/4b054c60b1641612ef0a76dcc75eed5dd23a18cf/substrate/client/authority-discovery/src/worker.rs#L1029
[`DhtEvent`]:https://github.com/paritytech/polkadot-sdk/blob/4b054c60b1641612ef0a76dcc75eed5dd23a18cf/substrate/client/network/src/event.rs#L35
[`Service`]:https://github.com/paritytech/polkadot-sdk/blob/414a8fc2eda3bb72e30cefdba628cf6c361cd6e1/substrate/client/authority-discovery/src/service.rs#L34
[`ServicetoWorkerMessage`]:https://github.com/paritytech/polkadot-sdk/blob/80616f6d03661106326b621e9cc3ee1d2fa283ed/substrate/client/authority-discovery/src/lib.rs#L168

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.