Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Networking] GossipSub iWant Flooding Mitigation #4574

Merged
merged 49 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0093a47
add iWant control message validation
kc1116 Jul 19, 2023
41ef40b
Update component.go
kc1116 Jul 25, 2023
5cf8b9d
Merge branch 'master' of github.com:onflow/flow-go into khalil/6472-i…
kc1116 Jul 25, 2023
322aee5
Update network/p2p/inspector/validation/control_message_validation_in…
kc1116 Aug 1, 2023
03a4423
add rpc control tracking to control message validation inspector
kc1116 Aug 16, 2023
85f63c6
distribute invalid control message notification for iwant errs
kc1116 Aug 16, 2023
3e99842
sample all message IDs
kc1116 Aug 16, 2023
2e6c88a
add duplicate messageID and cache miss threshold tests
kc1116 Aug 16, 2023
b745ea3
Delete export_report.json
kc1116 Aug 16, 2023
acf9486
Merge branch 'master' into khalil/6472-iwant-flooding-detection
kc1116 Aug 16, 2023
3ff2eaf
update WithIWant godoc and var names
kc1116 Aug 22, 2023
eccb7a1
allow a threshold of duplicate message ids
kc1116 Aug 22, 2023
38d5caf
update threshold comparisons
kc1116 Aug 22, 2023
704a20d
Update network/p2p/inspector/validation/control_message_validation_in…
kc1116 Aug 22, 2023
26a7159
Update network/p2p/inspector/validation/errors.go
kc1116 Aug 22, 2023
c815a12
Update network/p2p/inspector/validation/errors.go
kc1116 Aug 22, 2023
9c09799
Merge branch 'khalil/6472-iwant-flooding-detection' of github.com:onf…
kc1116 Aug 22, 2023
d9c7970
add round trip tests for new errors
kc1116 Aug 22, 2023
bb87e90
add happy path tests for util dup str tracker
kc1116 Aug 22, 2023
e3f7fb8
Update network/p2p/tracer/internal/rpc_sent_tracker.go
kc1116 Aug 22, 2023
3b7aa43
Merge branch 'khalil/6472-iwant-flooding-detection' of github.com:onf…
kc1116 Aug 22, 2023
7721c00
distribute notif only for expected errors
kc1116 Aug 22, 2023
48b8fa1
Update rpc_sent_tracker.go
kc1116 Aug 22, 2023
c0b999a
Merge branch 'master' into khalil/6472-iwant-flooding-detection
kc1116 Aug 22, 2023
848a708
add trace level log to improve debugging
kc1116 Aug 24, 2023
efdeb97
add debug log with cache miss and duplicate counts
kc1116 Aug 24, 2023
c9e1dab
fix flag
kc1116 Aug 24, 2023
fb521fc
add logging.KeyNetworkingSecurity to all error logs
kc1116 Aug 24, 2023
ba7406e
Update config/default-config.yml
kc1116 Aug 24, 2023
6d226ad
Update insecure/corruptlibp2p/fixtures.go
kc1116 Aug 24, 2023
acb84a0
rename inspectDisseminatedNotif -> inspectDisseminatedNotifyFunc
kc1116 Aug 24, 2023
4090cb0
move utils to utils file
kc1116 Aug 24, 2023
45e77ff
Update validation_inspector_test.go
kc1116 Aug 24, 2023
a6d9eaa
move utils to utils file
kc1116 Aug 24, 2023
130fc6b
Merge branch 'khalil/6472-iwant-flooding-detection' of github.com:onf…
kc1116 Aug 24, 2023
e249547
Update network/p2p/inspector/validation/control_message_validation_in…
kc1116 Aug 24, 2023
1f71d13
Merge branch 'master' into khalil/6472-iwant-flooding-detection
kc1116 Aug 24, 2023
eb6434d
fix test
kc1116 Aug 24, 2023
e530edc
Merge branch 'master' into khalil/6472-iwant-flooding-detection
kc1116 Aug 24, 2023
897cb98
remove old test
kc1116 Aug 24, 2023
96c1d4f
improve geometric test flakiness
kc1116 Aug 27, 2023
2e3a710
improve echoengine test flakiness
kc1116 Aug 27, 2023
a865809
add 500 millisecond sleep before lauching second batch of goroutines
kc1116 Aug 27, 2023
88ab754
quarantine flaky tests
kc1116 Aug 28, 2023
8150c52
Update decay_test.go
kc1116 Aug 28, 2023
367b94c
Update decay_test.go
kc1116 Aug 28, 2023
37cfa4d
Update echoengine_test.go
kc1116 Aug 29, 2023
7c1d963
Update validation_inspector_test.go
kc1116 Aug 29, 2023
a4fcdb5
Update validation_inspector_test.go
kc1116 Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,8 @@ func (builder *FlowAccessNodeBuilder) initPublicLibp2pNode(networkKey crypto.Pri
&p2p.DisallowListCacheConfig{
MaxSize: builder.FlowConfig.NetworkConfig.DisallowListNotificationCacheSize,
Metrics: metrics.DisallowListCacheMetricsFactory(builder.HeroCacheMetricsFactory(), network.PublicNetwork),
}).
},
meshTracer).
SetBasicResolver(builder.Resolver).
SetSubscriptionFilter(
subscription.NewRoleBasedFilter(
Expand Down
3 changes: 2 additions & 1 deletion cmd/observer/node_builder/observer_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ func (builder *ObserverServiceBuilder) initPublicLibp2pNode(networkKey crypto.Pr
&p2p.DisallowListCacheConfig{
MaxSize: builder.FlowConfig.NetworkConfig.DisallowListNotificationCacheSize,
Metrics: metrics.DisallowListCacheMetricsFactory(builder.HeroCacheMetricsFactory(), network.PublicNetwork),
}).
},
meshTracer).
SetSubscriptionFilter(
subscription.NewRoleBasedFilter(
subscription.UnstakedRole, builder.IdentityProvider,
Expand Down
7 changes: 7 additions & 0 deletions config/default-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ network-config:
ihave-async-inspection-sample-size-percentage: .10
# Max number of ihave messages in a sample to be inspected
ihave-max-sample-size: 100

# Max number of iwant messages in a sample to be inspected
gossipsub-rpc-iwant-max-sample-size: 1_000_000
# The allowed threshold of iWant messages received without a corresponding tracked iHave message that was sent
gossipsub-rpc-iwant-cache-miss-threshold: .5
# The max allowed duplicate message IDs in a single iWant control message
gossipsub-rpc-iwant-duplicate-message-id-threshold: .15
# RPC metrics observer inspector configs
# The number of metrics inspector pool workers
gossipsub-rpc-metrics-inspector-workers: 1
Expand Down
3 changes: 2 additions & 1 deletion follower/follower_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ func (builder *FollowerServiceBuilder) initPublicLibp2pNode(networkKey crypto.Pr
&p2p.DisallowListCacheConfig{
MaxSize: builder.FlowConfig.NetworkConfig.DisallowListNotificationCacheSize,
Metrics: metrics.DisallowListCacheMetricsFactory(builder.HeroCacheMetricsFactory(), network.PublicNetwork),
}).
},
meshTracer).
SetSubscriptionFilter(
subscription.NewRoleBasedFilter(
subscription.UnstakedRole, builder.IdentityProvider,
Expand Down
17 changes: 13 additions & 4 deletions insecure/corruptlibp2p/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,21 @@ func WithIHave(msgCount, msgSize int, topicId string) GossipSubCtrlOption {
}

// WithIWant adds iWant control messages of the given size and number to the control message.
func WithIWant(msgCount, msgSize int) GossipSubCtrlOption {
// The message IDs are generated randomly.
// Args:
//
// msgCount: number of iWant messages to add.
// msgIdsPerIWant: number of message IDs to add to each iWant message.
//
// Returns:
// A GossipSubCtrlOption that adds iWant messages to the control message.
// Example: WithIWant(2, 3) will add 2 iWant messages, each with 3 message IDs.
func WithIWant(iWantCount int, msgIdsPerIWant int) GossipSubCtrlOption {
return func(msg *pubsubpb.ControlMessage) {
iWants := make([]*pubsubpb.ControlIWant, msgCount)
for i := 0; i < msgCount; i++ {
iWants := make([]*pubsubpb.ControlIWant, iWantCount)
for i := 0; i < iWantCount; i++ {
iWants[i] = &pubsubpb.ControlIWant{
MessageIDs: GossipSubMessageIdsFixture(msgSize),
MessageIDs: GossipSubMessageIdsFixture(msgIdsPerIWant),
}
}
msg.Iwant = iWants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestMetricsInspector_ObserveRPC(t *testing.T) {
nodes := []p2p.LibP2PNode{victimNode, spammer.SpammerNode}
startNodesAndEnsureConnected(t, signalerCtx, nodes, sporkID)
spammer.Start(t)
defer stopNodesAndInspector(t, cancel, nodes, metricsInspector)
defer stopTestComponents(t, cancel, nodes, metricsInspector)
// prepare to spam - generate control messages
ctlMsgs := spammer.GenerateCtlMessages(controlMessageCount,
corruptlibp2p.WithGraft(messageCount, channels.PushBlocks.String()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ package rpc_inspector

import (
"context"
"fmt"
"math/rand"
"testing"
"time"

mockery "github.com/stretchr/testify/mock"

"github.com/onflow/flow-go/config"
"github.com/onflow/flow-go/insecure/corruptlibp2p"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/irrecoverable"
"github.com/onflow/flow-go/module/metrics"
"github.com/onflow/flow-go/network/channels"
"github.com/onflow/flow-go/network/p2p"
mockp2p "github.com/onflow/flow-go/network/p2p/mock"
p2ptest "github.com/onflow/flow-go/network/p2p/test"
"github.com/onflow/flow-go/network/p2p/tracer"
"github.com/onflow/flow-go/utils/unittest"
)

Expand All @@ -26,7 +36,54 @@ func startNodesAndEnsureConnected(t *testing.T, ctx irrecoverable.SignalerContex
})
}

func stopNodesAndInspector(t *testing.T, cancel context.CancelFunc, nodes []p2p.LibP2PNode, inspector p2p.GossipSubRPCInspector) {
func stopTestComponents(t *testing.T, cancel context.CancelFunc, nodes []p2p.LibP2PNode, components ...module.ReadyDoneAware) {
p2ptest.StopNodes(t, nodes, cancel)
unittest.RequireComponentsDoneBefore(t, time.Second, inspector)
unittest.RequireComponentsDoneBefore(t, time.Second, components...)
}

func randomClusterPrefixedTopic() channels.Topic {
return channels.Topic(channels.SyncCluster(flow.ChainID(fmt.Sprintf("%d", rand.Uint64()))))
}

type onNotificationDissemination func(spammer *corruptlibp2p.GossipSubRouterSpammer) func(args mockery.Arguments)
type mockDistributorOption func(*mockp2p.GossipSubInspectorNotificationDistributor, *corruptlibp2p.GossipSubRouterSpammer)

func withExpectedNotificationDissemination(expectedNumOfTotalNotif int, f onNotificationDissemination) mockDistributorOption {
return func(distributor *mockp2p.GossipSubInspectorNotificationDistributor, spammer *corruptlibp2p.GossipSubRouterSpammer) {
distributor.
On("Distribute", mockery.Anything).
Times(expectedNumOfTotalNotif).
Run(f(spammer)).
Return(nil)
}
}

// mockDistributorReadyDoneAware mocks the Ready and Done methods of the distributor to return a channel that is already closed,
// so that the distributor is considered ready and done when the test needs.
func mockDistributorReadyDoneAware(d *mockp2p.GossipSubInspectorNotificationDistributor) {
d.On("Start", mockery.Anything).Return().Maybe()
d.On("Ready").Return(func() <-chan struct{} {
ch := make(chan struct{})
close(ch)
return ch
}()).Maybe()
d.On("Done").Return(func() <-chan struct{} {
ch := make(chan struct{})
close(ch)
return ch
}()).Maybe()
}

func meshTracerFixture(flowConfig *config.FlowConfig, idProvider module.IdentityProvider) *tracer.GossipSubMeshTracer {
meshTracerCfg := &tracer.GossipSubMeshTracerConfig{
Logger: unittest.Logger(),
Metrics: metrics.NewNoopCollector(),
IDProvider: idProvider,
LoggerInterval: time.Second,
HeroCacheMetricsFactory: metrics.NewNoopHeroCacheMetricsFactory(),
RpcSentTrackerCacheSize: flowConfig.NetworkConfig.GossipSubConfig.RPCSentTrackerCacheSize,
RpcSentTrackerWorkerQueueCacheSize: flowConfig.NetworkConfig.GossipSubConfig.RPCSentTrackerQueueCacheSize,
RpcSentTrackerNumOfWorkers: flowConfig.NetworkConfig.GossipSubConfig.RpcSentTrackerNumOfWorkers,
}
return tracer.NewGossipSubMeshTracer(meshTracerCfg)
}
Loading
Loading