Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,8 @@ type Config struct {
// Specifies how much disk usage each peer can cause before
// we rate-limit them.
DiskTargeter tracker.Targeter `json:"-"`

// If true, connects to all validators regardless of primary network validator
// status or of configured tracked subnets.
ConnectToAllValidators bool `json:"connectToAllValidators"`
}
18 changes: 12 additions & 6 deletions network/ip_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func newIPTracker(
trackedSubnets set.Set[ids.ID],
log logging.Logger,
registerer prometheus.Registerer,
connectToAllValidators bool,
) (*ipTracker, error) {
bloomMetrics, err := bloom.NewMetrics("ip_bloom", registerer)
if err != nil {
Expand All @@ -64,11 +65,12 @@ func newIPTracker(
Name: "tracked_subnets",
Help: "number of subnets this node is monitoring",
}),
bloomMetrics: bloomMetrics,
tracked: make(map[ids.NodeID]*trackedNode),
bloomAdditions: make(map[ids.NodeID]int),
connected: make(map[ids.NodeID]*connectedNode),
subnet: make(map[ids.ID]*gossipableSubnet),
connectToAllValidators: connectToAllValidators,
bloomMetrics: bloomMetrics,
tracked: make(map[ids.NodeID]*trackedNode),
bloomAdditions: make(map[ids.NodeID]int),
connected: make(map[ids.NodeID]*connectedNode),
subnet: make(map[ids.ID]*gossipableSubnet),
}
err = errors.Join(
registerer.Register(tracker.numTrackedPeers),
Expand Down Expand Up @@ -230,6 +232,8 @@ type ipTracker struct {
connected map[ids.NodeID]*connectedNode
// subnet tracks all the subnets that have at least one gossipable ID.
subnet map[ids.ID]*gossipableSubnet

connectToAllValidators bool
}

// ManuallyTrack marks the provided nodeID as being desirable to connect to.
Expand Down Expand Up @@ -267,6 +271,7 @@ func (i *ipTracker) ManuallyGossip(subnetID ids.ID, nodeID ids.NodeID) {
// 1. The node has been manually tracked.
// 2. The node has been manually gossiped on a tracked subnet.
// 3. The node is currently a validator on a tracked subnet.
// 4. The node is currently a validator on any subnet and connectToAllValidators is true.
func (i *ipTracker) WantsConnection(nodeID ids.NodeID) bool {
i.lock.RLock()
defer i.lock.RUnlock()
Expand Down Expand Up @@ -305,6 +310,7 @@ func (i *ipTracker) ShouldVerifyIP(
// 1. The provided IP is from a node whose connection is desired on a tracked
// subnet.
// 2. This IP is newer than the most recent IP we know of for the node.
// 3. The node is a validator and connectToAllValidators is true.
//
// If this IP is replacing a gossipable IP, this IP will also be marked as
// gossipable.
Expand Down Expand Up @@ -428,7 +434,7 @@ func (i *ipTracker) addTrackableID(nodeID ids.NodeID, subnetID *ids.ID) {
nodeTracker.manuallyTracked = true
} else {
nodeTracker.validatedSubnets.Add(*subnetID)
if *subnetID == constants.PrimaryNetworkID || i.trackedSubnets.Contains(*subnetID) {
if *subnetID == constants.PrimaryNetworkID || i.trackedSubnets.Contains(*subnetID) || i.connectToAllValidators {
nodeTracker.trackedSubnets.Add(*subnetID)
}
}
Expand Down
Loading
Loading