From 8bd1ae8d93020b1271547e8c98594cfa12eadaae Mon Sep 17 00:00:00 2001 From: Khalil Claybon Date: Mon, 10 Jul 2023 13:15:45 -0400 Subject: [PATCH 01/10] wip --- network/alsp/manager/manager.go | 5 +- network/alsp/manager/manager_test.go | 124 ++++++++++++++++++++++++++- network/slashing/consumer.go | 1 - 3 files changed, 123 insertions(+), 7 deletions(-) diff --git a/network/alsp/manager/manager.go b/network/alsp/manager/manager.go index 941407e2637..87dcd89cd11 100644 --- a/network/alsp/manager/manager.go +++ b/network/alsp/manager/manager.go @@ -332,8 +332,9 @@ func (m *MisbehaviorReportManager) onHeartbeat() error { FlowIds: flow.IdentifierList{id}, Cause: network.DisallowListedCauseAlsp, // sets the ALSP disallow listing cause on node }) + fmt.Println("DISALLOW-LISTED", record.OriginId, record.Penalty) } - + fmt.Println(record.OriginId, record.Penalty) // each time we decay the penalty by the decay speed, the penalty is a negative number, and the decay speed // is a positive number. So the penalty is getting closer to zero. // We use math.Min() to make sure the penalty is never positive. @@ -376,6 +377,7 @@ func (m *MisbehaviorReportManager) onHeartbeat() error { Float64("updated_penalty", penalty). Msg("spam record decayed") } + fmt.Println() return nil } @@ -425,7 +427,6 @@ func (m *MisbehaviorReportManager) processMisbehaviorReport(report internal.Repo // we should crash the node in this case to prevent further misbehavior reports from being lost and fix the bug. return fmt.Errorf("failed to apply penalty to the spam record: %w", err) } - lg.Debug().Float64("updated_penalty", updatedPenalty).Msg("misbehavior report handled") return nil } diff --git a/network/alsp/manager/manager_test.go b/network/alsp/manager/manager_test.go index 9b067e1ede8..81678f9a4a4 100644 --- a/network/alsp/manager/manager_test.go +++ b/network/alsp/manager/manager_test.go @@ -2,6 +2,8 @@ package alspmgr_test import ( "context" + "fmt" + "github.com/onflow/flow-go/network/slashing" "math" "math/rand" "sync" @@ -183,7 +185,7 @@ func TestHandleReportedMisbehavior_Cache_Integration(t *testing.T) { // TestHandleReportedMisbehavior_And_DisallowListing_Integration implements an end-to-end integration test for the // handling of reported misbehavior and disallow listing. // -// The test sets up 3 nodes, one victim, one honest, and one (alledged) spammer. +// The test sets up 3 nodes, one victim, one honest, and one (alleged) spammer. // Initially, the test ensures that all nodes are connected to each other. // Then, test imitates that victim node reports the spammer node for spamming. // The test generates enough spam reports to trigger the disallow-listing of the victim node. @@ -196,11 +198,11 @@ func TestHandleReportedMisbehavior_And_DisallowListing_Integration(t *testing.T) // this test is assessing the integration of the ALSP manager with the network. As the ALSP manager is an attribute // of the network, we need to configure the ALSP manager via the network configuration, and let the network create // the ALSP manager. - var victimSpamRecordCacheCache alsp.SpamRecordCache + var victimSpamRecordCache alsp.SpamRecordCache cfg.Opts = []alspmgr.MisbehaviorReportManagerOption{ alspmgr.WithSpamRecordsCacheFactory(func(logger zerolog.Logger, size uint32, metrics module.HeroCacheMetrics) alsp.SpamRecordCache { - victimSpamRecordCacheCache = internal.NewSpamRecordCache(size, logger, metrics, model.SpamRecordFactory()) - return victimSpamRecordCacheCache + victimSpamRecordCache = internal.NewSpamRecordCache(size, logger, metrics, model.SpamRecordFactory()) + return victimSpamRecordCache }), } @@ -266,6 +268,120 @@ func TestHandleReportedMisbehavior_And_DisallowListing_Integration(t *testing.T) p2ptest.EnsureNotConnectedBetweenGroups(t, ctx, []p2p.LibP2PNode{nodes[victimIndex]}, []p2p.LibP2PNode{nodes[spammerIndex]}) } +// TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration implements an end-to-end integration test for the +// handling of reported misbehavior from the slashing.ViolationsConsumer. +// +// The test sets up one victim, one honest, and one (alleged) spammer for each of the current slashing violations. +// Initially, the test ensures that all nodes are connected to each other. +// Then, test imitates the slashing violations consumer on the victim node reporting misbehavior's for each slashing violation. +// The test generates enough slashing violations to trigger the connection to each of the spamming nodes to be eventually pruned. +// The test ensures that the victim node is disconnected from all spammer nodes. +// The test ensures that despite attempting on connections, no inbound or outbound connections between the victim and +// the pruned spammer nodes are established. +func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t *testing.T) { + cfg := managerCfgFixture(t) + + // this test is assessing the integration of the ALSP manager with the network. As the ALSP manager is an attribute + // of the network, we need to configure the ALSP manager via the network configuration, and let the network create + // the ALSP manager. + var victimSpamRecordCache alsp.SpamRecordCache + cfg.Opts = []alspmgr.MisbehaviorReportManagerOption{ + alspmgr.WithSpamRecordsCacheFactory(func(logger zerolog.Logger, size uint32, metrics module.HeroCacheMetrics) alsp.SpamRecordCache { + victimSpamRecordCache = internal.NewSpamRecordCache(size, logger, metrics, model.SpamRecordFactory()) + return victimSpamRecordCache + }), + } + + slashingMisbehaviors := []network.Misbehavior{ + alsp.InvalidMessage, alsp.SenderEjected, alsp.UnauthorizedUnicastOnChannel, + alsp.UnauthorizedPublishOnChannel, alsp.UnknownMsgType, + } + + // create 1 victim node, 1 honest node and a node for each slashing violation + ids, nodes, _ := testutils.LibP2PNodeForMiddlewareFixture(t, len(slashingMisbehaviors)+2, + p2ptest.WithPeerManagerEnabled(p2ptest.PeerManagerConfigFixture(), nil)) + mws, _ := testutils.MiddlewareFixtures(t, ids, nodes, testutils.MiddlewareConfigFixture(t), mocknetwork.NewViolationsConsumer(t)) + networkCfg := testutils.NetworkConfigFixture(t, *ids[0], ids, mws[0], p2p.WithAlspConfig(cfg)) + victimNetwork, err := p2p.NewNetwork(networkCfg) + require.NoError(t, err) + + // create slashing violations consumer with victim node network providing the network.MisbehaviorReportConsumer interface + violationsConsumer := slashing.NewSlashingViolationsConsumer(unittest.Logger(), metrics.NewNoopCollector(), victimNetwork) + mws[0].SetSlashingViolationsConsumer(violationsConsumer) + + ctx, cancel := context.WithCancel(context.Background()) + signalerCtx := irrecoverable.NewMockSignalerContext(t, ctx) + testutils.StartNodesAndNetworks(signalerCtx, t, nodes, []network.Network{victimNetwork}, 100*time.Millisecond) + defer testutils.StopComponents[p2p.LibP2PNode](t, nodes, 100*time.Millisecond) + defer cancel() + + p2ptest.LetNodesDiscoverEachOther(t, ctx, nodes, ids) + // initially victim and spammer should be able to connect to each other. + p2ptest.TryConnectionAndEnsureConnected(t, ctx, nodes) + + // each slashing violation func is mapped to a violation with the identity of one of the misbehaving nodes + // index of the victim node in the nodes slice. + victimIndex := 0 + honestNodeIndex := 1 + invalidMessageIndex := 2 + senderEjectedIndex := 3 + unauthorizedUnicastOnChannelIndex := 4 + unauthorizedPublishOnChannelIndex := 5 + unknownMsgTypeIndex := 6 + slashingViolationTestCases := []struct { + violationsConsumerFunc func(violation *network.Violation) + violation *network.Violation + }{ + //{violationsConsumer.OnUnAuthorizedSenderError, &network.Violation{Identity: ids[invalidMessageIndex]}}, + //{violationsConsumer.OnSenderEjectedError, &network.Violation{Identity: ids[senderEjectedIndex]}}, + {violationsConsumer.OnUnauthorizedUnicastOnChannel, &network.Violation{Identity: ids[unauthorizedUnicastOnChannelIndex]}}, + {violationsConsumer.OnUnauthorizedPublishOnChannel, &network.Violation{Identity: ids[unauthorizedPublishOnChannelIndex]}}, + {violationsConsumer.OnUnknownMsgTypeError, &network.Violation{Identity: ids[unknownMsgTypeIndex]}}, + } + + violationsWg := sync.WaitGroup{} + violationCount := 120 + for _, testCase := range slashingViolationTestCases { + for i := 0; i < violationCount; i++ { + violationsWg.Add(1) + go func() { + defer violationsWg.Done() + testCase.violationsConsumerFunc(testCase.violation) + }() + } + } + unittest.RequireReturnsBefore(t, violationsWg.Wait, 100*time.Millisecond, "slashing violations not reported in time") + + time.Sleep(10 * time.Second) + + forEachMisbehavingNode := func(f func(i int)) { + //for misbehavingNodeIndex := 2; misbehavingNodeIndex <= len(nodes)-1; misbehavingNodeIndex++ { + // f(misbehavingNodeIndex) + //} + f(invalidMessageIndex) + f(senderEjectedIndex) + } + + // ensures connections to all misbehaving nodes are pruned + forEachMisbehavingNode(func(misbehavingNodeIndex int) { + fmt.Println(misbehavingNodeIndex) + p2ptest.RequireEventuallyNotConnected(t, []p2p.LibP2PNode{nodes[victimIndex]}, []p2p.LibP2PNode{nodes[misbehavingNodeIndex]}, 100*time.Millisecond, 2*time.Second) + }) + + // despite being disconnected from the victim node misbehaving nodes and the honest node are still connected. + forEachMisbehavingNode(func(misbehavingNodeIndex int) { + p2ptest.RequireConnectedEventually(t, []p2p.LibP2PNode{nodes[honestNodeIndex], nodes[misbehavingNodeIndex]}, 1*time.Millisecond, 100*time.Millisecond) + }) + + // despite pruning misbehaving nodes, ensure that (victim and honest) are still connected. + p2ptest.RequireConnectedEventually(t, []p2p.LibP2PNode{nodes[honestNodeIndex], nodes[victimIndex]}, 1*time.Millisecond, 100*time.Millisecond) + + // while misbehaving nodes are pruned, they cannot connect to the victim node. Also, the victim node cannot directly dial and connect to the misbehaving nodes until each node's peer score decays. + forEachMisbehavingNode(func(misbehavingNodeIndex int) { + p2ptest.EnsureNotConnectedBetweenGroups(t, ctx, []p2p.LibP2PNode{nodes[victimIndex]}, []p2p.LibP2PNode{nodes[misbehavingNodeIndex]}) + }) +} + // TestMisbehaviorReportMetrics tests the recording of misbehavior report metrics. // It checks that when a misbehavior report is received by the ALSP manager, the metrics are recorded. // It fails the test if the metrics are not recorded or if they are recorded incorrectly. diff --git a/network/slashing/consumer.go b/network/slashing/consumer.go index b7f09bb12b7..3ba8d656c21 100644 --- a/network/slashing/consumer.go +++ b/network/slashing/consumer.go @@ -88,7 +88,6 @@ func (c *Consumer) reportMisbehavior(misbehavior network.Misbehavior, violation Err(err). Str("peerID", violation.PeerID). Msg("failed to create misbehavior report") - } c.misbehaviorReportConsumer.ReportMisbehaviorOnChannel(violation.Channel, report) } From 1eed112554b0aa3f64127f3cfbd1c71715960eb2 Mon Sep 17 00:00:00 2001 From: Yahya Hassanzadeh Date: Mon, 10 Jul 2023 10:29:49 -0700 Subject: [PATCH 02/10] applies the fix --- network/alsp/manager/manager.go | 1 + network/alsp/manager/manager_test.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/network/alsp/manager/manager.go b/network/alsp/manager/manager.go index 87dcd89cd11..573d8d624ad 100644 --- a/network/alsp/manager/manager.go +++ b/network/alsp/manager/manager.go @@ -230,6 +230,7 @@ func (m *MisbehaviorReportManager) HandleMisbehaviorReport(channel channels.Chan Hex("misbehaving_id", logging.ID(report.OriginId())). Str("reason", report.Reason().String()). Float64("penalty", report.Penalty()).Logger() + lg.Trace().Msg("received misbehavior report") m.metrics.OnMisbehaviorReported(channel.String(), report.Reason().String()) nonce := [internal.NonceSize]byte{} diff --git a/network/alsp/manager/manager_test.go b/network/alsp/manager/manager_test.go index 81678f9a4a4..e053e4c8be3 100644 --- a/network/alsp/manager/manager_test.go +++ b/network/alsp/manager/manager_test.go @@ -3,13 +3,14 @@ package alspmgr_test import ( "context" "fmt" - "github.com/onflow/flow-go/network/slashing" "math" "math/rand" "sync" "testing" "time" + "github.com/onflow/flow-go/network/slashing" + "github.com/rs/zerolog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -343,6 +344,7 @@ func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t violationCount := 120 for _, testCase := range slashingViolationTestCases { for i := 0; i < violationCount; i++ { + testCase := testCase violationsWg.Add(1) go func() { defer violationsWg.Done() From c7675452368cddbfd467c956b42efae7ccff1e89 Mon Sep 17 00:00:00 2001 From: Khalil Claybon Date: Mon, 10 Jul 2023 13:38:02 -0400 Subject: [PATCH 03/10] update test --- network/alsp/manager/manager.go | 2 -- network/alsp/manager/manager_test.go | 18 ++++++------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/network/alsp/manager/manager.go b/network/alsp/manager/manager.go index 573d8d624ad..a49adee9146 100644 --- a/network/alsp/manager/manager.go +++ b/network/alsp/manager/manager.go @@ -333,9 +333,7 @@ func (m *MisbehaviorReportManager) onHeartbeat() error { FlowIds: flow.IdentifierList{id}, Cause: network.DisallowListedCauseAlsp, // sets the ALSP disallow listing cause on node }) - fmt.Println("DISALLOW-LISTED", record.OriginId, record.Penalty) } - fmt.Println(record.OriginId, record.Penalty) // each time we decay the penalty by the decay speed, the penalty is a negative number, and the decay speed // is a positive number. So the penalty is getting closer to zero. // We use math.Min() to make sure the penalty is never positive. diff --git a/network/alsp/manager/manager_test.go b/network/alsp/manager/manager_test.go index e053e4c8be3..c4793480a86 100644 --- a/network/alsp/manager/manager_test.go +++ b/network/alsp/manager/manager_test.go @@ -2,7 +2,6 @@ package alspmgr_test import ( "context" - "fmt" "math" "math/rand" "sync" @@ -317,7 +316,7 @@ func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t defer cancel() p2ptest.LetNodesDiscoverEachOther(t, ctx, nodes, ids) - // initially victim and spammer should be able to connect to each other. + // initially victim and misbehaving nodes should be able to connect to each other. p2ptest.TryConnectionAndEnsureConnected(t, ctx, nodes) // each slashing violation func is mapped to a violation with the identity of one of the misbehaving nodes @@ -333,8 +332,8 @@ func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t violationsConsumerFunc func(violation *network.Violation) violation *network.Violation }{ - //{violationsConsumer.OnUnAuthorizedSenderError, &network.Violation{Identity: ids[invalidMessageIndex]}}, - //{violationsConsumer.OnSenderEjectedError, &network.Violation{Identity: ids[senderEjectedIndex]}}, + {violationsConsumer.OnUnAuthorizedSenderError, &network.Violation{Identity: ids[invalidMessageIndex]}}, + {violationsConsumer.OnSenderEjectedError, &network.Violation{Identity: ids[senderEjectedIndex]}}, {violationsConsumer.OnUnauthorizedUnicastOnChannel, &network.Violation{Identity: ids[unauthorizedUnicastOnChannelIndex]}}, {violationsConsumer.OnUnauthorizedPublishOnChannel, &network.Violation{Identity: ids[unauthorizedPublishOnChannelIndex]}}, {violationsConsumer.OnUnknownMsgTypeError, &network.Violation{Identity: ids[unknownMsgTypeIndex]}}, @@ -354,19 +353,14 @@ func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t } unittest.RequireReturnsBefore(t, violationsWg.Wait, 100*time.Millisecond, "slashing violations not reported in time") - time.Sleep(10 * time.Second) - forEachMisbehavingNode := func(f func(i int)) { - //for misbehavingNodeIndex := 2; misbehavingNodeIndex <= len(nodes)-1; misbehavingNodeIndex++ { - // f(misbehavingNodeIndex) - //} - f(invalidMessageIndex) - f(senderEjectedIndex) + for misbehavingNodeIndex := 2; misbehavingNodeIndex <= len(nodes)-1; misbehavingNodeIndex++ { + f(misbehavingNodeIndex) + } } // ensures connections to all misbehaving nodes are pruned forEachMisbehavingNode(func(misbehavingNodeIndex int) { - fmt.Println(misbehavingNodeIndex) p2ptest.RequireEventuallyNotConnected(t, []p2p.LibP2PNode{nodes[victimIndex]}, []p2p.LibP2PNode{nodes[misbehavingNodeIndex]}, 100*time.Millisecond, 2*time.Second) }) From 1ed374cac7cb5a517da0a7372b45a4dfaa71399e Mon Sep 17 00:00:00 2001 From: Khalil Claybon Date: Mon, 10 Jul 2023 13:38:38 -0400 Subject: [PATCH 04/10] Update manager.go --- network/alsp/manager/manager.go | 1 - 1 file changed, 1 deletion(-) diff --git a/network/alsp/manager/manager.go b/network/alsp/manager/manager.go index a49adee9146..a1c3e25bf03 100644 --- a/network/alsp/manager/manager.go +++ b/network/alsp/manager/manager.go @@ -376,7 +376,6 @@ func (m *MisbehaviorReportManager) onHeartbeat() error { Float64("updated_penalty", penalty). Msg("spam record decayed") } - fmt.Println() return nil } From cce68b5bbedb20a758acbb46dcf056ff912a2144 Mon Sep 17 00:00:00 2001 From: Khalil Claybon Date: Mon, 10 Jul 2023 13:45:59 -0400 Subject: [PATCH 05/10] Update manager_test.go --- network/alsp/manager/manager_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/network/alsp/manager/manager_test.go b/network/alsp/manager/manager_test.go index c4793480a86..8563053b48d 100644 --- a/network/alsp/manager/manager_test.go +++ b/network/alsp/manager/manager_test.go @@ -359,20 +359,20 @@ func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t } } - // ensures connections to all misbehaving nodes are pruned + // ensures all misbehaving nodes are disconnected from the victim node forEachMisbehavingNode(func(misbehavingNodeIndex int) { p2ptest.RequireEventuallyNotConnected(t, []p2p.LibP2PNode{nodes[victimIndex]}, []p2p.LibP2PNode{nodes[misbehavingNodeIndex]}, 100*time.Millisecond, 2*time.Second) }) - // despite being disconnected from the victim node misbehaving nodes and the honest node are still connected. + // despite being disconnected from the victim node, misbehaving nodes and the honest node are still connected. forEachMisbehavingNode(func(misbehavingNodeIndex int) { p2ptest.RequireConnectedEventually(t, []p2p.LibP2PNode{nodes[honestNodeIndex], nodes[misbehavingNodeIndex]}, 1*time.Millisecond, 100*time.Millisecond) }) - // despite pruning misbehaving nodes, ensure that (victim and honest) are still connected. + // despite disconnecting misbehaving nodes, ensure that (victim and honest) are still connected. p2ptest.RequireConnectedEventually(t, []p2p.LibP2PNode{nodes[honestNodeIndex], nodes[victimIndex]}, 1*time.Millisecond, 100*time.Millisecond) - // while misbehaving nodes are pruned, they cannot connect to the victim node. Also, the victim node cannot directly dial and connect to the misbehaving nodes until each node's peer score decays. + // while misbehaving nodes are disconnected, they cannot connect to the victim node. Also, the victim node cannot directly dial and connect to the misbehaving nodes until each node's peer score decays. forEachMisbehavingNode(func(misbehavingNodeIndex int) { p2ptest.EnsureNotConnectedBetweenGroups(t, ctx, []p2p.LibP2PNode{nodes[victimIndex]}, []p2p.LibP2PNode{nodes[misbehavingNodeIndex]}) }) From ac19f5f1910833884f9e93ce2bdd8b20bab025a3 Mon Sep 17 00:00:00 2001 From: Khalil Claybon Date: Wed, 12 Jul 2023 18:37:05 -0400 Subject: [PATCH 06/10] Update network/alsp/manager/manager_test.go Co-authored-by: Yahya Hassanzadeh, Ph.D. --- network/alsp/manager/manager_test.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/network/alsp/manager/manager_test.go b/network/alsp/manager/manager_test.go index 8563053b48d..faba4d3f6a3 100644 --- a/network/alsp/manager/manager_test.go +++ b/network/alsp/manager/manager_test.go @@ -281,16 +281,6 @@ func TestHandleReportedMisbehavior_And_DisallowListing_Integration(t *testing.T) func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t *testing.T) { cfg := managerCfgFixture(t) - // this test is assessing the integration of the ALSP manager with the network. As the ALSP manager is an attribute - // of the network, we need to configure the ALSP manager via the network configuration, and let the network create - // the ALSP manager. - var victimSpamRecordCache alsp.SpamRecordCache - cfg.Opts = []alspmgr.MisbehaviorReportManagerOption{ - alspmgr.WithSpamRecordsCacheFactory(func(logger zerolog.Logger, size uint32, metrics module.HeroCacheMetrics) alsp.SpamRecordCache { - victimSpamRecordCache = internal.NewSpamRecordCache(size, logger, metrics, model.SpamRecordFactory()) - return victimSpamRecordCache - }), - } slashingMisbehaviors := []network.Misbehavior{ alsp.InvalidMessage, alsp.SenderEjected, alsp.UnauthorizedUnicastOnChannel, From c924c1c2ce89e746d3db112a26242bf3c28034f6 Mon Sep 17 00:00:00 2001 From: Khalil Claybon Date: Wed, 12 Jul 2023 18:38:57 -0400 Subject: [PATCH 07/10] Update network/alsp/manager/manager_test.go Co-authored-by: Yahya Hassanzadeh, Ph.D. --- network/alsp/manager/manager_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/network/alsp/manager/manager_test.go b/network/alsp/manager/manager_test.go index faba4d3f6a3..1feada8792e 100644 --- a/network/alsp/manager/manager_test.go +++ b/network/alsp/manager/manager_test.go @@ -279,7 +279,6 @@ func TestHandleReportedMisbehavior_And_DisallowListing_Integration(t *testing.T) // The test ensures that despite attempting on connections, no inbound or outbound connections between the victim and // the pruned spammer nodes are established. func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t *testing.T) { - cfg := managerCfgFixture(t) slashingMisbehaviors := []network.Misbehavior{ From ca4fc5bc8931186db12a5d49b45b3507fe03ef23 Mon Sep 17 00:00:00 2001 From: Khalil Claybon Date: Wed, 12 Jul 2023 18:39:19 -0400 Subject: [PATCH 08/10] Update network/alsp/manager/manager_test.go Co-authored-by: Yahya Hassanzadeh, Ph.D. --- network/alsp/manager/manager_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/alsp/manager/manager_test.go b/network/alsp/manager/manager_test.go index 1feada8792e..c0442662ab7 100644 --- a/network/alsp/manager/manager_test.go +++ b/network/alsp/manager/manager_test.go @@ -290,7 +290,7 @@ func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t ids, nodes, _ := testutils.LibP2PNodeForMiddlewareFixture(t, len(slashingMisbehaviors)+2, p2ptest.WithPeerManagerEnabled(p2ptest.PeerManagerConfigFixture(), nil)) mws, _ := testutils.MiddlewareFixtures(t, ids, nodes, testutils.MiddlewareConfigFixture(t), mocknetwork.NewViolationsConsumer(t)) - networkCfg := testutils.NetworkConfigFixture(t, *ids[0], ids, mws[0], p2p.WithAlspConfig(cfg)) + networkCfg := testutils.NetworkConfigFixture(t, *ids[0], ids, mws[0], p2p.WithAlspConfig(managerCfgFixture(t))) victimNetwork, err := p2p.NewNetwork(networkCfg) require.NoError(t, err) From f67f007425330b9e0b1b61607c6f8d74159e1e69 Mon Sep 17 00:00:00 2001 From: Khalil Claybon Date: Wed, 12 Jul 2023 18:39:49 -0400 Subject: [PATCH 09/10] Update network/alsp/manager/manager_test.go Co-authored-by: Yahya Hassanzadeh, Ph.D. --- network/alsp/manager/manager_test.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/network/alsp/manager/manager_test.go b/network/alsp/manager/manager_test.go index c0442662ab7..6c6db80f6bb 100644 --- a/network/alsp/manager/manager_test.go +++ b/network/alsp/manager/manager_test.go @@ -281,14 +281,13 @@ func TestHandleReportedMisbehavior_And_DisallowListing_Integration(t *testing.T) func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t *testing.T) { - slashingMisbehaviors := []network.Misbehavior{ - alsp.InvalidMessage, alsp.SenderEjected, alsp.UnauthorizedUnicastOnChannel, - alsp.UnauthorizedPublishOnChannel, alsp.UnknownMsgType, - } - // create 1 victim node, 1 honest node and a node for each slashing violation - ids, nodes, _ := testutils.LibP2PNodeForMiddlewareFixture(t, len(slashingMisbehaviors)+2, - p2ptest.WithPeerManagerEnabled(p2ptest.PeerManagerConfigFixture(), nil)) + ids, nodes, _ := testutils.LibP2PNodeForMiddlewareFixture(t, + 7) // creates 7 nodes (1 victim, 1 honest, 5 spammer nodes one for each slashing violation). + mws, _ := testutils.MiddlewareFixtures(t, ids, nodes, testutils.MiddlewareConfigFixture(t), mocknetwork.NewViolationsConsumer(t)) + networkCfg := testutils.NetworkConfigFixture(t, *ids[0], ids, mws[0], p2p.WithAlspConfig(managerCfgFixture(t))) + victimNetwork, err := p2p.NewNetwork(networkCfg) + require.NoError(t, err) mws, _ := testutils.MiddlewareFixtures(t, ids, nodes, testutils.MiddlewareConfigFixture(t), mocknetwork.NewViolationsConsumer(t)) networkCfg := testutils.NetworkConfigFixture(t, *ids[0], ids, mws[0], p2p.WithAlspConfig(managerCfgFixture(t))) victimNetwork, err := p2p.NewNetwork(networkCfg) From 07796e92950d9e446db0a24e2fc0d5d18ba31790 Mon Sep 17 00:00:00 2001 From: Khalil Claybon Date: Wed, 12 Jul 2023 18:41:42 -0400 Subject: [PATCH 10/10] Update manager_test.go --- network/alsp/manager/manager_test.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/network/alsp/manager/manager_test.go b/network/alsp/manager/manager_test.go index 6c6db80f6bb..b013688bf8b 100644 --- a/network/alsp/manager/manager_test.go +++ b/network/alsp/manager/manager_test.go @@ -8,8 +8,6 @@ import ( "testing" "time" - "github.com/onflow/flow-go/network/slashing" - "github.com/rs/zerolog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -32,6 +30,7 @@ import ( "github.com/onflow/flow-go/network/mocknetwork" "github.com/onflow/flow-go/network/p2p" p2ptest "github.com/onflow/flow-go/network/p2p/test" + "github.com/onflow/flow-go/network/slashing" "github.com/onflow/flow-go/utils/unittest" ) @@ -280,14 +279,8 @@ func TestHandleReportedMisbehavior_And_DisallowListing_Integration(t *testing.T) // the pruned spammer nodes are established. func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t *testing.T) { - // create 1 victim node, 1 honest node and a node for each slashing violation - ids, nodes, _ := testutils.LibP2PNodeForMiddlewareFixture(t, - 7) // creates 7 nodes (1 victim, 1 honest, 5 spammer nodes one for each slashing violation). - mws, _ := testutils.MiddlewareFixtures(t, ids, nodes, testutils.MiddlewareConfigFixture(t), mocknetwork.NewViolationsConsumer(t)) - networkCfg := testutils.NetworkConfigFixture(t, *ids[0], ids, mws[0], p2p.WithAlspConfig(managerCfgFixture(t))) - victimNetwork, err := p2p.NewNetwork(networkCfg) - require.NoError(t, err) + ids, nodes, _ := testutils.LibP2PNodeForMiddlewareFixture(t, 7) // creates 7 nodes (1 victim, 1 honest, 5 spammer nodes one for each slashing violation). mws, _ := testutils.MiddlewareFixtures(t, ids, nodes, testutils.MiddlewareConfigFixture(t), mocknetwork.NewViolationsConsumer(t)) networkCfg := testutils.NetworkConfigFixture(t, *ids[0], ids, mws[0], p2p.WithAlspConfig(managerCfgFixture(t))) victimNetwork, err := p2p.NewNetwork(networkCfg)