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

1898 slashing violations consumer alsp integration test #4549

Merged
merged 11 commits into from
Jul 19, 2023
Prev Previous commit
Next Next commit
update test
  • Loading branch information
kc1116 committed Jul 10, 2023
commit c7675452368cddbfd467c956b42efae7ccff1e89
2 changes: 0 additions & 2 deletions network/alsp/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 6 additions & 12 deletions network/alsp/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package alspmgr_test

import (
"context"
"fmt"
"math"
"math/rand"
"sync"
Expand Down Expand Up @@ -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
Expand All @@ -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]}},
Expand All @@ -354,19 +353,14 @@ func TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration(t
}
unittest.RequireReturnsBefore(t, violationsWg.Wait, 100*time.Millisecond, "slashing violations not reported in time")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do the calls to report each violation need to be done async? This could introduce flakiness due to timeouts, while reporting the callbacks serially most likely wouldn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done async so that we can ensure all async components under the hood are working as expected (queue, locks, workers etc). This will not cause flakiness as there are no network operations happening, it's just building up a queue of violations that will eventually be processed.


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)
})

Expand Down