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): split stored streams and handshakeData into inbound and outbound #1553

Merged
merged 9 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
16 changes: 6 additions & 10 deletions dot/network/block_announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,14 @@ func (s *Service) validateBlockAnnounceHandshake(peer peer.ID, hs Handshake) err

// don't need to lock here, since function is always called inside the func returned by
// `createNotificationsMessageHandler` which locks the map beforehand.
data, ok := np.getHandshakeData(peer)
if !ok {
np.handshakeData.Store(peer, handshakeData{
received: true,
validated: true,
})
data, _ = np.getHandshakeData(peer)
data, ok := np.getHandshakeData(peer, true)
if ok {
data.handshake = hs
// TODO: since this is used only for rpc system_peers only,
// we can just set the inbound handshake and use that in Peers()
np.inboundHandshakeData.Store(peer, data)
}

data.handshake = hs
np.handshakeData.Store(peer, data)

// if peer has higher best block than us, begin syncing
latestHeader, err := s.blockState.BestBlockHeader()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions dot/network/block_announce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ func TestValidateBlockAnnounceHandshake(t *testing.T) {
nodeA := createTestService(t, configA)
nodeA.noGossip = true
nodeA.notificationsProtocols[BlockAnnounceMsgType] = &notificationsProtocol{
handshakeData: new(sync.Map),
inboundHandshakeData: new(sync.Map),
}
testPeerID := peer.ID("noot")
nodeA.notificationsProtocols[BlockAnnounceMsgType].handshakeData.Store(testPeerID, handshakeData{})
nodeA.notificationsProtocols[BlockAnnounceMsgType].inboundHandshakeData.Store(testPeerID, handshakeData{})

err := nodeA.validateBlockAnnounceHandshake(testPeerID, &BlockAnnounceHandshake{
BestBlockNumber: 100,
Expand Down
6 changes: 3 additions & 3 deletions dot/network/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ func TestStreamCloseMetadataCleanup(t *testing.T) {
info := nodeA.notificationsProtocols[BlockAnnounceMsgType]

// Set handshake data to received
info.handshakeData.Store(nodeB.host.id(), handshakeData{
info.inboundHandshakeData.Store(nodeB.host.id(), handshakeData{
received: true,
validated: true,
})

// Verify that handshake data exists.
_, ok := info.getHandshakeData(nodeB.host.id())
_, ok := info.getHandshakeData(nodeB.host.id(), true)
require.True(t, ok)

time.Sleep(time.Second)
Expand All @@ -368,7 +368,7 @@ func TestStreamCloseMetadataCleanup(t *testing.T) {
time.Sleep(time.Second)

// Verify that handshake data is cleared.
_, ok = info.getHandshakeData(nodeB.host.id())
_, ok = info.getHandshakeData(nodeB.host.id(), true)
require.False(t, ok)
}

Expand Down
4 changes: 2 additions & 2 deletions dot/network/light_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestDecodeLightMessage(t *testing.T) {
reqEnc, err := testLightRequest.Encode()
require.NoError(t, err)

msg, err := s.decodeLightMessage(reqEnc, testPeer)
msg, err := s.decodeLightMessage(reqEnc, testPeer, true)
require.NoError(t, err)

req, ok := msg.(*LightRequest)
Expand All @@ -36,7 +36,7 @@ func TestDecodeLightMessage(t *testing.T) {
respEnc, err := testLightResponse.Encode()
require.NoError(t, err)

msg, err = s.decodeLightMessage(respEnc, testPeer)
msg, err = s.decodeLightMessage(respEnc, testPeer, true)
require.NoError(t, err)
resp, ok := msg.(*LightResponse)
require.True(t, ok)
Expand Down
Loading