@@ -66,7 +66,6 @@ type blockMsg struct {
66
66
ctx context.Context
67
67
chainID uint32
68
68
block * iotextypes.Block
69
- blkType uint32
70
69
}
71
70
72
71
func (m blockMsg ) ChainID () uint32 {
@@ -101,7 +100,7 @@ type IotxDispatcher struct {
101
100
started int32
102
101
shutdown int32
103
102
eventChan chan interface {}
104
- eventAudit map [uint32 ]int
103
+ eventAudit map [iotexrpc. MessageType ]int
105
104
eventAuditLock sync.RWMutex
106
105
wg sync.WaitGroup
107
106
quit chan struct {}
@@ -114,7 +113,7 @@ type IotxDispatcher struct {
114
113
func NewDispatcher (cfg config.Config ) (Dispatcher , error ) {
115
114
d := & IotxDispatcher {
116
115
eventChan : make (chan interface {}, cfg .Dispatcher .EventChanSize ),
117
- eventAudit : make (map [uint32 ]int ),
116
+ eventAudit : make (map [iotexrpc. MessageType ]int ),
118
117
quit : make (chan struct {}),
119
118
subscribers : make (map [uint32 ]Subscriber ),
120
119
}
@@ -160,10 +159,10 @@ func (d *IotxDispatcher) EventChan() *chan interface{} {
160
159
}
161
160
162
161
// EventAudit returns the event audit map
163
- func (d * IotxDispatcher ) EventAudit () map [uint32 ]int {
162
+ func (d * IotxDispatcher ) EventAudit () map [iotexrpc. MessageType ]int {
164
163
d .eventAuditLock .RLock ()
165
164
defer d .eventAuditLock .RUnlock ()
166
- snapshot := make (map [uint32 ]int )
165
+ snapshot := make (map [iotexrpc. MessageType ]int )
167
166
for k , v := range d .eventAudit {
168
167
snapshot [k ] = v
169
168
}
@@ -199,7 +198,7 @@ loop:
199
198
200
199
// handleActionMsg handles actionMsg from all peers.
201
200
func (d * IotxDispatcher ) handleActionMsg (m * actionMsg ) {
202
- d .updateEventAudit (protogen . MsgActionType )
201
+ d .updateEventAudit (iotexrpc . MessageType_ACTION )
203
202
if subscriber , ok := d .subscribers [m .ChainID ()]; ok {
204
203
if err := subscriber .HandleAction (m .ctx , m .action ); err != nil {
205
204
requestMtc .WithLabelValues ("AddAction" , "false" ).Inc ()
@@ -215,7 +214,7 @@ func (d *IotxDispatcher) handleBlockMsg(m *blockMsg) {
215
214
d .subscribersMU .RLock ()
216
215
defer d .subscribersMU .RUnlock ()
217
216
if subscriber , ok := d .subscribers [m .ChainID ()]; ok {
218
- d .updateEventAudit (protogen . MsgBlockProtoMsgType )
217
+ d .updateEventAudit (iotexrpc . MessageType_BLOCK )
219
218
if err := subscriber .HandleBlock (m .ctx , m .block ); err != nil {
220
219
log .L ().Error ("Fail to handle the block." , zap .Error (err ))
221
220
}
@@ -231,7 +230,7 @@ func (d *IotxDispatcher) handleBlockSyncMsg(m *blockSyncMsg) {
231
230
zap .Uint64 ("start" , m .sync .Start ),
232
231
zap .Uint64 ("end" , m .sync .End ))
233
232
234
- d .updateEventAudit (protogen . MsgBlockSyncReqType )
233
+ d .updateEventAudit (iotexrpc . MessageType_BLOCK_REQUEST )
235
234
if subscriber , ok := d .subscribers [m .ChainID ()]; ok {
236
235
// dispatch to block sync
237
236
if err := subscriber .HandleSyncRequest (m .ctx , m .peer , m .sync ); err != nil {
@@ -263,7 +262,6 @@ func (d *IotxDispatcher) dispatchBlockCommit(ctx context.Context, chainID uint32
263
262
ctx : ctx ,
264
263
chainID : chainID ,
265
264
block : (msg ).(* iotextypes.Block ),
266
- blkType : protogen .MsgBlockProtoMsgType ,
267
265
})
268
266
}
269
267
@@ -282,7 +280,7 @@ func (d *IotxDispatcher) dispatchBlockSyncReq(ctx context.Context, chainID uint3
282
280
283
281
// HandleBroadcast handles incoming broadcast message
284
282
func (d * IotxDispatcher ) HandleBroadcast (ctx context.Context , chainID uint32 , message proto.Message ) {
285
- msgType , err := protogen .GetTypeFromProtoMsg (message )
283
+ msgType , err := protogen .GetTypeFromRPCMsg (message )
286
284
if err != nil {
287
285
log .L ().Warn ("Unexpected message handled by HandleBroadcast." , zap .Error (err ))
288
286
}
@@ -296,33 +294,33 @@ func (d *IotxDispatcher) HandleBroadcast(ctx context.Context, chainID uint32, me
296
294
d .subscribersMU .RUnlock ()
297
295
298
296
switch msgType {
299
- case protogen . MsgConsensusType :
297
+ case iotexrpc . MessageType_CONSENSUS :
300
298
err := subscriber .HandleConsensusMsg (message .(* iotexrpc.Consensus ))
301
299
if err != nil {
302
300
log .L ().Error ("Failed to handle block propose." , zap .Error (err ))
303
301
}
304
- case protogen . MsgActionType :
302
+ case iotexrpc . MessageType_ACTION :
305
303
d .dispatchAction (ctx , chainID , message )
306
- case protogen . MsgBlockProtoMsgType :
304
+ case iotexrpc . MessageType_BLOCK :
307
305
d .dispatchBlockCommit (ctx , chainID , message )
308
306
default :
309
- log .L ().Warn ("Unexpected msgType handled by HandleBroadcast." , zap .Uint32 ("msgType" , msgType ))
307
+ log .L ().Warn ("Unexpected msgType handled by HandleBroadcast." , zap .Any ("msgType" , msgType ))
310
308
}
311
309
}
312
310
313
311
// HandleTell handles incoming unicast message
314
312
func (d * IotxDispatcher ) HandleTell (ctx context.Context , chainID uint32 , peer peerstore.PeerInfo , message proto.Message ) {
315
- msgType , err := protogen .GetTypeFromProtoMsg (message )
313
+ msgType , err := protogen .GetTypeFromRPCMsg (message )
316
314
if err != nil {
317
315
log .L ().Warn ("Unexpected message handled by HandleTell." , zap .Error (err ))
318
316
}
319
317
switch msgType {
320
- case protogen . MsgBlockSyncReqType :
318
+ case iotexrpc . MessageType_BLOCK_REQUEST :
321
319
d .dispatchBlockSyncReq (ctx , chainID , peer , message )
322
- case protogen . MsgBlockProtoMsgType :
320
+ case iotexrpc . MessageType_BLOCK :
323
321
d .dispatchBlockCommit (ctx , chainID , message )
324
322
default :
325
- log .L ().Warn ("Unexpected msgType handled by HandleTell." , zap .Uint32 ("msgType" , msgType ))
323
+ log .L ().Warn ("Unexpected msgType handled by HandleTell." , zap .Any ("msgType" , msgType ))
326
324
}
327
325
}
328
326
@@ -336,7 +334,7 @@ func (d *IotxDispatcher) enqueueEvent(event interface{}) {
336
334
}()
337
335
}
338
336
339
- func (d * IotxDispatcher ) updateEventAudit (t uint32 ) {
337
+ func (d * IotxDispatcher ) updateEventAudit (t iotexrpc. MessageType ) {
340
338
d .eventAuditLock .Lock ()
341
339
defer d .eventAuditLock .Unlock ()
342
340
d .eventAudit [t ]++
0 commit comments