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

Use a random peer ID for lookup check #967

Closed
wants to merge 1 commit into from

Conversation

xinaxu
Copy link

@xinaxu xinaxu commented Mar 22, 2024

This fixes #966

@xinaxu xinaxu requested review from guillaumemichel and a team as code owners March 22, 2024 19:57
Copy link
Contributor

@Jorropo Jorropo left a comment

Choose a reason for hiding this comment

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

Thx for investigating this but I don't see why this solves the bug.
AFAIT the situation is:

  • we are starting a new DHT out of thin air
  • rust-libp2p starts and has 0 peers.
  • go-libp2p-kad-dht do FindPeer on rust-libp2p to check if it is a valid node, rust-libp2p has no peer in bucket yet and returns nothing.

Even if we request an other peer id I don't see why rust-libp2p would be able to respond with anything.
Am I wrong somewhere ?

// answer it correctly
func (dht *IpfsDHT) lookupCheck(ctx context.Context, p peer.ID) error {
// lookup request to p requesting for its own peer.ID
peerids, err := dht.protoMessenger.GetClosestPeers(ctx, p, p)
_, public, err := crypto.GenerateKeyPair(crypto.Ed25519, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

This an expensive CPU operation the bits argument is ignored for Ed25519:
https://github.com/libp2p/go-libp2p/blob/cbfd89676cb2e775441d158fb607d66a94241ae2/core/crypto/key.go#L112-L113

Alternatives:

  • Do it once at init (meh but fine)
  • Do it once in new and store it as a field
  • Use our own Peer ID
  • Use a hardcoded whatever Peer ID.

Copy link
Contributor

@guillaumemichel guillaumemichel Mar 26, 2024

Choose a reason for hiding this comment

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

Use our own Peer ID

👍🏻 Let's use our own Peer ID.


Edit:
Using our own Peer ID will not work when creating a new DHT network with 2 go-libp2p-kad-dht nodes:

  • A and B are running and have 0 connected peers
  • A learns about B
  • A sends a check request to B
  • B has still an empty routing table (because it didn't check A yet).
  • B won't include itself in the response, hence it sends an empty response.
  • A doesn't add B in its routing table.
  • B knows about A, and sends it a check request
  • A still has en empty routing table (B check failed)
  • ...

@guillaumemichel
Copy link
Contributor

In the rust-libp2p implementation, only requesting for the recipient key will trigger an empty response. If any other key is requested, the node should answer with nodes from its routing table. So requesting any other key should allow go-libp2p-kad-dht nodes to add rust-libp2p nodes to their routing table.

* _we are starting a new DHT out of thin air_

* rust-libp2p starts and has 0 peers.

* go-libp2p-kad-dht do FindPeer on rust-libp2p to check if it is a valid node, rust-libp2p has no peer in bucket yet and returns nothing.

In this case, rust-libp2p would add go-libp2p-kad-dht in its routing table after the failed check is performed. When rust-libp2p buckets will refresh (e.g after 10 minutes), it will ping go-libp2p-kad-dht, which will learn again about rust-libp2p, and check it again. This time, rust-libp2p will be able to answer with the go-libp2p-kad-dht peer id.

I agree with @Jorropo that generating a new random key every time is too expensive.

@guillaumemichel
Copy link
Contributor

Alternatively, we could run the lookupCheck only if the nodes has a non-empty routing table, or at least 5 (?) nodes in its routing table. The node shouldn't be picky if it doesn't have any peers yet.

@guillaumemichel
Copy link
Contributor

Closing as #966 is now resolved

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.

Bootstrap process not compatible with rust libp2p-kad
3 participants