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
a0f8c73e
Unverified
Commit
a0f8c73e
authored
May 26, 2023
by
Michael de Hoog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add op-bootnode implementation
parent
a48e53c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
152 additions
and
0 deletions
+152
-0
entrypoint.go
op-bootnode/bootnode/entrypoint.go
+83
-0
main.go
op-bootnode/cmd/main.go
+33
-0
flags.go
op-bootnode/flags/flags.go
+36
-0
No files found.
op-bootnode/bootnode/entrypoint.go
0 → 100644
View file @
a0f8c73e
package
bootnode
import
(
"context"
"errors"
"fmt"
opnode
"github.com/ethereum-optimism/optimism/op-node"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/metrics"
"github.com/ethereum-optimism/optimism/op-node/p2p"
p2pcli
"github.com/ethereum-optimism/optimism/op-node/p2p/cli"
"github.com/ethereum-optimism/optimism/op-node/rollup"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/urfave/cli"
)
type
gossipNoop
struct
{}
func
(
g
*
gossipNoop
)
OnUnsafeL2Payload
(
_
context
.
Context
,
_
peer
.
ID
,
_
*
eth
.
ExecutionPayload
)
error
{
return
nil
}
type
gossipConfig
struct
{}
func
(
g
*
gossipConfig
)
P2PSequencerAddress
()
common
.
Address
{
return
common
.
Address
{}
}
type
l2Chain
struct
{}
func
(
l
*
l2Chain
)
PayloadByNumber
(
_
context
.
Context
,
_
uint64
)
(
*
eth
.
ExecutionPayload
,
error
)
{
return
nil
,
nil
}
func
Main
(
cliCtx
*
cli
.
Context
)
error
{
log
.
Info
(
"Initializing bootnode"
)
logCfg
:=
oplog
.
ReadCLIConfig
(
cliCtx
)
logger
:=
oplog
.
NewLogger
(
logCfg
)
m
:=
metrics
.
NewMetrics
(
"default"
)
ctx
:=
context
.
Background
()
config
,
err
:=
opnode
.
NewRollupConfig
(
cliCtx
)
if
err
!=
nil
{
return
err
}
if
err
=
validateConfig
(
config
);
err
!=
nil
{
return
err
}
p2pConfig
,
err
:=
p2pcli
.
NewConfig
(
cliCtx
,
config
.
BlockTime
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to load p2p config: %w"
,
err
)
}
p2pNode
,
err
:=
p2p
.
NewNodeP2P
(
ctx
,
config
,
logger
,
p2pConfig
,
&
gossipNoop
{},
&
l2Chain
{},
&
gossipConfig
{},
m
)
if
err
!=
nil
||
p2pNode
==
nil
{
return
err
}
if
p2pNode
.
Dv5Udp
()
==
nil
{
return
fmt
.
Errorf
(
"uninitialized discovery service"
)
}
p2pNode
.
DiscoveryProcess
(
ctx
,
logger
,
config
,
p2pConfig
.
TargetPeers
())
return
nil
}
// validateConfig ensures the minimal config required to run a bootnode
func
validateConfig
(
config
*
rollup
.
Config
)
error
{
if
config
.
L2ChainID
==
nil
||
config
.
L2ChainID
.
Uint64
()
==
0
{
return
errors
.
New
(
"chain ID is not set"
)
}
if
config
.
Genesis
.
L2Time
<=
0
{
return
errors
.
New
(
"genesis timestamp is not set"
)
}
if
config
.
BlockTime
<=
0
{
return
errors
.
New
(
"block time is not set"
)
}
return
nil
}
op-bootnode/cmd/main.go
0 → 100644
View file @
a0f8c73e
package
main
import
(
"os"
"github.com/ethereum-optimism/optimism/op-bootnode/bootnode"
"github.com/ethereum-optimism/optimism/op-bootnode/flags"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli"
)
func
main
()
{
// Set up logger with a default INFO level in case we fail to parse flags,
// otherwise the final critical log won't show what the parsing error was.
log
.
Root
()
.
SetHandler
(
log
.
LvlFilterHandler
(
log
.
LvlInfo
,
log
.
StreamHandler
(
os
.
Stdout
,
log
.
TerminalFormat
(
true
)),
),
)
app
:=
cli
.
NewApp
()
app
.
Flags
=
flags
.
Flags
app
.
Name
=
"bootnode"
app
.
Usage
=
"Rollup Bootnode"
app
.
Description
=
"Broadcasts incoming P2P peers to each other, enabling peer bootstrapping."
app
.
Action
=
bootnode
.
Main
err
:=
app
.
Run
(
os
.
Args
)
if
err
!=
nil
{
log
.
Crit
(
"Application failed"
,
"message"
,
err
)
}
}
op-bootnode/flags/flags.go
0 → 100644
View file @
a0f8c73e
package
flags
import
(
"fmt"
"strings"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/flags"
opservice
"github.com/ethereum-optimism/optimism/op-service"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
"github.com/urfave/cli"
)
const
envVarPrefix
=
"OP_BOOTNODE"
var
(
RollupConfig
=
cli
.
StringFlag
{
Name
:
flags
.
RollupConfig
.
Name
,
Usage
:
"Rollup chain parameters"
,
EnvVar
:
opservice
.
PrefixEnvVar
(
envVarPrefix
,
"ROLLUP_CONFIG"
),
}
Network
=
cli
.
StringFlag
{
Name
:
flags
.
Network
.
Name
,
Usage
:
fmt
.
Sprintf
(
"Predefined network selection. Available networks: %s"
,
strings
.
Join
(
chaincfg
.
AvailableNetworks
(),
", "
)),
EnvVar
:
opservice
.
PrefixEnvVar
(
envVarPrefix
,
"NETWORK"
),
}
)
var
Flags
=
[]
cli
.
Flag
{
RollupConfig
,
Network
,
}
func
init
()
{
Flags
=
append
(
Flags
,
oplog
.
CLIFlags
(
envVarPrefix
)
...
)
}
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