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
fcb2a125
Unverified
Commit
fcb2a125
authored
Dec 09, 2022
by
Mark Tyneway
Committed by
GitHub
Dec 09, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4327 from mdehoog/enr-tag-key-optimism-to-chain
[RFC] Bedrock: rename "optimism" ENR key to "opstack"
parents
35320420
85028bf1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
17 deletions
+17
-17
discovery.go
op-node/p2p/discovery.go
+13
-13
prepared.go
op-node/p2p/prepared.go
+1
-1
rollup-node-p2p.md
specs/rollup-node-p2p.md
+3
-3
No files found.
op-node/p2p/discovery.go
View file @
fcb2a125
...
@@ -75,7 +75,7 @@ func (conf *Config) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort
...
@@ -75,7 +75,7 @@ func (conf *Config) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort
}
else
{
}
else
{
return
nil
,
nil
,
fmt
.
Errorf
(
"no TCP port to put in discovery record"
)
return
nil
,
nil
,
fmt
.
Errorf
(
"no TCP port to put in discovery record"
)
}
}
dat
:=
Op
timism
ENRData
{
dat
:=
Op
Stack
ENRData
{
chainID
:
rollupCfg
.
L2ChainID
.
Uint64
(),
chainID
:
rollupCfg
.
L2ChainID
.
Uint64
(),
version
:
0
,
version
:
0
,
}
}
...
@@ -167,18 +167,18 @@ func enrToAddrInfo(r *enode.Node) (*peer.AddrInfo, *crypto.Secp256k1PublicKey, e
...
@@ -167,18 +167,18 @@ func enrToAddrInfo(r *enode.Node) (*peer.AddrInfo, *crypto.Secp256k1PublicKey, e
},
pub
,
nil
},
pub
,
nil
}
}
// The discovery ENRs are just key-value lists, and we filter them by records tagged with the "op
timism
" key,
// The discovery ENRs are just key-value lists, and we filter them by records tagged with the "op
stack
" key,
// and then check the chain ID and version.
// and then check the chain ID and version.
type
Op
timism
ENRData
struct
{
type
Op
Stack
ENRData
struct
{
chainID
uint64
chainID
uint64
version
uint64
version
uint64
}
}
func
(
o
*
Op
timism
ENRData
)
ENRKey
()
string
{
func
(
o
*
Op
Stack
ENRData
)
ENRKey
()
string
{
return
"op
timism
"
return
"op
stack
"
}
}
func
(
o
*
Op
timism
ENRData
)
EncodeRLP
(
w
io
.
Writer
)
error
{
func
(
o
*
Op
Stack
ENRData
)
EncodeRLP
(
w
io
.
Writer
)
error
{
out
:=
make
([]
byte
,
2
*
binary
.
MaxVarintLen64
)
out
:=
make
([]
byte
,
2
*
binary
.
MaxVarintLen64
)
offset
:=
binary
.
PutUvarint
(
out
,
o
.
chainID
)
offset
:=
binary
.
PutUvarint
(
out
,
o
.
chainID
)
offset
+=
binary
.
PutUvarint
(
out
[
offset
:
],
o
.
version
)
offset
+=
binary
.
PutUvarint
(
out
[
offset
:
],
o
.
version
)
...
@@ -187,13 +187,13 @@ func (o *OptimismENRData) EncodeRLP(w io.Writer) error {
...
@@ -187,13 +187,13 @@ func (o *OptimismENRData) EncodeRLP(w io.Writer) error {
return
rlp
.
Encode
(
w
,
out
)
return
rlp
.
Encode
(
w
,
out
)
}
}
func
(
o
*
Op
timism
ENRData
)
DecodeRLP
(
s
*
rlp
.
Stream
)
error
{
func
(
o
*
Op
Stack
ENRData
)
DecodeRLP
(
s
*
rlp
.
Stream
)
error
{
b
,
err
:=
s
.
Bytes
()
b
,
err
:=
s
.
Bytes
()
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to decode outer ENR entry: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to decode outer ENR entry: %w"
,
err
)
}
}
// We don't check the byte length: the below readers are limited, and the ENR itself has size limits.
// We don't check the byte length: the below readers are limited, and the ENR itself has size limits.
// Future "op
timism
" entries may contain additional data, and will be tagged with a newer version etc.
// Future "op
stack
" entries may contain additional data, and will be tagged with a newer version etc.
r
:=
bytes
.
NewReader
(
b
)
r
:=
bytes
.
NewReader
(
b
)
chainID
,
err
:=
binary
.
ReadUvarint
(
r
)
chainID
,
err
:=
binary
.
ReadUvarint
(
r
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -208,15 +208,15 @@ func (o *OptimismENRData) DecodeRLP(s *rlp.Stream) error {
...
@@ -208,15 +208,15 @@ func (o *OptimismENRData) DecodeRLP(s *rlp.Stream) error {
return
nil
return
nil
}
}
var
_
enr
.
Entry
=
(
*
Op
timism
ENRData
)(
nil
)
var
_
enr
.
Entry
=
(
*
Op
Stack
ENRData
)(
nil
)
func
FilterEnodes
(
log
log
.
Logger
,
cfg
*
rollup
.
Config
)
func
(
node
*
enode
.
Node
)
bool
{
func
FilterEnodes
(
log
log
.
Logger
,
cfg
*
rollup
.
Config
)
func
(
node
*
enode
.
Node
)
bool
{
return
func
(
node
*
enode
.
Node
)
bool
{
return
func
(
node
*
enode
.
Node
)
bool
{
var
dat
Op
timism
ENRData
var
dat
Op
Stack
ENRData
err
:=
node
.
Load
(
&
dat
)
err
:=
node
.
Load
(
&
dat
)
// if the entry does not exist, or if it is invalid, then ignore the node
// if the entry does not exist, or if it is invalid, then ignore the node
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Debug
(
"discovered node record has no op
timism
info"
,
"node"
,
node
.
ID
(),
"err"
,
err
)
log
.
Debug
(
"discovered node record has no op
stack
info"
,
"node"
,
node
.
ID
(),
"err"
,
err
)
return
false
return
false
}
}
// check chain ID matches
// check chain ID matches
...
@@ -347,7 +347,7 @@ func (n *NodeP2P) DiscoveryProcess(ctx context.Context, log log.Logger, cfg *rol
...
@@ -347,7 +347,7 @@ func (n *NodeP2P) DiscoveryProcess(ctx context.Context, log log.Logger, cfg *rol
log
.
Info
(
"stopped peer discovery"
)
log
.
Info
(
"stopped peer discovery"
)
return
// no ctx error, expected close
return
// no ctx error, expected close
case
found
:=
<-
randomNodesCh
:
case
found
:=
<-
randomNodesCh
:
var
dat
Op
timism
ENRData
var
dat
Op
Stack
ENRData
if
err
:=
found
.
Load
(
&
dat
);
err
!=
nil
{
// we already filtered on chain ID and version
if
err
:=
found
.
Load
(
&
dat
);
err
!=
nil
{
// we already filtered on chain ID and version
continue
continue
}
}
...
@@ -362,7 +362,7 @@ func (n *NodeP2P) DiscoveryProcess(ctx context.Context, log log.Logger, cfg *rol
...
@@ -362,7 +362,7 @@ func (n *NodeP2P) DiscoveryProcess(ctx context.Context, log log.Logger, cfg *rol
// Tag the peer, we'd rather have the connection manager prune away old peers,
// Tag the peer, we'd rather have the connection manager prune away old peers,
// or peers on different chains, or anyone we have not seen via discovery.
// or peers on different chains, or anyone we have not seen via discovery.
// There is no tag score decay yet, so just set it to 42.
// There is no tag score decay yet, so just set it to 42.
n
.
ConnectionManager
()
.
TagPeer
(
info
.
ID
,
fmt
.
Sprintf
(
"op
timism
-%d-%d"
,
dat
.
chainID
,
dat
.
version
),
42
)
n
.
ConnectionManager
()
.
TagPeer
(
info
.
ID
,
fmt
.
Sprintf
(
"op
stack
-%d-%d"
,
dat
.
chainID
,
dat
.
version
),
42
)
log
.
Debug
(
"discovered peer"
,
"peer"
,
info
.
ID
,
"nodeID"
,
found
.
ID
(),
"addr"
,
info
.
Addrs
[
0
])
log
.
Debug
(
"discovered peer"
,
"peer"
,
info
.
ID
,
"nodeID"
,
found
.
ID
(),
"addr"
,
info
.
Addrs
[
0
])
case
<-
connectTicker
.
C
:
case
<-
connectTicker
.
C
:
connected
:=
n
.
Host
()
.
Network
()
.
Peers
()
connected
:=
n
.
Host
()
.
Network
()
.
Peers
()
...
...
op-node/p2p/prepared.go
View file @
fcb2a125
...
@@ -47,7 +47,7 @@ func (p *Prepared) Host(log log.Logger, reporter metrics.Reporter) (host.Host, e
...
@@ -47,7 +47,7 @@ func (p *Prepared) Host(log log.Logger, reporter metrics.Reporter) (host.Host, e
// Discovery creates a disc-v5 service. Returns nil, nil, nil if discovery is disabled.
// Discovery creates a disc-v5 service. Returns nil, nil, nil if discovery is disabled.
func
(
p
*
Prepared
)
Discovery
(
log
log
.
Logger
,
rollupCfg
*
rollup
.
Config
,
tcpPort
uint16
)
(
*
enode
.
LocalNode
,
*
discover
.
UDPv5
,
error
)
{
func
(
p
*
Prepared
)
Discovery
(
log
log
.
Logger
,
rollupCfg
*
rollup
.
Config
,
tcpPort
uint16
)
(
*
enode
.
LocalNode
,
*
discover
.
UDPv5
,
error
)
{
if
p
.
LocalNode
!=
nil
{
if
p
.
LocalNode
!=
nil
{
dat
:=
Op
timism
ENRData
{
dat
:=
Op
Stack
ENRData
{
chainID
:
rollupCfg
.
L2ChainID
.
Uint64
(),
chainID
:
rollupCfg
.
L2ChainID
.
Uint64
(),
version
:
0
,
version
:
0
,
}
}
...
...
specs/rollup-node-p2p.md
View file @
fcb2a125
...
@@ -84,9 +84,9 @@ The Ethereum Node Record (ENR) for an Optimism rollup node must contain the foll
...
@@ -84,9 +84,9 @@ The Ethereum Node Record (ENR) for an Optimism rollup node must contain the foll
-
An IPv4 address (
`ip`
field) and/or IPv6 address (
`ip6`
field).
-
An IPv4 address (
`ip`
field) and/or IPv6 address (
`ip6`
field).
-
A TCP port (
`tcp`
field) representing the local libp2p listening port.
-
A TCP port (
`tcp`
field) representing the local libp2p listening port.
-
A UDP port (
`udp`
field) representing the local discv5 listening port.
-
A UDP port (
`udp`
field) representing the local discv5 listening port.
-
An Op
timism (
`optimism
`
field) L2 network identifier
-
An Op
Stack (
`opstack
`
field) L2 network identifier
The
`op
timism
`
value is encoded as a single RLP
`bytes`
value, the concatenation of:
The
`op
stack
`
value is encoded as a single RLP
`bytes`
value, the concatenation of:
-
chain ID (
`unsigned varint`
)
-
chain ID (
`unsigned varint`
)
-
fork ID (
`unsigned varint`
)
-
fork ID (
`unsigned varint`
)
...
@@ -101,7 +101,7 @@ The discovery process in Optimism is a pipeline of node records:
...
@@ -101,7 +101,7 @@ The discovery process in Optimism is a pipeline of node records:
2.
Pull additional records with searches to random Node IDs if necessary
2.
Pull additional records with searches to random Node IDs if necessary
(e.g. iterate
[
`RandomNodes()`
][
discv5-random-nodes
]
in Go implementation)
(e.g. iterate
[
`RandomNodes()`
][
discv5-random-nodes
]
in Go implementation)
3.
Pull records from the DiscV5 module when looking for peers
3.
Pull records from the DiscV5 module when looking for peers
4.
Check if the record contains the
`op
timism
`
entry, verify it matches the chain ID and current or future fork number
4.
Check if the record contains the
`op
stack
`
entry, verify it matches the chain ID and current or future fork number
5.
If not already connected, and not recently disconnected or put on deny-list, attempt to dial.
5.
If not already connected, and not recently disconnected or put on deny-list, attempt to dial.
### LibP2P
### LibP2P
...
...
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