Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(design): Authority Discovery design #4577

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

timwu20
Copy link
Contributor

@timwu20 timwu20 commented Feb 26, 2025

Changes

  • Design for Authority Design component

Issues

@timwu20 timwu20 marked this pull request as ready for review February 26, 2025 21:40
@timwu20 timwu20 requested a review from P1sar as a code owner February 26, 2025 21:40
- 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`
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we can skip Role::Discover since it is only for collators, cumulus and other occasions where software is not an authority, which is not a case for Gossamer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section describes behaviour that needs to be run whether or not the node is an authority or not. It still needs to fetch and validate DHT requests based on the authority records.


The [`AuthorityDiscovery`] trait contains only two methods: `authorities` and `best_hash`.

The `authorities` is the same method found in [`ProvideRuntimeApi`] trait, implying a runtime call is expected to be made to get the authorities at a given block hash.
Copy link
Member

Choose a reason for hiding this comment

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

As I understood we would need to implement this host function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already have this host function.


#### Implementing `NetworkDhtProvider` and `DhtEventStream`

I believe will we need to fork `go-libp2p-kad-dht` or look for viable alternatives DHT packages to support the `put_record_to` functionality as well emit the `DhtEvent` variants from the package itself. Without this functionality we will not be able to run the Substrate Authority Discovery protocol as expected by Substrate based nodes.
Copy link
Member

Choose a reason for hiding this comment

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

I have concerns regarding forking. put_record_to can be implemented on our side by wrapping original interface.
Regarding events I have a feeling they do not have rather because of different architectures. Moreover I checked handle_dht_event function (not sure if it is explicit) but it is mostly about metrics and though we would need them, I beleive we have control over whole events that happening, eg ValuePut, ValueNotFound are just resutls of the operations that we do, hence I we really need to have vent based architecture we can also wrap kad-dht-go with our implementation and add events streaming on top of each action

Copy link
Contributor Author

@timwu20 timwu20 Feb 27, 2025

Choose a reason for hiding this comment

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

I have concerns regarding forking. put_record_to can be implemented on our side by wrapping original interface.

I'm not sure if we can replicate the put_record_to functionality without forking the repo. If we look at the IpfsDHT type, all the attributes are private, so we wouldn't necessarily be able to extend it. There may be a possibility where we expose certain attributes of IpfsDHT through receiver methods, and add the put_record_to functionality on a type that embeds IpfsDHT and extends it. When I create the issue to investigate implementing put_record_to to, we should consider all options that mitigate the need to maintain a fork.

Regarding events I have a feeling they do not have rather because of different architectures. Moreover I checked handle_dht_event function (not sure if it is explicit) but it is mostly about metrics and though we would need them, I beleive we have control over whole events that happening, eg ValuePut, ValueNotFound are just resutls of the operations that we do, hence I we really need to have vent based architecture we can also wrap kad-dht-go with our implementation and add events streaming on top of each action

There is quite a bit of business logic related to the ValueFound event which calls handle_dht_value_found_event. handle_put_record_requested is called from handling PutRecordRequest event, which also contains quite a bit of business logic. I agree we should attempt to wrap IpfsDHT first to emit these events instead of completely forking it. I'll mention this in a design issue to implement our own version of DhtEventStream.

Copy link
Member

Choose a reason for hiding this comment

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

I also was reveiwing GossipEnginer and I only see that DHTEvents are defined within substrate not within the libp2p, or am I missing something?

Copy link
Contributor Author

@timwu20 timwu20 Feb 27, 2025

Choose a reason for hiding this comment

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

Their DHT produces errors that are translated through an intermediary DiscoveryOut enum to eventually become DhtEvent. libp2p::kad::GetRecordError -> DiscoveryOut::ValueNotFound -> DhtEvent::ValueNotFound see https://github.com/paritytech/polkadot-sdk/blob/c88128832f95bb916c8b1b5eb45a34bf78ec998a/substrate/client/network/src/discovery.rs#L987

@timwu20 timwu20 requested a review from P1sar March 1, 2025 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Authority Discovery design
2 participants