1- package rpc_inspector_test
1+ package rpc_inspector
22
33import (
44 "context"
@@ -23,14 +23,14 @@ import (
2323 "github.com/onflow/flow-go/network/p2p"
2424 "github.com/onflow/flow-go/network/p2p/inspector/validation"
2525 mockp2p "github.com/onflow/flow-go/network/p2p/mock"
26- "github.com/onflow/flow-go/network/p2p/p2pbuilder"
26+ inspectorbuilder "github.com/onflow/flow-go/network/p2p/p2pbuilder/inspector "
2727 p2ptest "github.com/onflow/flow-go/network/p2p/test"
2828 "github.com/onflow/flow-go/utils/unittest"
2929)
3030
31- // TestInspect_SafetyThreshold ensures that when RPC control message count is below the configured safety threshold the control message validation inspector
31+ // TestValidationInspector_SafetyThreshold ensures that when RPC control message count is below the configured safety threshold the control message validation inspector
3232// does not return any errors and validation is skipped.
33- func TestInspect_SafetyThreshold (t * testing.T ) {
33+ func TestValidationInspector_SafetyThreshold (t * testing.T ) {
3434 t .Parallel ()
3535 role := flow .RoleConsensus
3636 sporkID := unittest .IdentifierFixture ()
@@ -40,7 +40,7 @@ func TestInspect_SafetyThreshold(t *testing.T) {
4040 // if GRAFT/PRUNE message count is lower than safety threshold the RPC validation should pass
4141 safetyThreshold := uint64 (10 )
4242 // create our RPC validation inspector
43- inspectorConfig := p2pbuilder .DefaultRPCValidationConfig ()
43+ inspectorConfig := inspectorbuilder .DefaultRPCValidationConfig ()
4444 inspectorConfig .NumberOfWorkers = 1
4545 inspectorConfig .GraftValidationCfg .SafetyThreshold = safetyThreshold
4646 inspectorConfig .PruneValidationCfg .SafetyThreshold = safetyThreshold
@@ -100,9 +100,9 @@ func TestInspect_SafetyThreshold(t *testing.T) {
100100 }, 2 * time .Second , 10 * time .Millisecond )
101101}
102102
103- // TestInspect_DiscardThreshold ensures that when RPC control message count is above the configured discard threshold the control message validation inspector
103+ // TestValidationInspector_DiscardThreshold ensures that when RPC control message count is above the configured discard threshold the control message validation inspector
104104// returns the expected error.
105- func TestInspect_DiscardThreshold (t * testing.T ) {
105+ func TestValidationInspector_DiscardThreshold (t * testing.T ) {
106106 t .Parallel ()
107107 role := flow .RoleConsensus
108108 sporkID := unittest .IdentifierFixture ()
@@ -112,7 +112,7 @@ func TestInspect_DiscardThreshold(t *testing.T) {
112112 // if GRAFT/PRUNE message count is higher than discard threshold the RPC validation should fail and expected error should be returned
113113 discardThreshold := uint64 (10 )
114114 // create our RPC validation inspector
115- inspectorConfig := p2pbuilder .DefaultRPCValidationConfig ()
115+ inspectorConfig := inspectorbuilder .DefaultRPCValidationConfig ()
116116 inspectorConfig .NumberOfWorkers = 1
117117 inspectorConfig .GraftValidationCfg .DiscardThreshold = discardThreshold
118118 inspectorConfig .PruneValidationCfg .DiscardThreshold = discardThreshold
@@ -170,8 +170,8 @@ func TestInspect_DiscardThreshold(t *testing.T) {
170170 unittest .RequireCloseBefore (t , done , 2 * time .Second , "failed to inspect RPC messages on time" )
171171}
172172
173- // TestInspect_RateLimitedPeer ensures that the control message validation inspector rate limits peers per control message type as expected.
174- func TestInspect_RateLimitedPeer (t * testing.T ) {
173+ // TestValidationInspector_RateLimitedPeer ensures that the control message validation inspector rate limits peers per control message type as expected.
174+ func TestValidationInspector_RateLimitedPeer (t * testing.T ) {
175175 t .Parallel ()
176176 role := flow .RoleConsensus
177177 sporkID := unittest .IdentifierFixture ()
@@ -180,7 +180,7 @@ func TestInspect_RateLimitedPeer(t *testing.T) {
180180 signalerCtx := irrecoverable .NewMockSignalerContext (t , ctx )
181181
182182 // create our RPC validation inspector
183- inspectorConfig := p2pbuilder .DefaultRPCValidationConfig ()
183+ inspectorConfig := inspectorbuilder .DefaultRPCValidationConfig ()
184184 inspectorConfig .NumberOfWorkers = 1
185185
186186 // here we set the message count to the amount of flow channels
@@ -245,8 +245,8 @@ func TestInspect_RateLimitedPeer(t *testing.T) {
245245 unittest .RequireCloseBefore (t , done , 2 * time .Second , "failed to inspect RPC messages on time" )
246246}
247247
248- // TestInspect_InvalidTopicID ensures that when an RPC control message contains an invalid topic ID the expected error is logged.
249- func TestInspect_InvalidTopicID (t * testing.T ) {
248+ // TestValidationInspector_InvalidTopicID ensures that when an RPC control message contains an invalid topic ID the expected error is logged.
249+ func TestValidationInspector_InvalidTopicID (t * testing.T ) {
250250 t .Parallel ()
251251 role := flow .RoleConsensus
252252 sporkID := unittest .IdentifierFixture ()
@@ -255,7 +255,7 @@ func TestInspect_InvalidTopicID(t *testing.T) {
255255 signalerCtx := irrecoverable .NewMockSignalerContext (t , ctx )
256256 // if GRAFT/PRUNE message count is higher than discard threshold the RPC validation should fail and expected error should be returned
257257 // create our RPC validation inspector
258- inspectorConfig := p2pbuilder .DefaultRPCValidationConfig ()
258+ inspectorConfig := inspectorbuilder .DefaultRPCValidationConfig ()
259259 inspectorConfig .PruneValidationCfg .SafetyThreshold = 0
260260 inspectorConfig .GraftValidationCfg .SafetyThreshold = 0
261261 inspectorConfig .NumberOfWorkers = 1
@@ -328,21 +328,3 @@ func TestInspect_InvalidTopicID(t *testing.T) {
328328
329329 unittest .RequireCloseBefore (t , done , 5 * time .Second , "failed to inspect RPC messages on time" )
330330}
331-
332- // StartNodesAndEnsureConnected starts the victim and spammer node and ensures they are both connected.
333- func startNodesAndEnsureConnected (t * testing.T , ctx irrecoverable.SignalerContext , nodes []p2p.LibP2PNode , sporkID flow.Identifier ) {
334- p2ptest .StartNodes (t , ctx , nodes , 5 * time .Second )
335- // prior to the test we should ensure that spammer and victim connect.
336- // this is vital as the spammer will circumvent the normal pubsub subscription mechanism and send iHAVE messages directly to the victim.
337- // without a prior connection established, directly spamming pubsub messages may cause a race condition in the pubsub implementation.
338- p2ptest .EnsureConnected (t , ctx , nodes )
339- p2ptest .EnsurePubsubMessageExchange (t , ctx , nodes , func () (interface {}, channels.Topic ) {
340- blockTopic := channels .TopicFromChannel (channels .PushBlocks , sporkID )
341- return unittest .ProposalFixture (), blockTopic
342- })
343- }
344-
345- func stopNodesAndInspector (t * testing.T , cancel context.CancelFunc , nodes []p2p.LibP2PNode , inspector * validation.ControlMsgValidationInspector ) {
346- p2ptest .StopNodes (t , nodes , cancel , 5 * time .Second )
347- unittest .RequireComponentsDoneBefore (t , time .Second , inspector )
348- }
0 commit comments