Skip to content

Commit 637050b

Browse files
authored
fix(dot/network): split stored streams and handshakeData into inbound and outbound (ChainSafe#1553)
1 parent 88b88f2 commit 637050b

11 files changed

+191
-174
lines changed

dot/network/block_announce.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,14 @@ func (s *Service) validateBlockAnnounceHandshake(peer peer.ID, hs Handshake) err
220220

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

232-
data.handshake = hs
233-
np.handshakeData.Store(peer, data)
234-
235231
// if peer has higher best block than us, begin syncing
236232
latestHeader, err := s.blockState.BestBlockHeader()
237233
if err != nil {

dot/network/block_announce_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ func TestValidateBlockAnnounceHandshake(t *testing.T) {
117117
nodeA := createTestService(t, configA)
118118
nodeA.noGossip = true
119119
nodeA.notificationsProtocols[BlockAnnounceMsgType] = &notificationsProtocol{
120-
handshakeData: new(sync.Map),
120+
inboundHandshakeData: new(sync.Map),
121121
}
122122
testPeerID := peer.ID("noot")
123-
nodeA.notificationsProtocols[BlockAnnounceMsgType].handshakeData.Store(testPeerID, handshakeData{})
123+
nodeA.notificationsProtocols[BlockAnnounceMsgType].inboundHandshakeData.Store(testPeerID, handshakeData{})
124124

125125
err := nodeA.validateBlockAnnounceHandshake(testPeerID, &BlockAnnounceHandshake{
126126
BestBlockNumber: 100,

dot/network/host_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,13 @@ func TestStreamCloseMetadataCleanup(t *testing.T) {
352352
info := nodeA.notificationsProtocols[BlockAnnounceMsgType]
353353

354354
// Set handshake data to received
355-
info.handshakeData.Store(nodeB.host.id(), handshakeData{
355+
info.inboundHandshakeData.Store(nodeB.host.id(), handshakeData{
356356
received: true,
357357
validated: true,
358358
})
359359

360360
// Verify that handshake data exists.
361-
_, ok := info.getHandshakeData(nodeB.host.id())
361+
_, ok := info.getHandshakeData(nodeB.host.id(), true)
362362
require.True(t, ok)
363363

364364
time.Sleep(time.Second)
@@ -368,7 +368,7 @@ func TestStreamCloseMetadataCleanup(t *testing.T) {
368368
time.Sleep(time.Second)
369369

370370
// Verify that handshake data is cleared.
371-
_, ok = info.getHandshakeData(nodeB.host.id())
371+
_, ok = info.getHandshakeData(nodeB.host.id(), true)
372372
require.False(t, ok)
373373
}
374374

dot/network/light_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestDecodeLightMessage(t *testing.T) {
2222
reqEnc, err := testLightRequest.Encode()
2323
require.NoError(t, err)
2424

25-
msg, err := s.decodeLightMessage(reqEnc, testPeer)
25+
msg, err := s.decodeLightMessage(reqEnc, testPeer, true)
2626
require.NoError(t, err)
2727

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

39-
msg, err = s.decodeLightMessage(respEnc, testPeer)
39+
msg, err = s.decodeLightMessage(respEnc, testPeer, true)
4040
require.NoError(t, err)
4141
resp, ok := msg.(*LightResponse)
4242
require.True(t, ok)

0 commit comments

Comments
 (0)