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
9766f38e
Unverified
Commit
9766f38e
authored
May 23, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Store gossip scores in extended peer store
parent
aef72764
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
16 deletions
+47
-16
host.go
op-node/p2p/host.go
+7
-1
ConnectionGater.go
op-node/p2p/mocks/ConnectionGater.go
+0
-14
Peerstore.go
op-node/p2p/mocks/Peerstore.go
+16
-0
peer_scorer.go
op-node/p2p/peer_scorer.go
+9
-0
peer_scorer_test.go
op-node/p2p/peer_scorer_test.go
+8
-0
peer_scores.go
op-node/p2p/peer_scores.go
+7
-1
No files found.
op-node/p2p/host.go
View file @
9766f38e
...
...
@@ -7,6 +7,7 @@ import (
"sync"
"time"
"github.com/ethereum-optimism/optimism/op-node/p2p/store"
libp2p
"github.com/libp2p/go-libp2p"
lconf
"github.com/libp2p/go-libp2p/config"
"github.com/libp2p/go-libp2p/core/connmgr"
...
...
@@ -132,11 +133,16 @@ func (conf *Config) Host(log log.Logger, reporter metrics.Reporter) (host.Host,
return
nil
,
fmt
.
Errorf
(
"failed to derive pubkey from network priv key: %w"
,
err
)
}
p
s
,
err
:=
pstoreds
.
NewPeerstore
(
context
.
Background
(),
conf
.
Store
,
pstoreds
.
DefaultOpts
())
baseP
s
,
err
:=
pstoreds
.
NewPeerstore
(
context
.
Background
(),
conf
.
Store
,
pstoreds
.
DefaultOpts
())
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to open peerstore: %w"
,
err
)
}
ps
,
err
:=
store
.
NewExtendedPeerstore
(
context
.
Background
(),
basePs
,
conf
.
Store
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to open extended peerstore: %w"
,
err
)
}
if
err
:=
ps
.
AddPrivKey
(
pid
,
conf
.
Priv
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to set up peerstore with priv key: %w"
,
err
)
}
...
...
op-node/p2p/mocks/ConnectionGater.go
View file @
9766f38e
...
...
@@ -142,20 +142,6 @@ func (_m *ConnectionGater) InterceptUpgraded(_a0 network.Conn) (bool, control.Di
return
r0
,
r1
}
// IsBlocked provides a mock function with given fields: p
func
(
_m
*
ConnectionGater
)
IsBlocked
(
p
peer
.
ID
)
bool
{
ret
:=
_m
.
Called
(
p
)
var
r0
bool
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
peer
.
ID
)
bool
);
ok
{
r0
=
rf
(
p
)
}
else
{
r0
=
ret
.
Get
(
0
)
.
(
bool
)
}
return
r0
}
// ListBlockedAddrs provides a mock function with given fields:
func
(
_m
*
ConnectionGater
)
ListBlockedAddrs
()
[]
net
.
IP
{
ret
:=
_m
.
Called
()
...
...
op-node/p2p/mocks/Peerstore.go
View file @
9766f38e
...
...
@@ -6,6 +6,8 @@ import (
mock
"github.com/stretchr/testify/mock"
peer
"github.com/libp2p/go-libp2p/core/peer"
store
"github.com/ethereum-optimism/optimism/op-node/p2p/store"
)
// Peerstore is an autogenerated mock type for the Peerstore type
...
...
@@ -43,6 +45,20 @@ func (_m *Peerstore) Peers() peer.IDSlice {
return
r0
}
// SetScore provides a mock function with given fields: _a0, _a1, _a2
func
(
_m
*
Peerstore
)
SetScore
(
_a0
peer
.
ID
,
_a1
store
.
ScoreType
,
_a2
float64
)
error
{
ret
:=
_m
.
Called
(
_a0
,
_a1
,
_a2
)
var
r0
error
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
peer
.
ID
,
store
.
ScoreType
,
float64
)
error
);
ok
{
r0
=
rf
(
_a0
,
_a1
,
_a2
)
}
else
{
r0
=
ret
.
Error
(
0
)
}
return
r0
}
type
mockConstructorTestingTNewPeerstore
interface
{
mock
.
TestingT
Cleanup
(
func
())
...
...
op-node/p2p/peer_scorer.go
View file @
9766f38e
...
...
@@ -6,6 +6,7 @@ import (
"strconv"
"strings"
"github.com/ethereum-optimism/optimism/op-node/p2p/store"
log
"github.com/ethereum/go-ethereum/log"
pubsub
"github.com/libp2p/go-libp2p-pubsub"
peer
"github.com/libp2p/go-libp2p/core/peer"
...
...
@@ -91,6 +92,8 @@ type Peerstore interface {
// Peers returns all of the peer IDs stored across all inner stores.
Peers
()
peer
.
IDSlice
SetScore
(
peer
.
ID
,
store
.
ScoreType
,
float64
)
error
}
// Scorer is a peer scorer that scores peers based on application-specific metrics.
...
...
@@ -123,6 +126,12 @@ func (s *scorer) SnapshotHook() pubsub.ExtendedPeerScoreInspectFn {
}
// Now set the new scores.
for
id
,
snap
:=
range
m
{
scores
:=
make
(
map
[
store
.
ScoreType
]
float64
)
scores
[
store
.
TypeGossip
]
=
snap
.
Score
if
err
:=
s
.
peerStore
.
SetScore
(
id
,
store
.
TypeGossip
,
snap
.
Score
);
err
!=
nil
{
s
.
log
.
Warn
(
"Unable to update peer gossip score"
,
"err"
,
err
)
}
band
:=
s
.
bandScoreThresholds
.
Bucket
(
snap
.
Score
)
scoreMap
[
band
]
+=
1
s
.
gater
.
Update
(
id
,
snap
.
Score
)
...
...
op-node/p2p/peer_scorer_test.go
View file @
9766f38e
...
...
@@ -5,6 +5,7 @@ import (
p2p
"github.com/ethereum-optimism/optimism/op-node/p2p"
p2pMocks
"github.com/ethereum-optimism/optimism/op-node/p2p/mocks"
"github.com/ethereum-optimism/optimism/op-node/p2p/store"
"github.com/ethereum-optimism/optimism/op-node/testlog"
log
"github.com/ethereum/go-ethereum/log"
pubsub
"github.com/libp2p/go-libp2p-pubsub"
...
...
@@ -78,6 +79,9 @@ func (testSuite *PeerScorerTestSuite) TestScorer_SnapshotHook() {
// Mock the peer gater call
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
-
100
))
.
Return
(
nil
)
.
Once
()
// Expect updating the peer store
testSuite
.
mockStore
.
On
(
"SetScore"
,
peer
.
ID
(
"peer1"
),
store
.
TypeGossip
,
float64
(
-
100
))
.
Return
(
nil
)
.
Once
()
// The metricer should then be called with the peer score band map
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
map
[
string
]
float64
{
"friend"
:
0
,
...
...
@@ -94,6 +98,8 @@ func (testSuite *PeerScorerTestSuite) TestScorer_SnapshotHook() {
// Change the peer score now to a different band
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
0
))
.
Return
(
nil
)
.
Once
()
// Expect updating the peer store
testSuite
.
mockStore
.
On
(
"SetScore"
,
peer
.
ID
(
"peer1"
),
store
.
TypeGossip
,
float64
(
0
))
.
Return
(
nil
)
.
Once
()
// The metricer should then be called with the peer score band map
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
map
[
string
]
float64
{
...
...
@@ -124,6 +130,8 @@ func (testSuite *PeerScorerTestSuite) TestScorer_SnapshotHookBlocksPeer() {
// Mock the peer gater call
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
-
101
))
.
Return
(
nil
)
// Expect updating the peer store
testSuite
.
mockStore
.
On
(
"SetScore"
,
peer
.
ID
(
"peer1"
),
store
.
TypeGossip
,
float64
(
-
101
))
.
Return
(
nil
)
.
Once
()
// The metricer should then be called with the peer score band map
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
map
[
string
]
float64
{
...
...
op-node/p2p/peer_scores.go
View file @
9766f38e
package
p2p
import
(
"github.com/ethereum-optimism/optimism/op-node/p2p/store"
log
"github.com/ethereum/go-ethereum/log"
pubsub
"github.com/libp2p/go-libp2p-pubsub"
host
"github.com/libp2p/go-libp2p/core/host"
...
...
@@ -14,8 +15,13 @@ func ConfigurePeerScoring(h host.Host, g ConnectionGater, gossipConf GossipSetup
peerScoreThresholds
:=
NewPeerScoreThresholds
()
banEnabled
:=
gossipConf
.
BanPeers
()
peerGater
:=
NewPeerGater
(
g
,
log
,
banEnabled
)
scorer
:=
NewScorer
(
peerGater
,
h
.
Peerstore
(),
m
,
gossipConf
.
PeerBandScorer
(),
log
)
opts
:=
[]
pubsub
.
Option
{}
eps
,
ok
:=
h
.
Peerstore
()
.
(
store
.
ExtendedPeerstore
)
if
!
ok
{
log
.
Warn
(
"Disabling peer scoring. Peerstore does not support peer scores"
)
return
opts
}
scorer
:=
NewScorer
(
peerGater
,
eps
,
m
,
gossipConf
.
PeerBandScorer
(),
log
)
// Check the app specific score since libp2p doesn't export it's [validate] function :/
if
peerScoreParams
!=
nil
&&
peerScoreParams
.
AppSpecificScore
!=
nil
{
opts
=
[]
pubsub
.
Option
{
...
...
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