Skip to content

Commit d9a8972

Browse files
Merge branch 'development' into eclesio/rpc-sync-state
2 parents b997e93 + 093e149 commit d9a8972

28 files changed

+193
-213
lines changed

chain/gssmr/genesis.json

Lines changed: 5 additions & 9 deletions
Large diffs are not rendered by default.

dot/core/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type TransactionState interface {
7070

7171
// Network is the interface for the network service
7272
type Network interface {
73-
SendMessage(network.NotificationsMessage)
73+
GossipMessage(network.NotificationsMessage)
7474
}
7575

7676
// EpochState is the interface for state.EpochState

dot/core/messages_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ func TestService_ProcessBlockAnnounceMessage(t *testing.T) {
110110
BestBlock: true,
111111
}
112112

113-
//setup the SendMessage function
114-
net.On("SendMessage", expected)
113+
net.On("GossipMessage", expected)
115114

116115
state, err := s.storageState.TrieState(nil)
117116
require.NoError(t, err)
@@ -120,7 +119,7 @@ func TestService_ProcessBlockAnnounceMessage(t *testing.T) {
120119
require.NoError(t, err)
121120

122121
time.Sleep(time.Second)
123-
net.AssertCalled(t, "SendMessage", expected)
122+
net.AssertCalled(t, "GossipMessage", expected)
124123
}
125124

126125
func TestService_HandleTransactionMessage(t *testing.T) {

dot/core/mocks/network.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dot/core/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (s *Service) HandleBlockProduced(block *types.Block, state *rtstorage.TrieS
204204
BestBlock: true,
205205
}
206206

207-
s.net.SendMessage(msg)
207+
s.net.GossipMessage(msg)
208208
return s.handleBlock(block, state)
209209
}
210210

@@ -553,7 +553,7 @@ func (s *Service) HandleSubmittedExtrinsic(ext types.Extrinsic) error {
553553

554554
// broadcast transaction
555555
msg := &network.TransactionMessage{Extrinsics: []types.Extrinsic{ext}}
556-
s.net.SendMessage(msg)
556+
s.net.GossipMessage(msg)
557557
return nil
558558
}
559559

dot/core/service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func TestAnnounceBlock(t *testing.T) {
129129
BestBlock: true,
130130
}
131131

132-
net.On("SendMessage", expected)
132+
net.On("GossipMessage", expected)
133133

134134
state, err := s.storageState.TrieState(nil)
135135
require.NoError(t, err)
@@ -138,7 +138,7 @@ func TestAnnounceBlock(t *testing.T) {
138138
require.NoError(t, err)
139139

140140
time.Sleep(time.Second)
141-
net.AssertCalled(t, "SendMessage", expected)
141+
net.AssertCalled(t, "GossipMessage", expected)
142142
}
143143

144144
func TestService_HasKey(t *testing.T) {

dot/network/notifications_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func Test_HandshakeTimeout(t *testing.T) {
286286
BestBlockHash: common.Hash{1},
287287
GenesisHash: common.Hash{2},
288288
}
289-
nodeA.SendMessage(testHandshakeMsg)
289+
nodeA.GossipMessage(testHandshakeMsg)
290290

291291
go nodeA.sendData(nodeB.host.id(), testHandshakeMsg, info, nil)
292292

dot/network/service.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ func (s *Service) IsStopped() bool {
480480
return s.ctx.Err() != nil
481481
}
482482

483-
// SendMessage implementation of interface to handle receiving messages
484-
func (s *Service) SendMessage(msg NotificationsMessage) {
483+
// GossipMessage gossips a notifications protocol message to our peers
484+
func (s *Service) GossipMessage(msg NotificationsMessage) {
485485
if s.host == nil || msg == nil || s.IsStopped() {
486486
return
487487
}
@@ -509,6 +509,23 @@ func (s *Service) SendMessage(msg NotificationsMessage) {
509509
logger.Error("message not supported by any notifications protocol", "msg type", msg.Type())
510510
}
511511

512+
// SendMessage sends a message to the given peer
513+
func (s *Service) SendMessage(to peer.ID, msg NotificationsMessage) error {
514+
s.notificationsMu.Lock()
515+
defer s.notificationsMu.Unlock()
516+
for msgID, prtl := range s.notificationsProtocols {
517+
if msg.Type() != msgID || prtl == nil {
518+
continue
519+
}
520+
hs, err := prtl.getHandshake()
521+
if err != nil {
522+
return err
523+
}
524+
s.sendData(to, hs, prtl, msg)
525+
}
526+
return errors.New("message not supported by any notifications protocol")
527+
}
528+
512529
// handleLightStream handles streams with the <protocol-id>/light/2 protocol ID
513530
func (s *Service) handleLightStream(stream libp2pnetwork.Stream) {
514531
s.readStream(stream, s.decodeLightMessage, s.handleLightMsg)

dot/network/service_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func TestBroadcastMessages(t *testing.T) {
175175
require.NoError(t, err)
176176

177177
// simulate message sent from core service
178-
nodeA.SendMessage(testBlockAnnounceMessage)
178+
nodeA.GossipMessage(testBlockAnnounceMessage)
179179
time.Sleep(time.Second * 2)
180180
require.NotNil(t, handler.messages[nodeA.host.id()])
181181
}
@@ -232,7 +232,7 @@ func TestBroadcastDuplicateMessage(t *testing.T) {
232232

233233
// Only one message will be sent.
234234
for i := 0; i < 5; i++ {
235-
nodeA.SendMessage(testBlockAnnounceMessage)
235+
nodeA.GossipMessage(testBlockAnnounceMessage)
236236
time.Sleep(time.Millisecond * 10)
237237
}
238238

@@ -243,7 +243,7 @@ func TestBroadcastDuplicateMessage(t *testing.T) {
243243

244244
// All 5 message will be sent since cache is disabled.
245245
for i := 0; i < 5; i++ {
246-
nodeA.SendMessage(testBlockAnnounceMessage)
246+
nodeA.GossipMessage(testBlockAnnounceMessage)
247247
time.Sleep(time.Millisecond * 10)
248248
}
249249
require.Equal(t, 6, len(handler.messages[nodeA.host.id()]))

dot/rpc/modules/state_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestStateModule_GetRuntimeVersion(t *testing.T) {
4040
SpecName: "node",
4141
ImplName: "substrate-node",
4242
AuthoringVersion: 10,
43-
SpecVersion: 260,
43+
SpecVersion: 264,
4444
ImplVersion: 0,
4545
Apis: []interface{}{
4646
[]interface{}{"0xdf6acb689907609b", uint32(3)},
@@ -54,9 +54,10 @@ func TestStateModule_GetRuntimeVersion(t *testing.T) {
5454
[]interface{}{"0xbc9d89904f5b923f", uint32(1)},
5555
[]interface{}{"0x68b66ba122c93fa7", uint32(1)},
5656
[]interface{}{"0x37c8bb1350a9a2a8", uint32(1)},
57+
[]interface{}{"0x91d5df18b0d2cf58", uint32(1)},
5758
[]interface{}{"0xab3c0572291feb8b", uint32(1)},
5859
},
59-
TransactionVersion: 1,
60+
TransactionVersion: 2,
6061
}
6162

6263
sm, hash, _ := setupStateModule(t)
@@ -315,6 +316,7 @@ func TestStateModule_GetStorageSize(t *testing.T) {
315316
}
316317

317318
func TestStateModule_GetMetadata(t *testing.T) {
319+
t.Skip() // TODO: update expected_metadata
318320
sm, hash, _ := setupStateModule(t)
319321
randomHash, err := common.HexToHash(RandomHash)
320322
require.NoError(t, err)

0 commit comments

Comments
 (0)