Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
81a51448
Commit
81a51448
authored
Mar 23, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix peer gater logs
parent
ef5c1f77
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
2 deletions
+11
-2
peer_gater.go
op-node/p2p/peer_gater.go
+5
-2
peer_gater_test.go
op-node/p2p/peer_gater_test.go
+6
-0
No files found.
op-node/p2p/peer_gater.go
View file @
81a51448
...
@@ -40,15 +40,18 @@ func NewPeerGater(connGater ConnectionGater, log log.Logger, banEnabled bool) Pe
...
@@ -40,15 +40,18 @@ func NewPeerGater(connGater ConnectionGater, log log.Logger, banEnabled bool) Pe
func
(
s
*
gater
)
Update
(
id
peer
.
ID
,
score
float64
)
{
func
(
s
*
gater
)
Update
(
id
peer
.
ID
,
score
float64
)
{
// Check if the peer score is below the threshold
// Check if the peer score is below the threshold
// If so, we need to block the peer
// If so, we need to block the peer
isAlreadyBlocked
:=
slices
.
Contains
(
s
.
connGater
.
ListBlockedPeers
(),
id
)
if
score
<
PeerScoreThreshold
&&
s
.
banEnabled
{
if
score
<
PeerScoreThreshold
&&
s
.
banEnabled
{
s
.
log
.
Warn
(
"peer blocking enabled, blocking peer"
,
"id"
,
id
.
String
(),
"score"
,
score
)
if
!
isAlreadyBlocked
{
s
.
log
.
Warn
(
"peer blocking enabled, blocking peer"
,
"id"
,
id
.
String
(),
"score"
,
score
)
}
err
:=
s
.
connGater
.
BlockPeer
(
id
)
err
:=
s
.
connGater
.
BlockPeer
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
s
.
log
.
Warn
(
"connection gater failed to block peer"
,
"id"
,
id
.
String
(),
"err"
,
err
)
s
.
log
.
Warn
(
"connection gater failed to block peer"
,
"id"
,
id
.
String
(),
"err"
,
err
)
}
}
}
}
// Unblock peers whose score has recovered to an acceptable level
// Unblock peers whose score has recovered to an acceptable level
if
(
score
>
PeerScoreThreshold
)
&&
slices
.
Contains
(
s
.
connGater
.
ListBlockedPeers
(),
id
)
{
if
(
score
>
PeerScoreThreshold
)
&&
isAlreadyBlocked
{
err
:=
s
.
connGater
.
UnblockPeer
(
id
)
err
:=
s
.
connGater
.
UnblockPeer
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
s
.
log
.
Warn
(
"connection gater failed to unblock peer"
,
"id"
,
id
.
String
(),
"err"
,
err
)
s
.
log
.
Warn
(
"connection gater failed to unblock peer"
,
"id"
,
id
.
String
(),
"err"
,
err
)
...
...
op-node/p2p/peer_gater_test.go
View file @
81a51448
...
@@ -44,6 +44,9 @@ func (testSuite *PeerGaterTestSuite) TestPeerGaterUpdate() {
...
@@ -44,6 +44,9 @@ func (testSuite *PeerGaterTestSuite) TestPeerGaterUpdate() {
true
,
true
,
)
)
// Return an empty list of already blocked peers
testSuite
.
mockGater
.
On
(
"ListBlockedPeers"
)
.
Return
([]
peer
.
ID
{})
// Mock a connection gater peer block call
// Mock a connection gater peer block call
// Since the peer score is below the [PeerScoreThreshold] of -100,
// Since the peer score is below the [PeerScoreThreshold] of -100,
// the [BlockPeer] method should be called
// the [BlockPeer] method should be called
...
@@ -61,6 +64,9 @@ func (testSuite *PeerGaterTestSuite) TestPeerGaterUpdateNoBanning() {
...
@@ -61,6 +64,9 @@ func (testSuite *PeerGaterTestSuite) TestPeerGaterUpdateNoBanning() {
false
,
false
,
)
)
// Return an empty list of already blocked peers
testSuite
.
mockGater
.
On
(
"ListBlockedPeers"
)
.
Return
([]
peer
.
ID
{})
// Notice: [BlockPeer] should not be called since banning is not enabled
// Notice: [BlockPeer] should not be called since banning is not enabled
gater
.
Update
(
peer
.
ID
(
"peer1"
),
float64
(
-
100000
))
gater
.
Update
(
peer
.
ID
(
"peer1"
),
float64
(
-
100000
))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment