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

[Merged by Bors] - p2p: enable dht based disovery #4736

Closed
wants to merge 29 commits into from

Conversation

dshulyak
Copy link
Contributor

@dshulyak dshulyak commented Jul 21, 2023

this makes use of "native" libp2p discovery by enabling kad dht, peers exchange (adjusting score) and relay servers. the primary reason is to benefit from hole punching and multiple transports support (quic, webrtc).

in general peers will be obtained by one of the following methods:

  • getting more peers from dht. in order for peer to be added to public dht it needs to have dialable address and advertise it to the neighbors. this is pretty much analogous to our current setup, but it also supports multiple addresses so we can enable quic in next change. as it is udp based it may work on nat/firewall devices where tcp was restricted.
  • peer exchange (as a part of gossipsub) will advertise peers to other nodes as part of PRUNE message, once other node sees relayed address it will initiate holepunch. if peer is not publicly dialable it will request relay reservation from the bootnodes. once received this reservation will be communicated to bootnode as one of the peer addresses.
  • additionally we will persist peers in p2p/connected.txt every 30minutes, and try to reconnect with them on startup to decrease load on bootnodes/relays.

configuration changes:

  • p2p-bootnode option needs to be set explicitly on bootnodes in order to start dht in server mode, and adjust gossipsub configuration
  • p2p-reachability can be either public or private. we have to set public on bootnodes, otherwise autonat might be confused by out setup, beside that it is only useful for testing.
  • p2p-holepunching will enable relay client and holepunching. enabled by default
  • p2p-disable-legacy-discovery disables our own discovery. it can be run in parallel, but we will have no reason to keep it if all works as expected
  • p2p-private-network disables dht filtering by public address, it is mostly useful for testing
  • relay-server section:
    • enable enable relay server, has to be enabled on bootnodes
    • reservations number of relay reservations, 512 by default
    • ttl reservation ttl, 20 minutes

example of the p2p config section:

"p2p": {
        "listen": "/ip4/0.0.0.0/tcp/5000",
        "p2p-disable-legacy-discovery": true,
        "relay-server": {
            "enable": "true"
        },
        "p2p-reachability": "public",
        "p2p-bootnode": true,
}

@dshulyak
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jul 21, 2023
@dshulyak dshulyak changed the title p2p: enable dht based disovery method p2p: enable dht based disovery Jul 21, 2023
@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Merging #4736 (07433d1) into develop (a975106) will decrease coverage by 0.3%.
The diff coverage is 58.4%.

@@            Coverage Diff            @@
##           develop   #4736     +/-   ##
=========================================
- Coverage     77.2%   77.0%   -0.3%     
=========================================
  Files          257     259      +2     
  Lines        28975   29284    +309     
=========================================
+ Hits         22377   22549    +172     
- Misses        5206    5311    +105     
- Partials      1392    1424     +32     
Files Changed Coverage Δ
p2p/host.go 35.9% <22.6%> (-8.7%) ⬇️
p2p/pubsub/pubsub.go 87.5% <25.0%> (-4.7%) ⬇️
p2p/persist.go 56.3% <56.3%> (ø)
p2p/upgrade.go 68.3% <66.0%> (-2.0%) ⬇️
p2p/dhtdiscovery/discovery.go 71.0% <71.0%> (ø)

... and 1 file with indirect coverage changes

@bors
Copy link

bors bot commented Jul 21, 2023

try

Build failed:

@dshulyak
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jul 21, 2023
@dshulyak
Copy link
Contributor Author

spacemeshos/go-spacemesh-dev:8ef576f

@bors
Copy link

bors bot commented Jul 21, 2023

try

Build failed:

@dshulyak
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jul 21, 2023
@dshulyak
Copy link
Contributor Author

dshulyak commented Jul 21, 2023

config for testing

{
    "api": {
        "grpc-public-services": [],
        "grpc-private-services": []
    },
    "p2p": {
        "listen": "/ip4/0.0.0.0/tcp/5000",
        "p2p-disable-legacy-discovery": true,
        "bootnodes": [
            "/dns4/holepunch-101-bootnode-0.spacemesh.network/tcp/5000/p2p/12D3KooWQMAAL9nkgXJgTM2psJLMbWRgZLjAxJozx7dNkKYczs2V",
            "/dns4/holepunch-101-bootnode-1.spacemesh.network/tcp/5000/p2p/12D3KooWF2bhnqsnu2UjxJGZs8KCbzvd91vnud29KaG9rzTNFH78",
            "/dns4/holepunch-101-bootnode-2.spacemesh.network/tcp/5000/p2p/12D3KooWQKosE9LZraMfFPg9QRYyKwxT4ipsar37oT6wRy8WqWos",
            "/dns4/holepunch-101-bootnode-3.spacemesh.network/tcp/5000/p2p/12D3KooWKMQ5j15x2gzfXfX7uisss7uwkPnqJyoHcfyiYfHgSo3F"
        ]
    },
    "genesis": {
        "genesis-time": "2023-07-21T17:00:00.00Z",
        "genesis-extra-data": "holepunch",
        "genesis-accounts": {}
    }
}

@bors
Copy link

bors bot commented Jul 21, 2023

try

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@dshulyak dshulyak marked this pull request as ready for review July 22, 2023 08:33
@dshulyak
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jul 31, 2023
@bors
Copy link

bors bot commented Jul 31, 2023

try

Build failed:

Copy link
Contributor

@countvonzero countvonzero left a comment

Choose a reason for hiding this comment

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

general question. when you enable legacy with dht, how do you differentiate the peers discovered via each mechanism?

p2p/dhtdiscovery/discovery.go Show resolved Hide resolved
p2p/upgrade.go Outdated Show resolved Hide resolved
@dshulyak
Copy link
Contributor Author

general question. when you enable legacy with dht, how do you differentiate the peers discovered via each mechanism?

there is no differentiation, if two discoveries run in parallel each will use its own protocol (new - kad dht, old - peerexchange). if some of the peers don't talk one of the protocols then that discovery will skip that peer

@dshulyak
Copy link
Contributor Author

bors merge

@dshulyak
Copy link
Contributor Author

bors cancel

@dshulyak
Copy link
Contributor Author

bors merge

@dshulyak
Copy link
Contributor Author

bors cancel

@dshulyak
Copy link
Contributor Author

bors merge

bors bot pushed a commit that referenced this pull request Jul 31, 2023
this makes use of "native" libp2p discovery by enabling kad dht, peers exchange (adjusting score) and relay servers. the primary reason is to benefit from hole punching and multiple transports support (quic, webrtc).

in general peers will be obtained by one of the following methods:
- getting more peers from dht. in order for peer to be added to public dht it needs to have dialable address and advertise it to the neighbors. this is pretty much analogous to our current setup, but it also supports multiple addresses so we can enable quic in next change. as it is udp based it may work on nat/firewall devices where tcp was restricted.
- peer exchange (as a part of gossipsub) will advertise peers to other nodes as part of PRUNE message, once other node sees relayed address it will initiate holepunch.  if peer is not publicly dialable it will request relay reservation from the bootnodes. once received this reservation will be communicated to bootnode as one of the peer addresses.
- additionally we will persist peers in p2p/connected.txt every 30minutes, and try to reconnect with them on startup to decrease load on bootnodes/relays. 

configuration changes:
- `p2p-bootnode` option needs to be set explicitly on bootnodes in order to start dht in server mode, and adjust gossipsub configuration
- `p2p-reachability` can be either `public` or `private`. we have to set `public` on bootnodes, otherwise autonat might be confused by out setup, beside that it is only useful for testing.
- `p2p-holepunching` will enable relay client and holepunching. enabled by default
- `p2p-disable-legacy-discovery` disables our own discovery. it can be run in parallel, but we will have no reason to keep it if all works as expected
- `p2p-private-network` disables dht filtering by public address, it is mostly useful for testing
- `relay-server` section:
     - `enable` enable relay server, has to be enabled on bootnodes
     - `reservations` number of relay reservations, 512 by default
     -  `ttl` reservation ttl, 20 minutes  

example of the p2p config section:
```json
"p2p": {
        "listen": "/ip4/0.0.0.0/tcp/5000",
        "p2p-disable-legacy-discovery": true,
        "relay-server": {
            "enable": "true"
        },
        "p2p-reachability": "public",
        "p2p-bootnode": true,
}
```
@bors
Copy link

bors bot commented Jul 31, 2023

Build failed:

@dshulyak
Copy link
Contributor Author

bors merge

1 similar comment
@countvonzero
Copy link
Contributor

bors merge

bors bot pushed a commit that referenced this pull request Jul 31, 2023
this makes use of "native" libp2p discovery by enabling kad dht, peers exchange (adjusting score) and relay servers. the primary reason is to benefit from hole punching and multiple transports support (quic, webrtc).

in general peers will be obtained by one of the following methods:
- getting more peers from dht. in order for peer to be added to public dht it needs to have dialable address and advertise it to the neighbors. this is pretty much analogous to our current setup, but it also supports multiple addresses so we can enable quic in next change. as it is udp based it may work on nat/firewall devices where tcp was restricted.
- peer exchange (as a part of gossipsub) will advertise peers to other nodes as part of PRUNE message, once other node sees relayed address it will initiate holepunch.  if peer is not publicly dialable it will request relay reservation from the bootnodes. once received this reservation will be communicated to bootnode as one of the peer addresses.
- additionally we will persist peers in p2p/connected.txt every 30minutes, and try to reconnect with them on startup to decrease load on bootnodes/relays. 

configuration changes:
- `p2p-bootnode` option needs to be set explicitly on bootnodes in order to start dht in server mode, and adjust gossipsub configuration
- `p2p-reachability` can be either `public` or `private`. we have to set `public` on bootnodes, otherwise autonat might be confused by out setup, beside that it is only useful for testing.
- `p2p-holepunching` will enable relay client and holepunching. enabled by default
- `p2p-disable-legacy-discovery` disables our own discovery. it can be run in parallel, but we will have no reason to keep it if all works as expected
- `p2p-private-network` disables dht filtering by public address, it is mostly useful for testing
- `relay-server` section:
     - `enable` enable relay server, has to be enabled on bootnodes
     - `reservations` number of relay reservations, 512 by default
     -  `ttl` reservation ttl, 20 minutes  

example of the p2p config section:
```json
"p2p": {
        "listen": "/ip4/0.0.0.0/tcp/5000",
        "p2p-disable-legacy-discovery": true,
        "relay-server": {
            "enable": "true"
        },
        "p2p-reachability": "public",
        "p2p-bootnode": true,
}
```
@bors
Copy link

bors bot commented Jul 31, 2023

Pull request successfully merged into develop.

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot changed the title p2p: enable dht based disovery [Merged by Bors] - p2p: enable dht based disovery Jul 31, 2023
@bors bors bot closed this Jul 31, 2023
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.

None yet

2 participants