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

Prefer gossiping bootstrapper IPs #2400

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions genesis/bootstrappers.go
Original file line number Diff line number Diff line change
@@ -36,10 +36,17 @@ type Bootstrapper struct {
IP ips.IPDesc `json:"ip"`
}

// SampleBootstrappers returns the some beacons this node should connect to
func SampleBootstrappers(networkID uint32, count int) []Bootstrapper {
// GetBootstrappers returns all the default bootstrappers for the provided
// network
func GetBootstrappers(networkID uint32) []Bootstrapper {
networkName := constants.NetworkIDToNetworkName[networkID]
bootstrappers := bootstrappersPerNetwork[networkName]
return bootstrappersPerNetwork[networkName]
}

// SampleBootstrappers returns some bootstrappers this node can connect to when
// joining the provided network
func SampleBootstrappers(networkID uint32, count int) []Bootstrapper {
bootstrappers := GetBootstrappers(networkID)
count = math.Min(count, len(bootstrappers))

s := sampler.NewUniform()
45 changes: 33 additions & 12 deletions network/network.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import (
"golang.org/x/exp/maps"

"github.com/ava-labs/avalanchego/api/health"
"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/message"
"github.com/ava-labs/avalanchego/network/dialer"
@@ -685,20 +686,14 @@ func (n *network) Peers(peerID ids.NodeID) ([]ips.ClaimedIPPort, error) {
return nil, nil
}

// We select a random sample of validators to gossip to avoid starving out a
// validator from being gossiped for an extended period of time.
s := sampler.NewUniform()
s.Initialize(uint64(len(unknownValidators)))
var bootstrapperIDs set.Set[ids.NodeID]
for _, bootstrapper := range genesis.GetBootstrappers(n.config.NetworkID) {
bootstrapperIDs.Add(bootstrapper.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will initialize the Set if it hasn't been yet, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct

}

// Calculate the unknown information we need to send to this peer.
validatorIPs := make([]ips.ClaimedIPPort, 0, int(n.config.PeerListNumValidatorIPs))
for i := 0; i < len(unknownValidators) && len(validatorIPs) < int(n.config.PeerListNumValidatorIPs); i++ {
drawn, err := s.Next()
if err != nil {
return nil, err
}

validator := unknownValidators[drawn]
tryAddValidator := func(validator peer.ValidatorID) {
n.peersLock.RLock()
_, isConnected := n.connectedPeers.GetByID(validator.NodeID)
peerIP := n.peerIPs[validator.NodeID]
@@ -708,7 +703,7 @@ func (n *network) Peers(peerID ids.NodeID) ([]ips.ClaimedIPPort, error) {
"unable to find validator in connected peers",
zap.Stringer("nodeID", validator.NodeID),
)
continue
return
}

// Note: peerIP isn't used directly here because the TxID may be
@@ -723,6 +718,32 @@ func (n *network) Peers(peerID ids.NodeID) ([]ips.ClaimedIPPort, error) {
},
)
}
for _, validator := range unknownValidators {
if !bootstrapperIDs.Contains(validator.NodeID) {
continue
}

tryAddValidator(validator)
}

// We select a random sample of validators to gossip to avoid starving out a
// validator from being gossiped for an extended period of time.
s := sampler.NewUniform()
s.Initialize(uint64(len(unknownValidators)))

for i := 0; i < len(unknownValidators) && len(validatorIPs) < int(n.config.PeerListNumValidatorIPs); i++ {
drawn, err := s.Next()
if err != nil {
return nil, err
}

validator := unknownValidators[drawn]
if bootstrapperIDs.Contains(validator.NodeID) {
continue
}

tryAddValidator(validator)
}

return validatorIPs, nil
}
2 changes: 1 addition & 1 deletion utils/constants/networking.go
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ const (

MaxContainersLen = int(4 * DefaultMaxMessageSize / 5)

DefaultNetworkPeerListNumValidatorIPs = 15
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set this so that we will (even in the first message) send some non-bootstrapper IPs so that the first round of connections don't just result in everyone sending the same peerlists (and therefore the nodes not quickly connecting to the wider network)

DefaultNetworkPeerListNumValidatorIPs = 30
DefaultNetworkPeerListValidatorGossipSize = 20
DefaultNetworkPeerListNonValidatorGossipSize = 0
DefaultNetworkPeerListPeersGossipSize = 10