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
727c1fcc
Unverified
Commit
727c1fcc
authored
Dec 16, 2022
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: guard against panics in the gossip validator
parent
8d8219f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletion
+47
-1
gossip.go
op-node/p2p/gossip.go
+13
-1
gossip_test.go
op-node/p2p/gossip_test.go
+34
-0
No files found.
op-node/p2p/gossip.go
View file @
727c1fcc
...
@@ -165,6 +165,18 @@ func logValidationResult(self peer.ID, msg string, log log.Logger, fn pubsub.Val
...
@@ -165,6 +165,18 @@ func logValidationResult(self peer.ID, msg string, log log.Logger, fn pubsub.Val
}
}
}
}
func
guardGossipValidator
(
log
log
.
Logger
,
fn
pubsub
.
ValidatorEx
)
pubsub
.
ValidatorEx
{
return
func
(
ctx
context
.
Context
,
id
peer
.
ID
,
message
*
pubsub
.
Message
)
(
result
pubsub
.
ValidationResult
)
{
defer
func
()
{
if
err
:=
recover
();
err
!=
nil
{
log
.
Error
(
"gossip validation panic"
,
"err"
,
err
,
"peer"
,
id
)
result
=
pubsub
.
ValidationReject
}
}()
return
fn
(
ctx
,
id
,
message
)
}
}
type
seenBlocks
struct
{
type
seenBlocks
struct
{
sync
.
Mutex
sync
.
Mutex
blockHashes
[]
common
.
Hash
blockHashes
[]
common
.
Hash
...
@@ -358,7 +370,7 @@ func (p *publisher) Close() error {
...
@@ -358,7 +370,7 @@ func (p *publisher) Close() error {
}
}
func
JoinGossip
(
p2pCtx
context
.
Context
,
self
peer
.
ID
,
ps
*
pubsub
.
PubSub
,
log
log
.
Logger
,
cfg
*
rollup
.
Config
,
gossipIn
GossipIn
)
(
GossipOut
,
error
)
{
func
JoinGossip
(
p2pCtx
context
.
Context
,
self
peer
.
ID
,
ps
*
pubsub
.
PubSub
,
log
log
.
Logger
,
cfg
*
rollup
.
Config
,
gossipIn
GossipIn
)
(
GossipOut
,
error
)
{
val
:=
logValidationResult
(
self
,
"validated block"
,
log
,
BuildBlocksValidator
(
log
,
cfg
))
val
:=
guardGossipValidator
(
log
,
logValidationResult
(
self
,
"validated block"
,
log
,
BuildBlocksValidator
(
log
,
cfg
)
))
blocksTopicName
:=
blocksTopicV1
(
cfg
)
blocksTopicName
:=
blocksTopicV1
(
cfg
)
err
:=
ps
.
RegisterTopicValidator
(
blocksTopicName
,
err
:=
ps
.
RegisterTopicValidator
(
blocksTopicName
,
val
,
val
,
...
...
op-node/p2p/gossip_test.go
0 → 100644
View file @
727c1fcc
package
p2p
import
(
"context"
"testing"
"github.com/ethereum/go-ethereum/log"
pubsub
"github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-node/testlog"
)
func
TestGuardGossipValidator
(
t
*
testing
.
T
)
{
logger
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
val
:=
guardGossipValidator
(
logger
,
func
(
ctx
context
.
Context
,
id
peer
.
ID
,
message
*
pubsub
.
Message
)
pubsub
.
ValidationResult
{
if
id
==
"mallory"
{
panic
(
"mallory was here"
)
}
if
id
==
"bob"
{
return
pubsub
.
ValidationIgnore
}
return
pubsub
.
ValidationAccept
})
// Test that panics from mallory are recovered and rejected,
// and test that we can continue to ignore bob and accept alice.
require
.
Equal
(
t
,
pubsub
.
ValidationAccept
,
val
(
context
.
Background
(),
"alice"
,
nil
))
require
.
Equal
(
t
,
pubsub
.
ValidationReject
,
val
(
context
.
Background
(),
"mallory"
,
nil
))
require
.
Equal
(
t
,
pubsub
.
ValidationIgnore
,
val
(
context
.
Background
(),
"bob"
,
nil
))
require
.
Equal
(
t
,
pubsub
.
ValidationReject
,
val
(
context
.
Background
(),
"mallory"
,
nil
))
require
.
Equal
(
t
,
pubsub
.
ValidationAccept
,
val
(
context
.
Background
(),
"alice"
,
nil
))
require
.
Equal
(
t
,
pubsub
.
ValidationIgnore
,
val
(
context
.
Background
(),
"bob"
,
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