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
b19f9486
Commit
b19f9486
authored
Mar 23, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix peer scorer band metrics on update
parent
ef5c1f77
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
peer_scorer.go
op-node/p2p/peer_scorer.go
+5
-0
peer_scorer_test.go
op-node/p2p/peer_scorer_test.go
+22
-3
No files found.
op-node/p2p/peer_scorer.go
View file @
b19f9486
...
@@ -117,6 +117,11 @@ func NewScorer(peerGater PeerGater, peerStore Peerstore, metricer GossipMetricer
...
@@ -117,6 +117,11 @@ func NewScorer(peerGater PeerGater, peerStore Peerstore, metricer GossipMetricer
func
(
s
*
scorer
)
SnapshotHook
()
pubsub
.
ExtendedPeerScoreInspectFn
{
func
(
s
*
scorer
)
SnapshotHook
()
pubsub
.
ExtendedPeerScoreInspectFn
{
return
func
(
m
map
[
peer
.
ID
]
*
pubsub
.
PeerScoreSnapshot
)
{
return
func
(
m
map
[
peer
.
ID
]
*
pubsub
.
PeerScoreSnapshot
)
{
scoreMap
:=
make
(
map
[
string
]
float64
)
scoreMap
:=
make
(
map
[
string
]
float64
)
// Zero out all bands.
for
_
,
b
:=
range
s
.
bandScoreThresholds
.
bands
{
scoreMap
[
b
.
band
]
=
0
}
// Now set the new scores.
for
id
,
snap
:=
range
m
{
for
id
,
snap
:=
range
m
{
band
:=
s
.
bandScoreThresholds
.
Bucket
(
snap
.
Score
)
band
:=
s
.
bandScoreThresholds
.
Bucket
(
snap
.
Score
)
scoreMap
[
band
]
+=
1
scoreMap
[
band
]
+=
1
...
...
op-node/p2p/peer_scorer_test.go
View file @
b19f9486
...
@@ -29,7 +29,7 @@ func (testSuite *PeerScorerTestSuite) SetupTest() {
...
@@ -29,7 +29,7 @@ func (testSuite *PeerScorerTestSuite) SetupTest() {
testSuite
.
mockGater
=
&
p2pMocks
.
PeerGater
{}
testSuite
.
mockGater
=
&
p2pMocks
.
PeerGater
{}
testSuite
.
mockStore
=
&
p2pMocks
.
Peerstore
{}
testSuite
.
mockStore
=
&
p2pMocks
.
Peerstore
{}
testSuite
.
mockMetricer
=
&
p2pMocks
.
GossipMetricer
{}
testSuite
.
mockMetricer
=
&
p2pMocks
.
GossipMetricer
{}
bandScorer
,
err
:=
p2p
.
NewBandScorer
(
"
0:graylist
;"
)
bandScorer
,
err
:=
p2p
.
NewBandScorer
(
"
-40:graylist;0:friend
;"
)
testSuite
.
NoError
(
err
)
testSuite
.
NoError
(
err
)
testSuite
.
bandScorer
=
bandScorer
testSuite
.
bandScorer
=
bandScorer
testSuite
.
logger
=
testlog
.
Logger
(
testSuite
.
T
(),
log
.
LvlError
)
testSuite
.
logger
=
testlog
.
Logger
(
testSuite
.
T
(),
log
.
LvlError
)
...
@@ -76,12 +76,13 @@ func (testSuite *PeerScorerTestSuite) TestScorer_SnapshotHook() {
...
@@ -76,12 +76,13 @@ func (testSuite *PeerScorerTestSuite) TestScorer_SnapshotHook() {
inspectFn
:=
scorer
.
SnapshotHook
()
inspectFn
:=
scorer
.
SnapshotHook
()
// Mock the peer gater call
// Mock the peer gater call
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
-
100
))
.
Return
(
nil
)
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
-
100
))
.
Return
(
nil
)
.
Once
()
// The metricer should then be called with the peer score band map
// The metricer should then be called with the peer score band map
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
map
[
string
]
float64
{
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
map
[
string
]
float64
{
"friend"
:
0
,
"graylist"
:
1
,
"graylist"
:
1
,
})
.
Return
(
nil
)
})
.
Return
(
nil
)
.
Once
()
// Apply the snapshot
// Apply the snapshot
snapshotMap
:=
map
[
peer
.
ID
]
*
pubsub
.
PeerScoreSnapshot
{
snapshotMap
:=
map
[
peer
.
ID
]
*
pubsub
.
PeerScoreSnapshot
{
...
@@ -90,6 +91,23 @@ func (testSuite *PeerScorerTestSuite) TestScorer_SnapshotHook() {
...
@@ -90,6 +91,23 @@ func (testSuite *PeerScorerTestSuite) TestScorer_SnapshotHook() {
},
},
}
}
inspectFn
(
snapshotMap
)
inspectFn
(
snapshotMap
)
// Change the peer score now to a different band
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
0
))
.
Return
(
nil
)
.
Once
()
// The metricer should then be called with the peer score band map
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
map
[
string
]
float64
{
"friend"
:
1
,
"graylist"
:
0
,
})
.
Return
(
nil
)
.
Once
()
// Apply the snapshot
snapshotMap
=
map
[
peer
.
ID
]
*
pubsub
.
PeerScoreSnapshot
{
peer
.
ID
(
"peer1"
)
:
{
Score
:
0
,
},
}
inspectFn
(
snapshotMap
)
}
}
// TestScorer_SnapshotHookBlocksPeer tests running the snapshot hook on the peer scorer with a peer score below the threshold.
// TestScorer_SnapshotHookBlocksPeer tests running the snapshot hook on the peer scorer with a peer score below the threshold.
...
@@ -109,6 +127,7 @@ func (testSuite *PeerScorerTestSuite) TestScorer_SnapshotHookBlocksPeer() {
...
@@ -109,6 +127,7 @@ func (testSuite *PeerScorerTestSuite) TestScorer_SnapshotHookBlocksPeer() {
// The metricer should then be called with the peer score band map
// The metricer should then be called with the peer score band map
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
map
[
string
]
float64
{
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
map
[
string
]
float64
{
"friend"
:
0
,
"graylist"
:
1
,
"graylist"
:
1
,
})
.
Return
(
nil
)
})
.
Return
(
nil
)
...
...
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