Skip to content

Commit

Permalink
indicies -> indices (#2873)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Mar 26, 2024
1 parent c896704 commit f945aa5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions network/ip_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newIPTracker(
bloomMetrics: bloomMetrics,
connected: make(map[ids.NodeID]*ips.ClaimedIPPort),
mostRecentValidatorIPs: make(map[ids.NodeID]*ips.ClaimedIPPort),
gossipableIndicies: make(map[ids.NodeID]int),
gossipableIndices: make(map[ids.NodeID]int),
bloomAdditions: make(map[ids.NodeID]int),
}
err = utils.Err(
Expand Down Expand Up @@ -92,8 +92,8 @@ type ipTracker struct {
// - The node is a validator
// - The node is connected
// - The IP the node connected with is its latest IP
gossipableIndicies map[ids.NodeID]int
gossipableIPs []*ips.ClaimedIPPort
gossipableIndices map[ids.NodeID]int
gossipableIPs []*ips.ClaimedIPPort

// The bloom filter contains the most recent validator IPs to avoid
// unnecessary IP gossip.
Expand Down Expand Up @@ -288,25 +288,25 @@ func (i *ipTracker) updateMostRecentValidatorIP(ip *ips.ClaimedIPPort) {
}

func (i *ipTracker) addGossipableIP(ip *ips.ClaimedIPPort) {
i.gossipableIndicies[ip.NodeID] = len(i.gossipableIPs)
i.gossipableIndices[ip.NodeID] = len(i.gossipableIPs)
i.gossipableIPs = append(i.gossipableIPs, ip)
i.numGossipable.Inc()
}

func (i *ipTracker) removeGossipableIP(nodeID ids.NodeID) {
indexToRemove, wasGossipable := i.gossipableIndicies[nodeID]
indexToRemove, wasGossipable := i.gossipableIndices[nodeID]
if !wasGossipable {
return
}

newNumGossipable := len(i.gossipableIPs) - 1
if newNumGossipable != indexToRemove {
replacementIP := i.gossipableIPs[newNumGossipable]
i.gossipableIndicies[replacementIP.NodeID] = indexToRemove
i.gossipableIndices[replacementIP.NodeID] = indexToRemove
i.gossipableIPs[indexToRemove] = replacementIP
}

delete(i.gossipableIndicies, nodeID)
delete(i.gossipableIndices, nodeID)
i.gossipableIPs[newNumGossipable] = nil
i.gossipableIPs = i.gossipableIPs[:newNumGossipable]
i.numGossipable.Dec()
Expand Down
22 changes: 11 additions & 11 deletions network/ip_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func requireEqual(t *testing.T, expected, actual *ipTracker) {
require.Equal(expected.connected, actual.connected)
require.Equal(expected.mostRecentValidatorIPs, actual.mostRecentValidatorIPs)
require.Equal(expected.validators, actual.validators)
require.Equal(expected.gossipableIndicies, actual.gossipableIndicies)
require.Equal(expected.gossipableIndices, actual.gossipableIndices)
require.Equal(expected.gossipableIPs, actual.gossipableIPs)
require.Equal(expected.bloomAdditions, actual.bloomAdditions)
require.Equal(expected.maxBloomCount, actual.maxBloomCount)
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestIPTracker_ManuallyTrack(t *testing.T) {
tracker.Connected(ip)
tracker.mostRecentValidatorIPs[ip.NodeID] = ip
tracker.bloomAdditions[ip.NodeID] = 1
tracker.gossipableIndicies[ip.NodeID] = 0
tracker.gossipableIndices[ip.NodeID] = 0
tracker.gossipableIPs = []*ips.ClaimedIPPort{
ip,
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestIPTracker_AddIP(t *testing.T) {
tracker.Connected(ip)
tracker.mostRecentValidatorIPs[newerIP.NodeID] = newerIP
tracker.bloomAdditions[newerIP.NodeID] = 2
delete(tracker.gossipableIndicies, newerIP.NodeID)
delete(tracker.gossipableIndices, newerIP.NodeID)
tracker.gossipableIPs = tracker.gossipableIPs[:0]
return tracker
}(),
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestIPTracker_Connected(t *testing.T) {
tracker.connected[ip.NodeID] = ip
tracker.mostRecentValidatorIPs[ip.NodeID] = ip
tracker.bloomAdditions[ip.NodeID] = 1
tracker.gossipableIndicies[ip.NodeID] = 0
tracker.gossipableIndices[ip.NodeID] = 0
tracker.gossipableIPs = []*ips.ClaimedIPPort{
ip,
}
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestIPTracker_Connected(t *testing.T) {
tracker.connected[newerIP.NodeID] = newerIP
tracker.mostRecentValidatorIPs[newerIP.NodeID] = newerIP
tracker.bloomAdditions[newerIP.NodeID] = 2
tracker.gossipableIndicies[newerIP.NodeID] = 0
tracker.gossipableIndices[newerIP.NodeID] = 0
tracker.gossipableIPs = []*ips.ClaimedIPPort{
newerIP,
}
Expand All @@ -344,7 +344,7 @@ func TestIPTracker_Connected(t *testing.T) {
tracker.onValidatorAdded(ip.NodeID)
require.True(t, tracker.AddIP(ip))
tracker.connected[ip.NodeID] = ip
tracker.gossipableIndicies[ip.NodeID] = 0
tracker.gossipableIndices[ip.NodeID] = 0
tracker.gossipableIPs = []*ips.ClaimedIPPort{
ip,
}
Expand Down Expand Up @@ -392,7 +392,7 @@ func TestIPTracker_Disconnected(t *testing.T) {
tracker.onValidatorAdded(ip.NodeID)
tracker.Connected(ip)
delete(tracker.connected, ip.NodeID)
delete(tracker.gossipableIndicies, ip.NodeID)
delete(tracker.gossipableIndices, ip.NodeID)
tracker.gossipableIPs = tracker.gossipableIPs[:0]
return tracker
}(),
Expand All @@ -415,7 +415,7 @@ func TestIPTracker_Disconnected(t *testing.T) {
tracker.onValidatorAdded(otherIP.NodeID)
tracker.Connected(otherIP)
delete(tracker.connected, ip.NodeID)
tracker.gossipableIndicies = map[ids.NodeID]int{
tracker.gossipableIndices = map[ids.NodeID]int{
otherIP.NodeID: 0,
}
tracker.gossipableIPs = []*ips.ClaimedIPPort{
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestIPTracker_OnValidatorAdded(t *testing.T) {
tracker.validators.Add(ip.NodeID)
tracker.mostRecentValidatorIPs[ip.NodeID] = ip
tracker.bloomAdditions[ip.NodeID] = 1
tracker.gossipableIndicies[ip.NodeID] = 0
tracker.gossipableIndices[ip.NodeID] = 0
tracker.gossipableIPs = []*ips.ClaimedIPPort{
ip,
}
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestIPTracker_OnValidatorRemoved(t *testing.T) {
tracker.Connected(ip)
delete(tracker.mostRecentValidatorIPs, ip.NodeID)
tracker.validators.Remove(ip.NodeID)
delete(tracker.gossipableIndicies, ip.NodeID)
delete(tracker.gossipableIndices, ip.NodeID)
tracker.gossipableIPs = tracker.gossipableIPs[:0]
return tracker
}(),
Expand All @@ -578,7 +578,7 @@ func TestIPTracker_OnValidatorRemoved(t *testing.T) {
tracker.Connected(otherIP)
delete(tracker.mostRecentValidatorIPs, ip.NodeID)
tracker.validators.Remove(ip.NodeID)
tracker.gossipableIndicies = map[ids.NodeID]int{
tracker.gossipableIndices = map[ids.NodeID]int{
otherIP.NodeID: 0,
}
tracker.gossipableIPs = []*ips.ClaimedIPPort{
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/add_permissionless_delegator_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func TestAddPermissionlessPrimaryDelegatorSerialization(t *testing.T) {
0x00, 0x00, 0x00, 0x05,
// amount
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// number of signature indicies
// number of signature indices
0x00, 0x00, 0x00, 0x00,
// memo length
0x00, 0x00, 0x00, 0x14,
Expand Down Expand Up @@ -1281,7 +1281,7 @@ func TestAddPermissionlessSubnetDelegatorSerialization(t *testing.T) {
0x00, 0x00, 0x00, 0x05,
// amount
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// number of signature indicies
// number of signature indices
0x00, 0x00, 0x00, 0x00,
// memo length
0x00, 0x00, 0x00, 0x14,
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/add_permissionless_validator_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func TestAddPermissionlessPrimaryValidator(t *testing.T) {
0x00, 0x00, 0x00, 0x05,
// amount
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// number of signature indicies
// number of signature indices
0x00, 0x00, 0x00, 0x00,
// memo length
0x00, 0x00, 0x00, 0x14,
Expand Down Expand Up @@ -1272,7 +1272,7 @@ func TestAddPermissionlessSubnetValidator(t *testing.T) {
0x00, 0x00, 0x00, 0x05,
// amount
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// number of signature indicies
// number of signature indices
0x00, 0x00, 0x00, 0x00,
// memo length
0x00, 0x00, 0x00, 0x14,
Expand Down

0 comments on commit f945aa5

Please sign in to comment.