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

fix(dot/network): fix dht connection on discovery on devnet #2059

Merged
merged 18 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions dot/network/connmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestPersistentPeers(t *testing.T) {
}
nodeB := createTestService(t, configB)

time.Sleep(time.Millisecond * 2000)
time.Sleep(time.Millisecond * 600)
// B should have connected to A during bootstrap
conns := nodeB.host.h.Network().ConnsToPeer(nodeA.host.id())
require.NotEqual(t, 0, len(conns))
Expand Down Expand Up @@ -226,13 +226,13 @@ func TestSetReservedPeer(t *testing.T) {

node3 := createTestService(t, config)
node3.noGossip = true
time.Sleep(time.Millisecond * 3000)
time.Sleep(time.Millisecond * 600)

require.Equal(t, 2, node3.host.peerCount())

node3.host.h.Peerstore().AddAddrs(addrC.ID, addrC.Addrs, peerstore.PermanentAddrTTL)
node3.host.cm.peerSetHandler.SetReservedPeer(0, addrC.ID)
time.Sleep(2000 * time.Millisecond)
time.Sleep(200 * time.Millisecond)

// reservedOnly mode is not yet implemented, so nodeA and nodeB won't be disconnected (#1888).
// TODO: once reservedOnly mode is implemented and reservedOnly is set to true, change expected value to 1 (nodeC)
Expand Down
4 changes: 2 additions & 2 deletions dot/network/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func Test_AddReservedPeers(t *testing.T) {
err := nodeA.host.addReservedPeers(nodeBPeerAddr)
require.NoError(t, err)

time.Sleep(1000 * time.Millisecond)
time.Sleep(100 * time.Millisecond)

require.Equal(t, 1, nodeA.host.peerCount())
}
Expand Down Expand Up @@ -485,7 +485,7 @@ func Test_RemoveReservedPeers(t *testing.T) {
err := nodeA.host.addReservedPeers(nodeBPeerAddr)
require.NoError(t, err)

time.Sleep(1000 * time.Millisecond)
time.Sleep(100 * time.Millisecond)

require.Equal(t, 1, nodeA.host.peerCount())
pID := nodeB.host.addrInfo().ID.String()
Expand Down
2 changes: 2 additions & 0 deletions dot/peerset/peerset.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ func (ps *PeerSet) addReservedPeers(setID int, peers ...peer.ID) error {
return nil
}

ps.peerState.discover(setID, peerID)

ps.reservedNode[peerID] = struct{}{}
if err := ps.peerState.addNoSlotNode(setID, peerID); err != nil {
return fmt.Errorf("could not add to list of no-slot nodes: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion dot/peerset/peerset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestAddReservedPeers(t *testing.T) {
handler.AddReservedPeer(0, reservedPeer)
handler.AddReservedPeer(0, reservedPeer2)

time.Sleep(time.Millisecond * 2000)
time.Sleep(time.Millisecond * 200)

expectedMsgs := []Message{
{Status: Connect, setID: 0, PeerID: bootNode},
Expand Down
2 changes: 1 addition & 1 deletion dot/peerset/peerstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (ps *PeersState) addNoSlotNode(idx int, peerID peer.ID) error {
ps.sets[idx].noSlotNodes[peerID] = struct{}{}
n, err := ps.getNode(peerID)
if err != nil {
return fmt.Errorf("could not get node: %w", err)
return fmt.Errorf("could not get node for peer id %s: %w", peerID, err)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}

switch n.state[idx] {
Expand Down
2 changes: 1 addition & 1 deletion dot/peerset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newTestPeerSet(t *testing.T, in, out uint32, bootNodes, reservedPeers []pee

handler.AddPeer(0, bootNodes...)
handler.AddReservedPeer(0, reservedPeers...)
time.Sleep(time.Millisecond * 4000)
time.Sleep(time.Millisecond * 100)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved

return handler
}
Expand Down