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
da2644c9
Commit
da2644c9
authored
Mar 07, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start tests
parent
05ec8aa0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
85 additions
and
33 deletions
+85
-33
p2p_flags.go
op-node/flags/p2p_flags.go
+9
-0
metrics.go
op-node/metrics/metrics.go
+0
-1
load_config.go
op-node/p2p/cli/load_config.go
+20
-6
config.go
op-node/p2p/config.go
+7
-7
gossip.go
op-node/p2p/gossip.go
+2
-6
node.go
op-node/p2p/node.go
+1
-1
peer_params.go
op-node/p2p/peer_params.go
+10
-11
peer_params_test.go
op-node/p2p/peer_params_test.go
+31
-0
prepared.go
op-node/p2p/prepared.go
+4
-0
service.go
op-node/service.go
+1
-1
No files found.
op-node/flags/p2p_flags.go
View file @
da2644c9
...
@@ -25,6 +25,15 @@ var (
...
@@ -25,6 +25,15 @@ var (
Required
:
false
,
Required
:
false
,
EnvVar
:
p2pEnv
(
"NO_DISCOVERY"
),
EnvVar
:
p2pEnv
(
"NO_DISCOVERY"
),
}
}
P2PScoring
=
cli
.
StringFlag
{
Name
:
"p2p.scoring"
,
Usage
:
"Sets the scoring strategy for the P2P stack. "
+
"Can be one of: none, light, full."
+
"Custom scoring strategies can be defined in the config file."
,
Required
:
false
,
Value
:
"none"
,
EnvVar
:
p2pEnv
(
"SCORING"
),
}
P2PPrivPath
=
cli
.
StringFlag
{
P2PPrivPath
=
cli
.
StringFlag
{
Name
:
"p2p.priv.path"
,
Name
:
"p2p.priv.path"
,
Usage
:
"Read the hex-encoded 32-byte private key for the peer ID from this txt file. Created if not already exists."
+
Usage
:
"Read the hex-encoded 32-byte private key for the peer ID from this txt file. Created if not already exists."
+
...
...
op-node/metrics/metrics.go
View file @
da2644c9
...
@@ -66,7 +66,6 @@ type Metricer interface {
...
@@ -66,7 +66,6 @@ type Metricer interface {
RecordSequencerSealingTime
(
duration
time
.
Duration
)
RecordSequencerSealingTime
(
duration
time
.
Duration
)
Document
()
[]
metrics
.
DocumentedMetric
Document
()
[]
metrics
.
DocumentedMetric
// P2P Metrics
// P2P Metrics
RecordGossipEvent
(
evType
int32
)
RecordPeerScoring
(
peerID
peer
.
ID
,
score
float64
)
RecordPeerScoring
(
peerID
peer
.
ID
,
score
float64
)
}
}
...
...
op-node/p2p/cli/load_config.go
View file @
da2644c9
...
@@ -24,7 +24,7 @@ import (
...
@@ -24,7 +24,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enode"
)
)
func
NewConfig
(
ctx
*
cli
.
Context
)
(
*
p2p
.
Config
,
error
)
{
func
NewConfig
(
ctx
*
cli
.
Context
,
blockTime
uint64
)
(
*
p2p
.
Config
,
error
)
{
conf
:=
&
p2p
.
Config
{}
conf
:=
&
p2p
.
Config
{}
if
ctx
.
GlobalBool
(
flags
.
DisableP2P
.
Name
)
{
if
ctx
.
GlobalBool
(
flags
.
DisableP2P
.
Name
)
{
...
@@ -54,6 +54,10 @@ func NewConfig(ctx *cli.Context) (*p2p.Config, error) {
...
@@ -54,6 +54,10 @@ func NewConfig(ctx *cli.Context) (*p2p.Config, error) {
return
nil
,
fmt
.
Errorf
(
"failed to load p2p gossip options: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to load p2p gossip options: %w"
,
err
)
}
}
if
err
:=
loadScoringOpts
(
conf
,
ctx
,
blockTime
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to load p2p scoring options: %w"
,
err
)
}
conf
.
ConnGater
=
p2p
.
DefaultConnGater
conf
.
ConnGater
=
p2p
.
DefaultConnGater
conf
.
ConnMngr
=
p2p
.
DefaultConnManager
conf
.
ConnMngr
=
p2p
.
DefaultConnManager
...
@@ -73,11 +77,21 @@ func validatePort(p uint) (uint16, error) {
...
@@ -73,11 +77,21 @@ func validatePort(p uint) (uint16, error) {
return
uint16
(
p
),
nil
return
uint16
(
p
),
nil
}
}
// TODO: Load peer scoring options
// loadScoringOpts loads the scoring options from the CLI context.
// func loadScoringOpts(conf *p2p.Config, ctx *cli.Context) error {
func
loadScoringOpts
(
conf
*
p2p
.
Config
,
ctx
*
cli
.
Context
,
blockTime
uint64
)
error
{
// conf.ScoringParams = p2p.DefaultScoringParams
scoringLevel
:=
ctx
.
GlobalString
(
flags
.
P2PScoring
.
Name
)
// return nil
if
scoringLevel
==
""
{
// }
scoringLevel
=
"none"
}
peerScoreParams
,
err
:=
p2p
.
GetPeerScoreParams
(
scoringLevel
,
blockTime
)
if
err
!=
nil
{
return
err
}
conf
.
PeerScoring
=
peerScoreParams
return
nil
}
func
loadListenOpts
(
conf
*
p2p
.
Config
,
ctx
*
cli
.
Context
)
error
{
func
loadListenOpts
(
conf
*
p2p
.
Config
,
ctx
*
cli
.
Context
)
error
{
listenIP
:=
ctx
.
GlobalString
(
flags
.
ListenIP
.
Name
)
listenIP
:=
ctx
.
GlobalString
(
flags
.
ListenIP
.
Name
)
...
...
op-node/p2p/config.go
View file @
da2644c9
...
@@ -19,6 +19,7 @@ import (
...
@@ -19,6 +19,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/net/conngater"
"github.com/libp2p/go-libp2p/p2p/net/conngater"
cmgr
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
cmgr
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
pubsub
"github.com/libp2p/go-libp2p-pubsub"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup"
)
)
...
@@ -49,8 +50,8 @@ type Config struct {
...
@@ -49,8 +50,8 @@ type Config struct {
DisableP2P
bool
DisableP2P
bool
NoDiscovery
bool
NoDiscovery
bool
// P2P Scoring Configurations
// P
ubsub P
2P Scoring Configurations
ScoringConfig
*
ScoringConfig
PeerScoring
pubsub
.
PeerScoreParams
ListenIP
net
.
IP
ListenIP
net
.
IP
ListenTCPPort
uint16
ListenTCPPort
uint16
...
@@ -98,11 +99,6 @@ type Config struct {
...
@@ -98,11 +99,6 @@ type Config struct {
ConnMngr
func
(
conf
*
Config
)
(
connmgr
.
ConnManager
,
error
)
ConnMngr
func
(
conf
*
Config
)
(
connmgr
.
ConnManager
,
error
)
}
}
type
ScoringConfig
struct
{
// Scoring Level
EnablePeerScoring
bool
}
type
ConnectionGater
interface
{
type
ConnectionGater
interface
{
connmgr
.
ConnectionGater
connmgr
.
ConnectionGater
...
@@ -146,6 +142,10 @@ func (conf *Config) Disabled() bool {
...
@@ -146,6 +142,10 @@ func (conf *Config) Disabled() bool {
return
conf
.
DisableP2P
return
conf
.
DisableP2P
}
}
func
(
conf
*
Config
)
Scoring
()
*
pubsub
.
PeerScoreParams
{
return
&
conf
.
PeerScoring
}
const
maxMeshParam
=
1000
const
maxMeshParam
=
1000
func
(
conf
*
Config
)
Check
()
error
{
func
(
conf
*
Config
)
Check
()
error
{
...
...
op-node/p2p/gossip.go
View file @
da2644c9
...
@@ -51,6 +51,7 @@ var MessageDomainInvalidSnappy = [4]byte{0, 0, 0, 0}
...
@@ -51,6 +51,7 @@ var MessageDomainInvalidSnappy = [4]byte{0, 0, 0, 0}
var
MessageDomainValidSnappy
=
[
4
]
byte
{
1
,
0
,
0
,
0
}
var
MessageDomainValidSnappy
=
[
4
]
byte
{
1
,
0
,
0
,
0
}
type
GossipSetupConfigurables
interface
{
type
GossipSetupConfigurables
interface
{
Scoring
()
*
pubsub
.
PeerScoreParams
ConfigureGossip
(
params
*
pubsub
.
GossipSubParams
)
[]
pubsub
.
Option
ConfigureGossip
(
params
*
pubsub
.
GossipSubParams
)
[]
pubsub
.
Option
}
}
...
@@ -152,11 +153,6 @@ func NewGossipSub(p2pCtx context.Context, h host.Host, g ConnectionGater, cfg *r
...
@@ -152,11 +153,6 @@ func NewGossipSub(p2pCtx context.Context, h host.Host, g ConnectionGater, cfg *r
return
nil
,
err
return
nil
,
err
}
}
params
:=
BuildGlobalGossipParams
(
cfg
)
params
:=
BuildGlobalGossipParams
(
cfg
)
// TODO: make this configurable behind a cli flag - disabled or default
peerScoreParams
,
err
:=
GetPeerScoreParams
(
"default"
,
cfg
)
if
err
!=
nil
{
return
nil
,
err
}
peerScoreThresholds
:=
NewPeerScoreThresholds
()
peerScoreThresholds
:=
NewPeerScoreThresholds
()
scorer
:=
NewScorer
(
g
,
h
.
Peerstore
(),
m
,
log
)
scorer
:=
NewScorer
(
g
,
h
.
Peerstore
(),
m
,
log
)
gossipOpts
:=
[]
pubsub
.
Option
{
gossipOpts
:=
[]
pubsub
.
Option
{
...
@@ -173,7 +169,7 @@ func NewGossipSub(p2pCtx context.Context, h host.Host, g ConnectionGater, cfg *r
...
@@ -173,7 +169,7 @@ func NewGossipSub(p2pCtx context.Context, h host.Host, g ConnectionGater, cfg *r
pubsub
.
WithBlacklist
(
denyList
),
pubsub
.
WithBlacklist
(
denyList
),
pubsub
.
WithGossipSubParams
(
params
),
pubsub
.
WithGossipSubParams
(
params
),
pubsub
.
WithEventTracer
(
&
gossipTracer
{
m
:
m
}),
pubsub
.
WithEventTracer
(
&
gossipTracer
{
m
:
m
}),
pubsub
.
WithPeerScore
(
&
peerScoreParams
,
&
peerScoreThresholds
),
pubsub
.
WithPeerScore
(
gossipConf
.
Scoring
()
,
&
peerScoreThresholds
),
pubsub
.
WithPeerScoreInspect
(
scorer
.
SnapshotHook
(),
peerScoreInspectFrequency
),
pubsub
.
WithPeerScoreInspect
(
scorer
.
SnapshotHook
(),
peerScoreInspectFrequency
),
}
}
gossipOpts
=
append
(
gossipOpts
,
gossipConf
.
ConfigureGossip
(
&
params
)
...
)
gossipOpts
=
append
(
gossipOpts
,
gossipConf
.
ConfigureGossip
(
&
params
)
...
)
...
...
op-node/p2p/node.go
View file @
da2644c9
...
@@ -76,7 +76,7 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.Config, l
...
@@ -76,7 +76,7 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.Config, l
// notify of any new connections/streams/etc.
// notify of any new connections/streams/etc.
n
.
host
.
Network
()
.
Notify
(
NewNetworkNotifier
(
log
,
metrics
))
n
.
host
.
Network
()
.
Notify
(
NewNetworkNotifier
(
log
,
metrics
))
// note: the IDDelta functionality was removed from libP2P, and no longer needs to be explicitly disabled.
// note: the IDDelta functionality was removed from libP2P, and no longer needs to be explicitly disabled.
n
.
gs
,
err
=
NewGossipSub
(
resourcesCtx
,
n
.
host
,
rollupCfg
,
setup
,
metrics
)
n
.
gs
,
err
=
NewGossipSub
(
resourcesCtx
,
n
.
host
,
n
.
gater
,
rollupCfg
,
setup
,
metrics
,
log
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to start gossipsub router: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to start gossipsub router: %w"
,
err
)
}
}
...
...
op-node/p2p/peer_params.go
View file @
da2644c9
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"math"
"math"
"time"
"time"
"github.com/ethereum-optimism/optimism/op-node/rollup"
pubsub
"github.com/libp2p/go-libp2p-pubsub"
pubsub
"github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peer"
)
)
...
@@ -19,12 +18,12 @@ func ScoreDecay(duration time.Duration, slot time.Duration) float64 {
...
@@ -19,12 +18,12 @@ func ScoreDecay(duration time.Duration, slot time.Duration) float64 {
return
math
.
Pow
(
DecayToZero
,
1
/
float64
(
numOfTimes
))
return
math
.
Pow
(
DecayToZero
,
1
/
float64
(
numOfTimes
))
}
}
//
DefaultPeerScoreParams is a default instantiation of [pubsub.PeerScoreParams]
.
//
LightPeerScoreParams is an instantiation of [pubsub.PeerScoreParams] with light penalties
.
// See [PeerScoreParams] for detailed documentation.
// See [PeerScoreParams] for detailed documentation.
//
//
// [PeerScoreParams]: https://pkg.go.dev/github.com/libp2p/go-libp2p-pubsub@v0.8.1#PeerScoreParams
// [PeerScoreParams]: https://pkg.go.dev/github.com/libp2p/go-libp2p-pubsub@v0.8.1#PeerScoreParams
var
DefaultPeerScoreParams
=
func
(
cfg
*
rollup
.
Config
)
pubsub
.
PeerScoreParams
{
var
LightPeerScoreParams
=
func
(
blockTime
uint64
)
pubsub
.
PeerScoreParams
{
slot
:=
time
.
Duration
(
cfg
.
B
lockTime
)
*
time
.
Second
slot
:=
time
.
Duration
(
b
lockTime
)
*
time
.
Second
if
slot
==
0
{
if
slot
==
0
{
slot
=
2
*
time
.
Second
slot
=
2
*
time
.
Second
}
}
...
@@ -56,8 +55,8 @@ var DefaultPeerScoreParams = func(cfg *rollup.Config) pubsub.PeerScoreParams {
...
@@ -56,8 +55,8 @@ var DefaultPeerScoreParams = func(cfg *rollup.Config) pubsub.PeerScoreParams {
// See [PeerScoreParams] for detailed documentation.
// See [PeerScoreParams] for detailed documentation.
//
//
// [PeerScoreParams]: https://pkg.go.dev/github.com/libp2p/go-libp2p-pubsub@v0.8.1#PeerScoreParams
// [PeerScoreParams]: https://pkg.go.dev/github.com/libp2p/go-libp2p-pubsub@v0.8.1#PeerScoreParams
var
DisabledPeerScoreParams
=
func
(
cfg
*
rollup
.
Config
)
pubsub
.
PeerScoreParams
{
var
DisabledPeerScoreParams
=
func
(
blockTime
uint64
)
pubsub
.
PeerScoreParams
{
slot
:=
time
.
Duration
(
cfg
.
B
lockTime
)
*
time
.
Second
slot
:=
time
.
Duration
(
b
lockTime
)
*
time
.
Second
// We initialize an "epoch" as 6 blocks suggesting 6 blocks,
// We initialize an "epoch" as 6 blocks suggesting 6 blocks,
// each taking ~ 2 seconds, is 12 seconds
// each taking ~ 2 seconds, is 12 seconds
epoch
:=
6
*
slot
epoch
:=
6
*
slot
...
@@ -84,9 +83,9 @@ var DisabledPeerScoreParams = func(cfg *rollup.Config) pubsub.PeerScoreParams {
...
@@ -84,9 +83,9 @@ var DisabledPeerScoreParams = func(cfg *rollup.Config) pubsub.PeerScoreParams {
}
}
// PeerScoreParamsByName is a map of name to function that returns a [pubsub.PeerScoreParams] based on the provided [rollup.Config].
// PeerScoreParamsByName is a map of name to function that returns a [pubsub.PeerScoreParams] based on the provided [rollup.Config].
var
PeerScoreParamsByName
=
map
[
string
](
func
(
cfg
*
rollup
.
Config
)
pubsub
.
PeerScoreParams
){
var
PeerScoreParamsByName
=
map
[
string
](
func
(
blockTime
uint64
)
pubsub
.
PeerScoreParams
){
"
default"
:
Defaul
tPeerScoreParams
,
"
light"
:
Ligh
tPeerScoreParams
,
"
disabled
"
:
DisabledPeerScoreParams
,
"
none
"
:
DisabledPeerScoreParams
,
}
}
// AvailablePeerScoreParams returns a list of available peer score params.
// AvailablePeerScoreParams returns a list of available peer score params.
...
@@ -101,13 +100,13 @@ func AvailablePeerScoreParams() []string {
...
@@ -101,13 +100,13 @@ func AvailablePeerScoreParams() []string {
}
}
// GetPeerScoreParams returns the [pubsub.PeerScoreParams] for the given name.
// GetPeerScoreParams returns the [pubsub.PeerScoreParams] for the given name.
func
GetPeerScoreParams
(
name
string
,
cfg
*
rollup
.
Config
)
(
pubsub
.
PeerScoreParams
,
error
)
{
func
GetPeerScoreParams
(
name
string
,
blockTime
uint64
)
(
pubsub
.
PeerScoreParams
,
error
)
{
params
,
ok
:=
PeerScoreParamsByName
[
name
]
params
,
ok
:=
PeerScoreParamsByName
[
name
]
if
!
ok
{
if
!
ok
{
return
pubsub
.
PeerScoreParams
{},
fmt
.
Errorf
(
"invalid params %s"
,
name
)
return
pubsub
.
PeerScoreParams
{},
fmt
.
Errorf
(
"invalid params %s"
,
name
)
}
}
return
params
(
cfg
),
nil
return
params
(
blockTime
),
nil
}
}
// NewPeerScoreThresholds returns a default [pubsub.PeerScoreThresholds].
// NewPeerScoreThresholds returns a default [pubsub.PeerScoreThresholds].
...
...
op-node/p2p/peer_params_test.go
0 → 100644
View file @
da2644c9
package
p2p
import
(
"sort"
"testing"
"github.com/stretchr/testify/suite"
)
// PeerParamsTestSuite tests peer parameterization.
type
PeerParamsTestSuite
struct
{
suite
.
Suite
}
// SetupTest sets up the test suite.
func
(
testSuite
*
PeerParamsTestSuite
)
SetupTest
()
{
// TODO:
}
// TestPeerParams runs the PeerParamsTestSuite.
func
TestPeerParams
(
t
*
testing
.
T
)
{
suite
.
Run
(
t
,
new
(
PeerParamsTestSuite
))
}
// TestAvailablePeerScoreParams validates the available peer score parameters.
func
(
testSuite
*
PeerParamsTestSuite
)
TestAvailablePeerScoreParams
()
{
available
:=
AvailablePeerScoreParams
()
sort
.
Strings
(
available
)
expected
:=
[]
string
{
"light"
,
"none"
}
testSuite
.
Equal
(
expected
,
available
)
}
op-node/p2p/prepared.go
View file @
da2644c9
...
@@ -64,6 +64,10 @@ func (p *Prepared) ConfigureGossip(params *pubsub.GossipSubParams) []pubsub.Opti
...
@@ -64,6 +64,10 @@ func (p *Prepared) ConfigureGossip(params *pubsub.GossipSubParams) []pubsub.Opti
return
nil
return
nil
}
}
func
(
p
*
Prepared
)
Scoring
()
*
pubsub
.
PeerScoreParams
{
return
nil
}
func
(
p
*
Prepared
)
Disabled
()
bool
{
func
(
p
*
Prepared
)
Disabled
()
bool
{
return
false
return
false
}
}
op-node/service.go
View file @
da2644c9
...
@@ -46,7 +46,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
...
@@ -46,7 +46,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
return
nil
,
fmt
.
Errorf
(
"failed to load p2p signer: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to load p2p signer: %w"
,
err
)
}
}
p2pConfig
,
err
:=
p2pcli
.
NewConfig
(
ctx
)
p2pConfig
,
err
:=
p2pcli
.
NewConfig
(
ctx
,
rollupConfig
.
BlockTime
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to load p2p config: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to load p2p config: %w"
,
err
)
}
}
...
...
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