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

Ignore --maxpeers param for --staticpeers #2789

Merged
merged 1 commit into from
Oct 7, 2021
Merged
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
7 changes: 3 additions & 4 deletions p2p/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ loop:
for {
// Launch new dials if slots are available.
slots := d.freeDialSlots()
slots -= d.startStaticDials(slots)
d.startStaticDials()
if slots > 0 {
nodesCh = d.nodesIn
} else {
Expand Down Expand Up @@ -421,14 +421,13 @@ func (d *dialScheduler) checkDial(n *enode.Node) error {
}

// startStaticDials starts n static dial tasks.
func (d *dialScheduler) startStaticDials(n int) (started int) {
for started = 0; started < n && len(d.staticPool) > 0; started++ {
func (d *dialScheduler) startStaticDials() {
for len(d.staticPool) > 0 {
idx := d.rand.Intn(len(d.staticPool))
task := d.staticPool[idx]
d.startDial(task)
d.removeFromStaticPool(idx)
}
return started
}

// updateStaticPool attempts to move the given static dial back into staticPool.
Expand Down
50 changes: 13 additions & 37 deletions p2p/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,22 @@ func TestDialSchedStaticDial(t *testing.T) {
d.addStatic(newNode(uintID(0x05), "127.0.0.5:30303"))
d.addStatic(newNode(uintID(0x06), "127.0.0.6:30303"))
d.addStatic(newNode(uintID(0x07), "127.0.0.7:30303"))
d.addStatic(newNode(uintID(0x08), "127.0.0.8:30303"))
d.addStatic(newNode(uintID(0x09), "127.0.0.9:30303"))
},
wantNewDials: []*enode.Node{
newNode(uintID(0x03), "127.0.0.3:30303"),
newNode(uintID(0x04), "127.0.0.4:30303"),
newNode(uintID(0x05), "127.0.0.5:30303"),
newNode(uintID(0x06), "127.0.0.6:30303"),
newNode(uintID(0x07), "127.0.0.7:30303"),
},
},
// Dial to 0x03 completes, filling a peer slot. One slot remains,
// two dials are launched to attempt to fill it.
{
update: func(d *dialScheduler) {
d.addStatic(newNode(uintID(0x08), "127.0.0.8:30303"))
d.addStatic(newNode(uintID(0x09), "127.0.0.9:30303"))
},
succeeded: []enode.ID{
uintID(0x03),
},
Expand Down Expand Up @@ -235,7 +238,7 @@ func TestDialSchedRemoveStatic(t *testing.T) {
maxDialPeers: 1,
}
runDialTest(t, config, []dialTestRound{
// Add static nodes.
// Add static nodes. Ignore maxActiveDials config
{
update: func(d *dialScheduler) {
d.addStatic(newNode(uintID(0x01), "127.0.0.1:30303"))
Expand All @@ -244,18 +247,23 @@ func TestDialSchedRemoveStatic(t *testing.T) {
},
wantNewDials: []*enode.Node{
newNode(uintID(0x01), "127.0.0.1:30303"),
newNode(uintID(0x02), "127.0.0.2:30303"),
newNode(uintID(0x03), "127.0.0.3:30303"),
},
},
// Dial to 0x01 fails.
{
update: func(d *dialScheduler) {
d.addStatic(newNode(uintID(0x04), "127.0.0.4:30303"))
},
failed: []enode.ID{
uintID(0x01),
},
wantResolves: map[enode.ID]*enode.Node{
uintID(0x01): nil,
},
wantNewDials: []*enode.Node{
newNode(uintID(0x02), "127.0.0.2:30303"),
newNode(uintID(0x04), "127.0.0.4:30303"),
},
},
// All static nodes are removed. 0x01 is in history, 0x02 is being
Expand All @@ -265,6 +273,7 @@ func TestDialSchedRemoveStatic(t *testing.T) {
d.removeStatic(newNode(uintID(0x01), "127.0.0.1:30303"))
d.removeStatic(newNode(uintID(0x02), "127.0.0.2:30303"))
d.removeStatic(newNode(uintID(0x03), "127.0.0.3:30303"))
d.removeStatic(newNode(uintID(0x04), "127.0.0.4:30303"))
},
failed: []enode.ID{
uintID(0x02),
Expand All @@ -278,39 +287,6 @@ func TestDialSchedRemoveStatic(t *testing.T) {
})
}

// This test checks that static dials are selected at random.
func TestDialSchedManyStaticNodes(t *testing.T) {
t.Parallel()

config := dialConfig{maxDialPeers: 2}
runDialTest(t, config, []dialTestRound{
{
peersAdded: []*conn{
{flags: dynDialedConn, node: newNode(uintID(0xFFFE), "")},
{flags: dynDialedConn, node: newNode(uintID(0xFFFF), "")},
},
update: func(d *dialScheduler) {
for id := uint16(0); id < 2000; id++ {
n := newNode(uintID(id), "127.0.0.1:30303")
d.addStatic(n)
}
},
},
{
peersRemoved: []enode.ID{
uintID(0xFFFE),
uintID(0xFFFF),
},
wantNewDials: []*enode.Node{
newNode(uintID(0x0085), "127.0.0.1:30303"),
newNode(uintID(0x02dc), "127.0.0.1:30303"),
newNode(uintID(0x0285), "127.0.0.1:30303"),
newNode(uintID(0x00cb), "127.0.0.1:30303"),
},
},
})
}

// This test checks that past dials are not retried for some time.
func TestDialSchedHistory(t *testing.T) {
t.Parallel()
Expand Down