chore(p2p): prefer tcp when discovering bootnodes#5406
Conversation
|
If I got it correctly, if bootnode has multiple underlays with TCP and WSS, and TCP for some reason is not connectable, currently it will never try other WSS address (because of the priority). This is beacuse in kademlia.go:832-835 - the callback returns (false, err) on any Connect failure (except ErrAlreadyConnected), and Discover propagates that error, aborting the loop. Would it be better that we skip and continue with next underlay? |
|
Thanks @gacevicljubisa. Not sure what do you mean with this assumption. My understanding is that the bool in the callback return signature is if _, err := p2p.Discover(ctx, addr, func(addr ma.Multiaddr) (stop bool, err error) {
loggerV1.Debug("connecting to bootnode", "bootnode_address", addr)
if attempts >= maxBootNodeAttempts {
return true, nil
}
.....
// connect to max 3 bootnodes
return connected >= 3, nil
}); |
When the callback returns (false, err) with a non-nil error, Discover propagates that error immediately and aborts the loop. The remaining addresses are never tried. Look at discover.go:57-59 I would suggest after Connect in kademlia.go:826 we check for if errors.Is(err, p2p.ErrUnsupportedAddresses) {
k.logger.Debug("bootnode address transport not supported, skipping", "bootnode_address", addr)
return false, nil
}And also, not to propage error from Connect at all in kademlia.go:831-838 if err != nil {
if errors.Is(err, p2p.ErrAlreadyConnected) {
k.logger.Debug("bootnode already connected", "bootnode_address", addr)
return false, nil
}
k.logger.Error(err, "connect to bootnode failed", "bootnode_address", addr)
return false, nil
} |
Checklist
Description
This PR introduces a prioritization of TCP underlays over other types of underlays when connecting to bootnodes.
AI Disclosure