paritytech / substrate

Substrate: The platform for blockchain innovators
Apache License 2.0
8.39k stars 2.65k forks source link

Cannot resolve bootnodes' libp2p multiaddr(`/dnsaddr`) in chainspec #11857

Open shunsukew opened 2 years ago

shunsukew commented 2 years ago

Is there an existing issue?

Experiencing problems? Have you tried our Stack Exchange first?

Description of bug

libp2p supports /dnsaddr multiaddr(s) by looking up TXT records in DNS. https://github.com/multiformats/multiaddr/blob/master/protocols/DNSADDR.md I assumed that https://github.com/paritytech/substrate/issues/7811 made it possible to use multiaddr. However, Substrate returns errors when /dnsaddr is defined in chainspec's bootnodes list.

Error: Input("Error parsing spec file: Peer id is missing from the address at line 7 column 3")

Steps to reproduce

  1. Register TXT record _dnsaddr.{domain name} and value is dnsaddr=/ip4/{ip address}/tcp/30333/p2p/{parachain node identity}

  2. Make sure libp2p-lookup works

    $ libp2p-lookup direct --address /dnsaddr/{domain name}
    Lookup for peer with id PeerId("{Actual Peer Identity}") succeeded.
    ...
  3. Add /dnsaddr to raw chain spec json

    {
    "bootNodes": [
        "/dnsaddr/{domain name}"
    ],
    ...
  4. Pass json file to Substrate --chain args

bkchr commented 2 years ago

We have the custom MultiaddrWithPeerId in Substrate. This requires that you have a multi-address that has a peer id attached. A lot of our code currently "requires" that we already know the peer id. We would probably need to change the code to first resolve the peer ids. However, I don't know how to do this actually. @kpp @tomaka do you maybe know if we can resolve a multiaddr that starts with dnsaddr to some "normal" multiaddr? (I mean it is done somewhere in libp2p, I just don't know how complicated it is to do this from the outside)

kpp commented 2 years ago

This is an expected behavior. There could be multiple records associated with the provided dnsaddr, section #suffix-matching says how to match against peer id in order to get the right record. Even ipfs has to specify p2p|ipfs peer id in their list of bootstrap nodes.

@bkchr do we need a different approach? Something like resolve -> get list of nodes -> add to bootstrap list?

bkchr commented 2 years ago

@bkchr do we need a different approach? Something like resolve -> get list of nodes -> add to bootstrap list?

Sounds correct to me.