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
6e1d30d4
Unverified
Commit
6e1d30d4
authored
Aug 06, 2024
by
Matt Joiner
Committed by
GitHub
Aug 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply error variable lint in op-node/p2p (#11354)
parent
c14a8b2a
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
30 additions
and
30 deletions
+30
-30
expiry.go
op-node/p2p/gating/expiry.go
+2
-2
expiry_test.go
op-node/p2p/gating/expiry_test.go
+7
-7
iface.go
op-node/p2p/store/iface.go
+3
-3
ip_ban_book.go
op-node/p2p/store/ip_ban_book.go
+2
-2
ip_ban_book_test.go
op-node/p2p/store/ip_ban_book_test.go
+1
-1
mdbook.go
op-node/p2p/store/mdbook.go
+1
-1
peer_ban_book.go
op-node/p2p/store/peer_ban_book.go
+2
-2
peer_ban_book_test.go
op-node/p2p/store/peer_ban_book_test.go
+1
-1
records_book.go
op-node/p2p/store/records_book.go
+5
-5
scorebook.go
op-node/p2p/store/scorebook.go
+1
-1
sync.go
op-node/p2p/sync.go
+5
-5
No files found.
op-node/p2p/gating/expiry.go
View file @
6e1d30d4
...
...
@@ -61,7 +61,7 @@ func (g *ExpiryConnectionGater) UnblockPeer(p peer.ID) error {
func
(
g
*
ExpiryConnectionGater
)
peerBanExpiryCheck
(
p
peer
.
ID
)
(
allow
bool
)
{
// if the peer is blocked, check if it's time to unblock
expiry
,
err
:=
g
.
store
.
GetPeerBanExpiration
(
p
)
if
errors
.
Is
(
err
,
store
.
UnknownBanErr
)
{
if
errors
.
Is
(
err
,
store
.
ErrUnknownBan
)
{
return
true
// peer is allowed if it has not been banned
}
if
err
!=
nil
{
...
...
@@ -88,7 +88,7 @@ func (g *ExpiryConnectionGater) addrBanExpiryCheck(ma multiaddr.Multiaddr) (allo
}
// if just the IP is blocked, check if it's time to unblock
expiry
,
err
:=
g
.
store
.
GetIPBanExpiration
(
ip
)
if
errors
.
Is
(
err
,
store
.
UnknownBanErr
)
{
if
errors
.
Is
(
err
,
store
.
ErrUnknownBan
)
{
return
true
// IP is allowed if it has not been banned
}
if
err
!=
nil
{
...
...
op-node/p2p/gating/expiry_test.go
View file @
6e1d30d4
...
...
@@ -47,7 +47,7 @@ func TestExpiryConnectionGater_InterceptPeerDial(t *testing.T) {
t
.
Run
(
"unknown expiring ban"
,
func
(
t
*
testing
.
T
)
{
_
,
mockExpiryStore
,
mockGater
,
gater
:=
expiryTestSetup
(
t
)
mockGater
.
EXPECT
()
.
InterceptPeerDial
(
mallory
)
.
Return
(
true
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
UnknownBanErr
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
ErrUnknownBan
)
allow
:=
gater
.
InterceptPeerDial
(
mallory
)
require
.
True
(
t
,
allow
)
})
...
...
@@ -68,7 +68,7 @@ func TestExpiryConnectionGater_InterceptAddrDial(t *testing.T) {
t
.
Run
(
"expired IP ban"
,
func
(
t
*
testing
.
T
)
{
cl
,
mockExpiryStore
,
mockGater
,
gater
:=
expiryTestSetup
(
t
)
mockGater
.
EXPECT
()
.
InterceptAddrDial
(
mallory
,
addr
)
.
Return
(
true
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
UnknownBanErr
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
ErrUnknownBan
)
mockExpiryStore
.
EXPECT
()
.
GetIPBanExpiration
(
ip
.
To4
())
.
Return
(
cl
.
Now
()
.
Add
(
-
time
.
Second
),
nil
)
mockExpiryStore
.
EXPECT
()
.
SetIPBanExpiration
(
ip
.
To4
(),
time
.
Time
{})
.
Return
(
nil
)
allow
:=
gater
.
InterceptAddrDial
(
mallory
,
addr
)
...
...
@@ -77,7 +77,7 @@ func TestExpiryConnectionGater_InterceptAddrDial(t *testing.T) {
t
.
Run
(
"active IP ban"
,
func
(
t
*
testing
.
T
)
{
cl
,
mockExpiryStore
,
mockGater
,
gater
:=
expiryTestSetup
(
t
)
mockGater
.
EXPECT
()
.
InterceptAddrDial
(
mallory
,
addr
)
.
Return
(
true
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
UnknownBanErr
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
ErrUnknownBan
)
mockExpiryStore
.
EXPECT
()
.
GetIPBanExpiration
(
ip
.
To4
())
.
Return
(
cl
.
Now
()
.
Add
(
time
.
Second
),
nil
)
allow
:=
gater
.
InterceptAddrDial
(
mallory
,
addr
)
require
.
False
(
t
,
allow
)
...
...
@@ -85,8 +85,8 @@ func TestExpiryConnectionGater_InterceptAddrDial(t *testing.T) {
t
.
Run
(
"unknown IP ban expiry"
,
func
(
t
*
testing
.
T
)
{
_
,
mockExpiryStore
,
mockGater
,
gater
:=
expiryTestSetup
(
t
)
mockGater
.
EXPECT
()
.
InterceptAddrDial
(
mallory
,
addr
)
.
Return
(
true
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
UnknownBanErr
)
mockExpiryStore
.
EXPECT
()
.
GetIPBanExpiration
(
ip
.
To4
())
.
Return
(
time
.
Time
{},
store
.
UnknownBanErr
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
ErrUnknownBan
)
mockExpiryStore
.
EXPECT
()
.
GetIPBanExpiration
(
ip
.
To4
())
.
Return
(
time
.
Time
{},
store
.
ErrUnknownBan
)
allow
:=
gater
.
InterceptAddrDial
(
mallory
,
addr
)
require
.
True
(
t
,
allow
)
})
...
...
@@ -165,7 +165,7 @@ func TestExpiryConnectionGater_InterceptAccept(t *testing.T) {
t
.
Run
(
"unknown expiry"
,
func
(
t
*
testing
.
T
)
{
_
,
mockExpiryStore
,
mockGater
,
gater
:=
expiryTestSetup
(
t
)
mockGater
.
EXPECT
()
.
InterceptAccept
(
mas
)
.
Return
(
true
)
mockExpiryStore
.
EXPECT
()
.
GetIPBanExpiration
(
ip
.
To4
())
.
Return
(
time
.
Time
{},
store
.
UnknownBanErr
)
mockExpiryStore
.
EXPECT
()
.
GetIPBanExpiration
(
ip
.
To4
())
.
Return
(
time
.
Time
{},
store
.
ErrUnknownBan
)
allow
:=
gater
.
InterceptAccept
(
mas
)
require
.
True
(
t
,
allow
)
})
...
...
@@ -201,7 +201,7 @@ func TestExpiryConnectionGater_InterceptSecured(t *testing.T) {
t
.
Run
(
"unknown expiry"
,
func
(
t
*
testing
.
T
)
{
_
,
mockExpiryStore
,
mockGater
,
gater
:=
expiryTestSetup
(
t
)
mockGater
.
EXPECT
()
.
InterceptSecured
(
network
.
DirInbound
,
mallory
,
mas
)
.
Return
(
true
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
UnknownBanErr
)
mockExpiryStore
.
EXPECT
()
.
GetPeerBanExpiration
(
mallory
)
.
Return
(
time
.
Time
{},
store
.
ErrUnknownBan
)
allow
:=
gater
.
InterceptSecured
(
network
.
DirInbound
,
mallory
,
mas
)
require
.
True
(
t
,
allow
)
})
...
...
op-node/p2p/store/iface.go
View file @
6e1d30d4
...
...
@@ -102,13 +102,13 @@ type ScoreDiff interface {
Apply
(
score
*
scoreRecord
)
}
var
UnknownBanErr
=
errors
.
New
(
"unknown ban"
)
var
ErrUnknownBan
=
errors
.
New
(
"unknown ban"
)
type
PeerBanStore
interface
{
// SetPeerBanExpiration create the peer ban with expiration time.
// If expiry == time.Time{} then the ban is deleted.
SetPeerBanExpiration
(
id
peer
.
ID
,
expiry
time
.
Time
)
error
// GetPeerBanExpiration gets the peer ban expiration time, or
UnknownBanErr
error if none exists.
// GetPeerBanExpiration gets the peer ban expiration time, or
ErrUnknownBan
error if none exists.
GetPeerBanExpiration
(
id
peer
.
ID
)
(
time
.
Time
,
error
)
}
...
...
@@ -116,7 +116,7 @@ type IPBanStore interface {
// SetIPBanExpiration create the IP ban with expiration time.
// If expiry == time.Time{} then the ban is deleted.
SetIPBanExpiration
(
ip
net
.
IP
,
expiry
time
.
Time
)
error
// GetIPBanExpiration gets the IP ban expiration time, or
UnknownBanErr
error if none exists.
// GetIPBanExpiration gets the IP ban expiration time, or
ErrUnknownBan
error if none exists.
GetIPBanExpiration
(
ip
net
.
IP
)
(
time
.
Time
,
error
)
}
...
...
op-node/p2p/store/ip_ban_book.go
View file @
6e1d30d4
...
...
@@ -71,8 +71,8 @@ func (d *ipBanBook) startGC() {
func
(
d
*
ipBanBook
)
GetIPBanExpiration
(
ip
net
.
IP
)
(
time
.
Time
,
error
)
{
rec
,
err
:=
d
.
book
.
getRecord
(
ip
.
To16
()
.
String
())
if
err
==
UnknownRecordErr
{
return
time
.
Time
{},
UnknownBanErr
if
err
==
ErrUnknownRecord
{
return
time
.
Time
{},
ErrUnknownBan
}
if
err
!=
nil
{
return
time
.
Time
{},
err
...
...
op-node/p2p/store/ip_ban_book_test.go
View file @
6e1d30d4
...
...
@@ -18,7 +18,7 @@ func TestGetUnknownIPBan(t *testing.T) {
book
:=
createMemoryIPBanBook
(
t
)
defer
book
.
Close
()
exp
,
err
:=
book
.
GetIPBanExpiration
(
net
.
IPv4
(
1
,
2
,
3
,
4
))
require
.
Same
(
t
,
UnknownBanErr
,
err
)
require
.
Same
(
t
,
ErrUnknownBan
,
err
)
require
.
Equal
(
t
,
time
.
Time
{},
exp
)
}
...
...
op-node/p2p/store/mdbook.go
View file @
6e1d30d4
...
...
@@ -69,7 +69,7 @@ func (m *metadataBook) startGC() {
func
(
m
*
metadataBook
)
GetPeerMetadata
(
id
peer
.
ID
)
(
PeerMetadata
,
error
)
{
record
,
err
:=
m
.
book
.
getRecord
(
id
)
// If the record is not found, return an empty PeerMetadata
if
err
==
UnknownRecordErr
{
if
err
==
ErrUnknownRecord
{
return
PeerMetadata
{},
nil
}
if
err
!=
nil
{
...
...
op-node/p2p/store/peer_ban_book.go
View file @
6e1d30d4
...
...
@@ -67,8 +67,8 @@ func (d *peerBanBook) startGC() {
func
(
d
*
peerBanBook
)
GetPeerBanExpiration
(
id
peer
.
ID
)
(
time
.
Time
,
error
)
{
rec
,
err
:=
d
.
book
.
getRecord
(
id
)
if
err
==
UnknownRecordErr
{
return
time
.
Time
{},
UnknownBanErr
if
err
==
ErrUnknownRecord
{
return
time
.
Time
{},
ErrUnknownBan
}
if
err
!=
nil
{
return
time
.
Time
{},
err
...
...
op-node/p2p/store/peer_ban_book_test.go
View file @
6e1d30d4
...
...
@@ -17,7 +17,7 @@ func TestGetUnknownPeerBan(t *testing.T) {
book
:=
createMemoryPeerBanBook
(
t
)
defer
book
.
Close
()
exp
,
err
:=
book
.
GetPeerBanExpiration
(
"a"
)
require
.
Same
(
t
,
UnknownBanErr
,
err
)
require
.
Same
(
t
,
ErrUnknownBan
,
err
)
require
.
Equal
(
t
,
time
.
Time
{},
exp
)
}
...
...
op-node/p2p/store/records_book.go
View file @
6e1d30d4
...
...
@@ -30,7 +30,7 @@ type recordDiff[V record] interface {
Apply
(
v
V
)
}
var
UnknownRecordErr
=
errors
.
New
(
"unknown record"
)
var
ErrUnknownRecord
=
errors
.
New
(
"unknown record"
)
// recordsBook is a generic K-V store to embed in the extended-peerstore.
// It prunes old entries to keep the store small.
...
...
@@ -103,13 +103,13 @@ func (d *recordsBook[K, V]) deleteRecord(key K) error {
func
(
d
*
recordsBook
[
K
,
V
])
getRecord
(
key
K
)
(
v
V
,
err
error
)
{
if
val
,
ok
:=
d
.
cache
.
Get
(
key
);
ok
{
if
d
.
hasExpired
(
val
)
{
return
v
,
UnknownRecordErr
return
v
,
ErrUnknownRecord
}
return
val
,
nil
}
data
,
err
:=
d
.
store
.
Get
(
d
.
ctx
,
d
.
dsKey
(
key
))
if
errors
.
Is
(
err
,
ds
.
ErrNotFound
)
{
return
v
,
UnknownRecordErr
return
v
,
ErrUnknownRecord
}
else
if
err
!=
nil
{
return
v
,
fmt
.
Errorf
(
"failed to load value of key %v: %w"
,
key
,
err
)
}
...
...
@@ -118,7 +118,7 @@ func (d *recordsBook[K, V]) getRecord(key K) (v V, err error) {
return
v
,
fmt
.
Errorf
(
"invalid value for key %v: %w"
,
key
,
err
)
}
if
d
.
hasExpired
(
v
)
{
return
v
,
UnknownRecordErr
return
v
,
ErrUnknownRecord
}
d
.
cache
.
Add
(
key
,
v
)
return
v
,
nil
...
...
@@ -128,7 +128,7 @@ func (d *recordsBook[K, V]) SetRecord(key K, diff recordDiff[V]) (V, error) {
d
.
Lock
()
defer
d
.
Unlock
()
rec
,
err
:=
d
.
getRecord
(
key
)
if
err
==
UnknownRecordErr
{
// instantiate new record if it does not exist yet
if
err
==
ErrUnknownRecord
{
// instantiate new record if it does not exist yet
rec
=
d
.
newRecord
()
}
else
if
err
!=
nil
{
return
d
.
newRecord
(),
err
...
...
op-node/p2p/store/scorebook.go
View file @
6e1d30d4
...
...
@@ -71,7 +71,7 @@ func (d *scoreBook) startGC() {
func
(
d
*
scoreBook
)
GetPeerScores
(
id
peer
.
ID
)
(
PeerScores
,
error
)
{
record
,
err
:=
d
.
book
.
getRecord
(
id
)
if
err
==
UnknownRecordErr
{
if
err
==
ErrUnknownRecord
{
return
PeerScores
{},
nil
// return zeroed scores by default
}
if
err
!=
nil
{
...
...
op-node/p2p/sync.go
View file @
6e1d30d4
...
...
@@ -833,7 +833,7 @@ func (srv *ReqRespServer) HandleSyncRequest(ctx context.Context, log log.Logger,
log
.
Warn
(
"failed to serve p2p sync request"
,
"req"
,
req
,
"err"
,
err
)
if
errors
.
Is
(
err
,
ethereum
.
NotFound
)
{
resultCode
=
ResultCodeNotFoundErr
}
else
if
errors
.
Is
(
err
,
invalidRequestErr
)
{
}
else
if
errors
.
Is
(
err
,
errInvalidRequest
)
{
resultCode
=
ResultCodeInvalidErr
}
else
{
resultCode
=
ResultCodeUnknownErr
...
...
@@ -846,7 +846,7 @@ func (srv *ReqRespServer) HandleSyncRequest(ctx context.Context, log log.Logger,
srv
.
metrics
.
ServerPayloadByNumberEvent
(
req
,
resultCode
,
time
.
Since
(
start
))
}
var
invalidRequestErr
=
errors
.
New
(
"invalid request"
)
var
errInvalidRequest
=
errors
.
New
(
"invalid request"
)
func
(
srv
*
ReqRespServer
)
handleSyncRequest
(
ctx
context
.
Context
,
stream
network
.
Stream
)
(
uint64
,
error
)
{
peerId
:=
stream
.
Conn
()
.
RemotePeer
()
...
...
@@ -892,14 +892,14 @@ func (srv *ReqRespServer) handleSyncRequest(ctx context.Context, stream network.
// Check the request is within the expected range of blocks
if
req
<
srv
.
cfg
.
Genesis
.
L2
.
Number
{
return
req
,
fmt
.
Errorf
(
"cannot serve request for L2 block %d before genesis %d: %w"
,
req
,
srv
.
cfg
.
Genesis
.
L2
.
Number
,
invalidRequestErr
)
return
req
,
fmt
.
Errorf
(
"cannot serve request for L2 block %d before genesis %d: %w"
,
req
,
srv
.
cfg
.
Genesis
.
L2
.
Number
,
errInvalidRequest
)
}
max
,
err
:=
srv
.
cfg
.
TargetBlockNumber
(
uint64
(
time
.
Now
()
.
Unix
()))
if
err
!=
nil
{
return
req
,
fmt
.
Errorf
(
"cannot determine max target block number to verify request: %w"
,
invalidRequestErr
)
return
req
,
fmt
.
Errorf
(
"cannot determine max target block number to verify request: %w"
,
errInvalidRequest
)
}
if
req
>
max
{
return
req
,
fmt
.
Errorf
(
"cannot serve request for L2 block %d after max expected block (%v): %w"
,
req
,
max
,
invalidRequestErr
)
return
req
,
fmt
.
Errorf
(
"cannot serve request for L2 block %d after max expected block (%v): %w"
,
req
,
max
,
errInvalidRequest
)
}
envelope
,
err
:=
srv
.
l2
.
PayloadByNumber
(
ctx
,
req
)
...
...
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