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
ad9305f6
Unverified
Commit
ad9305f6
authored
Jun 20, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Hook peerApplicationScorer into p2p/node
parent
e31c3dab
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
14 deletions
+60
-14
app_scores.go
op-node/p2p/app_scores.go
+34
-0
config.go
op-node/p2p/config.go
+2
-2
gossip.go
op-node/p2p/gossip.go
+1
-1
host.go
op-node/p2p/host.go
+1
-1
node.go
op-node/p2p/node.go
+17
-5
peer_scores.go
op-node/p2p/peer_scores.go
+4
-4
prepared.go
op-node/p2p/prepared.go
+1
-1
No files found.
op-node/p2p/app_scores.go
View file @
ad9305f6
...
...
@@ -15,6 +15,15 @@ type ScoreBook interface {
SetScore
(
id
peer
.
ID
,
diff
store
.
ScoreDiff
)
(
store
.
PeerScores
,
error
)
}
type
ApplicationScorer
interface
{
ApplicationScore
(
id
peer
.
ID
)
float64
onValidResponse
(
id
peer
.
ID
)
onResponseError
(
id
peer
.
ID
)
onRejectedPayload
(
id
peer
.
ID
)
start
()
stop
()
}
type
peerApplicationScorer
struct
{
ctx
context
.
Context
cancelFunc
context
.
CancelFunc
...
...
@@ -27,6 +36,8 @@ type peerApplicationScorer struct {
done
sync
.
WaitGroup
}
var
_
ApplicationScorer
=
(
*
peerApplicationScorer
)(
nil
)
func
newPeerApplicationScorer
(
ctx
context
.
Context
,
logger
log
.
Logger
,
clock
clock
.
Clock
,
params
*
ApplicationScoreParams
,
scorebook
ScoreBook
,
connectedPeers
func
()
[]
peer
.
ID
)
*
peerApplicationScorer
{
ctx
,
cancelFunc
:=
context
.
WithCancel
(
ctx
)
return
&
peerApplicationScorer
{
...
...
@@ -115,3 +126,26 @@ func (s *peerApplicationScorer) stop() {
s
.
cancelFunc
()
s
.
done
.
Wait
()
}
type
noopApplicationScorer
struct
{}
func
(
n
*
noopApplicationScorer
)
ApplicationScore
(
_
peer
.
ID
)
float64
{
return
0
}
func
(
n
*
noopApplicationScorer
)
onValidResponse
(
_
peer
.
ID
)
{
}
func
(
n
*
noopApplicationScorer
)
onResponseError
(
_
peer
.
ID
)
{
}
func
(
n
*
noopApplicationScorer
)
onRejectedPayload
(
_
peer
.
ID
)
{
}
func
(
n
*
noopApplicationScorer
)
start
()
{
}
func
(
n
*
noopApplicationScorer
)
stop
()
{
}
var
_
ApplicationScorer
=
(
*
noopApplicationScorer
)(
nil
)
op-node/p2p/config.go
View file @
ad9305f6
...
...
@@ -138,11 +138,11 @@ func (conf *Config) Disabled() bool {
return
conf
.
DisableP2P
}
func
(
conf
*
Config
)
PeerScoringParams
()
*
pubsub
.
PeerScore
Params
{
func
(
conf
*
Config
)
PeerScoringParams
()
*
Scoring
Params
{
if
conf
.
ScoringParams
==
nil
{
return
nil
}
return
&
conf
.
ScoringParams
.
PeerScoring
return
conf
.
ScoringParams
}
func
(
conf
*
Config
)
BanPeers
()
bool
{
...
...
op-node/p2p/gossip.go
View file @
ad9305f6
...
...
@@ -51,7 +51,7 @@ var MessageDomainInvalidSnappy = [4]byte{0, 0, 0, 0}
var
MessageDomainValidSnappy
=
[
4
]
byte
{
1
,
0
,
0
,
0
}
type
GossipSetupConfigurables
interface
{
PeerScoringParams
()
*
pubsub
.
PeerScore
Params
PeerScoringParams
()
*
Scoring
Params
// ConfigureGossip creates configuration options to apply to the GossipSub setup
ConfigureGossip
(
rollupCfg
*
rollup
.
Config
)
[]
pubsub
.
Option
}
...
...
op-node/p2p/host.go
View file @
ad9305f6
...
...
@@ -149,7 +149,7 @@ func (conf *Config) Host(log log.Logger, reporter metrics.Reporter, metrics Host
var
scoreRetention
time
.
Duration
if
peerScoreParams
!=
nil
{
// Use the same retention period as gossip will if available
scoreRetention
=
peerScoreParams
.
RetainScore
scoreRetention
=
peerScoreParams
.
PeerScoring
.
RetainScore
}
else
{
// Disable score GC if peer scoring is disabled
scoreRetention
=
0
...
...
op-node/p2p/node.go
View file @
ad9305f6
...
...
@@ -37,6 +37,7 @@ type NodeP2P struct {
connMgr
connmgr
.
ConnManager
// p2p conn manager, to keep a reliable number of peers, may be nil even with p2p enabled
peerMonitor
*
monitor
.
PeerMonitor
// peer monitor to disconnect bad peers, may be nil even with p2p enabled
store
store
.
ExtendedPeerstore
// peerstore of host, with extra bindings for scoring and banning
appScorer
ApplicationScorer
log
log
.
Logger
// the below components are all optional, and may be nil. They require the host to not be nil.
dv5Local
*
enode
.
LocalNode
// p2p discovery identity
...
...
@@ -89,6 +90,18 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.Config, l
n
.
gater
=
extra
.
ConnectionGater
()
n
.
connMgr
=
extra
.
ConnectionManager
()
}
eps
,
ok
:=
n
.
host
.
Peerstore
()
.
(
store
.
ExtendedPeerstore
)
if
!
ok
{
return
fmt
.
Errorf
(
"cannot init without extended peerstore: %w"
,
err
)
}
n
.
store
=
eps
scoreParams
:=
setup
.
PeerScoringParams
()
if
scoreParams
!=
nil
{
n
.
appScorer
=
newPeerApplicationScorer
(
resourcesCtx
,
log
,
clock
.
SystemClock
,
&
scoreParams
.
ApplicationScoring
,
eps
,
n
.
host
.
Network
()
.
Peers
)
}
else
{
n
.
appScorer
=
&
noopApplicationScorer
{}
}
// Activate the P2P req-resp sync if enabled by feature-flag.
if
setup
.
ReqRespSyncEnabled
()
{
n
.
syncCl
=
NewSyncClient
(
log
,
rollupCfg
,
n
.
host
.
NewStream
,
gossipIn
.
OnUnsafeL2Payload
,
metrics
)
...
...
@@ -112,11 +125,6 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.Config, l
n
.
host
.
SetStreamHandler
(
PayloadByNumberProtocolID
(
rollupCfg
.
L2ChainID
),
payloadByNumber
)
}
}
eps
,
ok
:=
n
.
host
.
Peerstore
()
.
(
store
.
ExtendedPeerstore
)
if
!
ok
{
return
fmt
.
Errorf
(
"cannot init without extended peerstore: %w"
,
err
)
}
n
.
store
=
eps
n
.
scorer
=
NewScorer
(
rollupCfg
,
eps
,
metrics
,
log
)
// notify of any new connections/streams/etc.
n
.
host
.
Network
()
.
Notify
(
NewNetworkNotifier
(
log
,
metrics
))
...
...
@@ -150,6 +158,7 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.Config, l
n
.
peerMonitor
=
monitor
.
NewPeerMonitor
(
resourcesCtx
,
log
,
clock
.
SystemClock
,
n
,
setup
.
BanThreshold
(),
setup
.
BanDuration
())
n
.
peerMonitor
.
Start
()
}
n
.
appScorer
.
start
()
}
return
nil
}
...
...
@@ -258,6 +267,9 @@ func (n *NodeP2P) Close() error {
}
}
}
if
n
.
appScorer
!=
nil
{
n
.
appScorer
.
stop
()
}
return
result
.
ErrorOrNil
()
}
...
...
op-node/p2p/peer_scores.go
View file @
ad9305f6
...
...
@@ -9,12 +9,12 @@ import (
func
ConfigurePeerScoring
(
gossipConf
GossipSetupConfigurables
,
scorer
Scorer
,
log
log
.
Logger
)
[]
pubsub
.
Option
{
// If we want to completely disable scoring config here, we can use the [peerScoringParams]
// to return early without returning any [pubsub.Option].
peerScoreParams
:=
gossipConf
.
PeerScoringParams
()
peerScoreThresholds
:=
NewPeerScoreThresholds
()
scoreParams
:=
gossipConf
.
PeerScoringParams
()
opts
:=
[]
pubsub
.
Option
{}
if
peerScoreParams
!=
nil
{
if
scoreParams
!=
nil
{
peerScoreThresholds
:=
NewPeerScoreThresholds
()
opts
=
[]
pubsub
.
Option
{
pubsub
.
WithPeerScore
(
peerScoreParams
,
&
peerScoreThresholds
),
pubsub
.
WithPeerScore
(
&
scoreParams
.
PeerScoring
,
&
peerScoreThresholds
),
pubsub
.
WithPeerScoreInspect
(
scorer
.
SnapshotHook
(),
peerScoreInspectFrequency
),
}
}
else
{
...
...
op-node/p2p/prepared.go
View file @
ad9305f6
...
...
@@ -69,7 +69,7 @@ func (p *Prepared) ConfigureGossip(rollupCfg *rollup.Config) []pubsub.Option {
}
}
func
(
p
*
Prepared
)
PeerScoringParams
()
*
pubsub
.
PeerScore
Params
{
func
(
p
*
Prepared
)
PeerScoringParams
()
*
Scoring
Params
{
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