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
4397661b
Unverified
Commit
4397661b
authored
Jun 19, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Define application score parameters.
parent
8bec48bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
3 deletions
+67
-3
app_params.go
op-node/p2p/app_params.go
+48
-0
config.go
op-node/p2p/config.go
+2
-1
peer_params.go
op-node/p2p/peer_params.go
+3
-2
peer_params_test.go
op-node/p2p/peer_params_test.go
+14
-0
No files found.
op-node/p2p/app_params.go
0 → 100644
View file @
4397661b
package
p2p
import
(
"time"
"github.com/ethereum-optimism/optimism/op-node/rollup"
)
type
ApplicationScoreParams
struct
{
ValidResponseCap
float64
ValidResponseWeight
float64
ValidResponseDecay
float64
ErrorResponseCap
float64
ErrorResponseWeight
float64
ErrorResponseDecay
float64
RejectedPayloadCap
float64
RejectedPayloadWeight
float64
RejectedPayloadDecay
float64
DecayToZero
float64
DecayInterval
time
.
Duration
}
func
LightApplicationScoreParams
(
cfg
*
rollup
.
Config
)
ApplicationScoreParams
{
slot
:=
time
.
Duration
(
cfg
.
BlockTime
)
*
time
.
Second
if
slot
==
0
{
slot
=
2
*
time
.
Second
}
// We initialize an "epoch" as 6 blocks suggesting 6 blocks,
// each taking ~ 2 seconds, is 12 seconds
epoch
:=
6
*
slot
tenEpochs
:=
10
*
epoch
return
ApplicationScoreParams
{
ValidResponseCap
:
10
,
ValidResponseWeight
:
1
,
ValidResponseDecay
:
ScoreDecay
(
tenEpochs
,
slot
),
ErrorResponseCap
:
10
,
ErrorResponseWeight
:
-
16
,
ErrorResponseDecay
:
ScoreDecay
(
tenEpochs
,
slot
),
RejectedPayloadCap
:
10
,
RejectedPayloadWeight
:
-
50
,
RejectedPayloadDecay
:
ScoreDecay
(
tenEpochs
,
slot
),
DecayToZero
:
DecayToZero
,
DecayInterval
:
slot
,
}
}
op-node/p2p/config.go
View file @
4397661b
...
@@ -53,7 +53,8 @@ type SetupP2P interface {
...
@@ -53,7 +53,8 @@ type SetupP2P interface {
// ScoringParams defines the various types of peer scoring parameters.
// ScoringParams defines the various types of peer scoring parameters.
type
ScoringParams
struct
{
type
ScoringParams
struct
{
PeerScoring
pubsub
.
PeerScoreParams
PeerScoring
pubsub
.
PeerScoreParams
ApplicationScoring
ApplicationScoreParams
}
}
// Config sets up a p2p host and discv5 service from configuration.
// Config sets up a p2p host and discv5 service from configuration.
...
...
op-node/p2p/peer_params.go
View file @
4397661b
...
@@ -32,7 +32,7 @@ func ScoreDecay(duration time.Duration, slot time.Duration) float64 {
...
@@ -32,7 +32,7 @@ func ScoreDecay(duration time.Duration, slot time.Duration) float64 {
// 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
LightPeerScoreParams
=
func
(
cfg
*
rollup
.
Config
)
pubsub
.
PeerScoreParams
{
func
LightPeerScoreParams
(
cfg
*
rollup
.
Config
)
pubsub
.
PeerScoreParams
{
slot
:=
time
.
Duration
(
cfg
.
BlockTime
)
*
time
.
Second
slot
:=
time
.
Duration
(
cfg
.
BlockTime
)
*
time
.
Second
if
slot
==
0
{
if
slot
==
0
{
slot
=
2
*
time
.
Second
slot
=
2
*
time
.
Second
...
@@ -91,7 +91,8 @@ func GetScoringParams(name string, cfg *rollup.Config) (*ScoringParams, error) {
...
@@ -91,7 +91,8 @@ func GetScoringParams(name string, cfg *rollup.Config) (*ScoringParams, error) {
switch
name
{
switch
name
{
case
"light"
:
case
"light"
:
return
&
ScoringParams
{
return
&
ScoringParams
{
PeerScoring
:
LightPeerScoreParams
(
cfg
),
PeerScoring
:
LightPeerScoreParams
(
cfg
),
ApplicationScoring
:
LightApplicationScoreParams
(
cfg
),
},
nil
},
nil
case
"none"
:
case
"none"
:
return
nil
,
nil
return
nil
,
nil
...
...
op-node/p2p/peer_params_test.go
View file @
4397661b
...
@@ -81,6 +81,19 @@ func (testSuite *PeerParamsTestSuite) TestGetPeerScoreParams_Light() {
...
@@ -81,6 +81,19 @@ func (testSuite *PeerParamsTestSuite) TestGetPeerScoreParams_Light() {
testSuite
.
Equal
(
peerParams
.
DecayInterval
,
slot
)
testSuite
.
Equal
(
peerParams
.
DecayInterval
,
slot
)
testSuite
.
Equal
(
peerParams
.
DecayToZero
,
DecayToZero
)
testSuite
.
Equal
(
peerParams
.
DecayToZero
,
DecayToZero
)
testSuite
.
Equal
(
peerParams
.
RetainScore
,
oneHundredEpochs
)
testSuite
.
Equal
(
peerParams
.
RetainScore
,
oneHundredEpochs
)
appParams
:=
scoringParams
.
ApplicationScoring
testSuite
.
Positive
(
appParams
.
ValidResponseCap
)
testSuite
.
Positive
(
appParams
.
ValidResponseWeight
)
testSuite
.
Positive
(
appParams
.
ValidResponseDecay
)
testSuite
.
Positive
(
appParams
.
ErrorResponseCap
)
testSuite
.
Negative
(
appParams
.
ErrorResponseWeight
)
testSuite
.
Positive
(
appParams
.
ErrorResponseDecay
)
testSuite
.
Positive
(
appParams
.
RejectedPayloadCap
)
testSuite
.
Negative
(
appParams
.
RejectedPayloadWeight
)
testSuite
.
Positive
(
appParams
.
RejectedPayloadDecay
)
testSuite
.
Equal
(
DecayToZero
,
appParams
.
DecayToZero
)
testSuite
.
Equal
(
slot
,
appParams
.
DecayInterval
)
}
}
// TestParamsZeroBlockTime validates peer score params use default slot for 0 block time.
// TestParamsZeroBlockTime validates peer score params use default slot for 0 block time.
...
@@ -91,4 +104,5 @@ func (testSuite *PeerParamsTestSuite) TestParamsZeroBlockTime() {
...
@@ -91,4 +104,5 @@ func (testSuite *PeerParamsTestSuite) TestParamsZeroBlockTime() {
params
,
err
:=
GetScoringParams
(
"light"
,
&
cfg
)
params
,
err
:=
GetScoringParams
(
"light"
,
&
cfg
)
testSuite
.
NoError
(
err
)
testSuite
.
NoError
(
err
)
testSuite
.
Equal
(
params
.
PeerScoring
.
DecayInterval
,
slot
)
testSuite
.
Equal
(
params
.
PeerScoring
.
DecayInterval
,
slot
)
testSuite
.
Equal
(
params
.
ApplicationScoring
.
DecayInterval
,
slot
)
}
}
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