@@ -30,7 +30,7 @@ type Handler interface {
30
30
ctx context.Context ,
31
31
nodeID ids.NodeID ,
32
32
gossipBytes []byte ,
33
- ) error
33
+ )
34
34
// AppRequest is called when handling an AppRequest message.
35
35
// Returns the bytes for the response corresponding to [requestBytes]
36
36
AppRequest (
@@ -53,9 +53,7 @@ type Handler interface {
53
53
// NoOpHandler drops all messages
54
54
type NoOpHandler struct {}
55
55
56
- func (NoOpHandler ) AppGossip (context.Context , ids.NodeID , []byte ) error {
57
- return nil
58
- }
56
+ func (NoOpHandler ) AppGossip (context.Context , ids.NodeID , []byte ) {}
59
57
60
58
func (NoOpHandler ) AppRequest (context.Context , ids.NodeID , time.Time , []byte ) ([]byte , error ) {
61
59
return nil , nil
@@ -69,14 +67,16 @@ func (NoOpHandler) CrossChainAppRequest(context.Context, ids.ID, time.Time, []by
69
67
type ValidatorHandler struct {
70
68
Handler
71
69
ValidatorSet ValidatorSet
70
+ Log logging.Logger
72
71
}
73
72
74
- func (v ValidatorHandler ) AppGossip (ctx context.Context , nodeID ids.NodeID , gossipBytes []byte ) error {
73
+ func (v ValidatorHandler ) AppGossip (ctx context.Context , nodeID ids.NodeID , gossipBytes []byte ) {
75
74
if ! v .ValidatorSet .Has (ctx , nodeID ) {
76
- return ErrNotValidator
75
+ v .Log .Debug ("dropping message" , zap .Stringer ("nodeID" , nodeID ))
76
+ return
77
77
}
78
78
79
- return v .Handler .AppGossip (ctx , nodeID , gossipBytes )
79
+ v .Handler .AppGossip (ctx , nodeID , gossipBytes )
80
80
}
81
81
82
82
func (v ValidatorHandler ) AppRequest (ctx context.Context , nodeID ids.NodeID , deadline time.Time , requestBytes []byte ) ([]byte , error ) {
@@ -89,15 +89,15 @@ func (v ValidatorHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, dea
89
89
90
90
// responder automatically sends the response for a given request
91
91
type responder struct {
92
+ Handler
92
93
handlerID uint64
93
- handler Handler
94
94
log logging.Logger
95
95
sender common.AppSender
96
96
}
97
97
98
98
// AppRequest calls the underlying handler and sends back the response to nodeID
99
99
func (r * responder ) AppRequest (ctx context.Context , nodeID ids.NodeID , requestID uint32 , deadline time.Time , request []byte ) error {
100
- appResponse , err := r .handler .AppRequest (ctx , nodeID , deadline , request )
100
+ appResponse , err := r .Handler .AppRequest (ctx , nodeID , deadline , request )
101
101
if err != nil {
102
102
r .log .Debug ("failed to handle message" ,
103
103
zap .Stringer ("messageOp" , message .AppRequestOp ),
@@ -113,21 +113,10 @@ func (r *responder) AppRequest(ctx context.Context, nodeID ids.NodeID, requestID
113
113
return r .sender .SendAppResponse (ctx , nodeID , requestID , appResponse )
114
114
}
115
115
116
- func (r * responder ) AppGossip (ctx context.Context , nodeID ids.NodeID , msg []byte ) {
117
- if err := r .handler .AppGossip (ctx , nodeID , msg ); err != nil {
118
- r .log .Debug ("failed to handle message" ,
119
- zap .Stringer ("messageOp" , message .AppGossipOp ),
120
- zap .Stringer ("nodeID" , nodeID ),
121
- zap .Uint64 ("handlerID" , r .handlerID ),
122
- zap .Binary ("message" , msg ),
123
- )
124
- }
125
- }
126
-
127
116
// CrossChainAppRequest calls the underlying handler and sends back the response
128
117
// to chainID
129
118
func (r * responder ) CrossChainAppRequest (ctx context.Context , chainID ids.ID , requestID uint32 , deadline time.Time , request []byte ) error {
130
- appResponse , err := r .handler .CrossChainAppRequest (ctx , chainID , deadline , request )
119
+ appResponse , err := r .Handler .CrossChainAppRequest (ctx , chainID , deadline , request )
131
120
if err != nil {
132
121
r .log .Debug ("failed to handle message" ,
133
122
zap .Stringer ("messageOp" , message .CrossChainAppRequestOp ),
0 commit comments