Skip to content

Add bootnode #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions playground/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
ecrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/hashicorp/go-uuid"
keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -407,6 +406,11 @@ func ConnectRaw(service, port, protocol, user string) string {
return fmt.Sprintf(`{{Service "%s" "%s" "%s" "%s"}}`, service, port, protocol, user)
}

func ConnectEnode(service, id string) string {
// Note, this assumes that all the enode ports are registered with the 'rpc' label.
return ConnectRaw(service, "rpc", "enode", id)
}

func Connect(service, port string) string {
return ConnectRaw(service, port, "http", "")
}
Expand Down Expand Up @@ -706,8 +710,13 @@ type EnodeAddr struct {
Artifact string
}

func (e *EnodeAddr) ID() enode.ID {
return enode.PubkeyToIDV4(&e.PrivKey.PublicKey)
func (e *EnodeAddr) PrivKeyHex() string {
return hex.EncodeToString(gethcommon.LeftPadBytes(e.PrivKey.D.Bytes(), 32))
}

func (e *EnodeAddr) NodeID() string {
nodeid := fmt.Sprintf("%x", ecrypto.FromECDSAPub(&e.PrivKey.PublicKey)[1:])
return nodeid
}

func (o *output) GetEnodeAddr() *EnodeAddr {
Expand Down
2 changes: 1 addition & 1 deletion playground/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestEnodeGeneration(t *testing.T) {
o2 := newTestOutput(t)

for i := 0; i < 10; i++ {
if o1.GetEnodeAddr().ID() != o2.GetEnodeAddr().ID() {
if o1.GetEnodeAddr().NodeID() != o2.GetEnodeAddr().NodeID() {
t.Fatalf("enode IDs are not the same")
}
}
Expand Down
10 changes: 10 additions & 0 deletions playground/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (o *OpRbuilder) Run(service *Service, ctx *ExContext) {
WithArtifact("/data/l2-genesis.json", "l2-genesis.json").
WithVolume("data", "/data_op_reth")

if ctx.Bootnode != nil {
service.WithArgs("--trusted-peers", ctx.Bootnode.Connect())
}

if o.Flashblocks {
service.WithArgs(
"--flashblocks.enabled",
Expand Down Expand Up @@ -192,6 +196,11 @@ func logLevelToGethVerbosity(logLevel LogLevel) string {
func (o *OpGeth) Run(service *Service, ctx *ExContext) {
o.Enode = ctx.Output.GetEnodeAddr()

var trustedPeers string
if ctx.Bootnode != nil {
trustedPeers = fmt.Sprintf("--bootnodes %s ", ctx.Bootnode.Connect())
}

service.
WithImage("us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth").
WithTag("v1.101503.2-rc.5").
Expand Down Expand Up @@ -226,6 +235,7 @@ func (o *OpGeth) Run(service *Service, ctx *ExContext) {
"--state.scheme hash "+
"--port "+`{{Port "rpc" 30303}} `+
"--nodekey /data/p2p_key.txt "+
trustedPeers+
"--metrics "+
"--metrics.addr 0.0.0.0 "+
"--metrics.port "+`{{Port "metrics" 6061}}`,
Expand Down
2 changes: 1 addition & 1 deletion playground/local_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func printAddr(protocol, serviceName string, port int, user string) string {
}

if user != "" {
return fmt.Sprintf("%s%s@%s:%s", protocolPrefix, user, serviceName, serviceName)
return fmt.Sprintf("%s%s@%s:%d", protocolPrefix, user, serviceName, port)
}

return fmt.Sprintf("%s%s:%d", protocolPrefix, serviceName, port)
Expand Down
13 changes: 13 additions & 0 deletions playground/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ type ExContext struct {
// have to modify the serviceDesc interface to give services
// access to the output.
Output *output

// Bootnode reference for EL nodes.
// TODO: Extend for CL nodes too
Bootnode *BootnodeRef
}

type BootnodeRef struct {
Service string
ID string
}

func (b *BootnodeRef) Connect() string {
return ConnectEnode(b.Service, b.ID)
}

type ServiceGen interface {
Expand Down
10 changes: 9 additions & 1 deletion playground/recipe_opstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ func (o *OpRecipe) Apply(ctx *ExContext, artifacts *Artifacts) *Manifest {
flashblocksBuilderURLRef := o.flashblocksBuilderURL
externalBuilderRef := o.externalBuilder

opGeth := &OpGeth{}
svcManager.AddService("op-geth", opGeth)

ctx.Bootnode = &BootnodeRef{
Service: "op-geth",
ID: opGeth.Enode.NodeID(),
}

if o.externalBuilder == "op-reth" {
// Add a new op-reth service and connect it to Rollup-boost
svcManager.AddService("op-reth", &OpReth{})
Expand Down Expand Up @@ -103,7 +111,7 @@ func (o *OpRecipe) Apply(ctx *ExContext, artifacts *Artifacts) *Manifest {
L1Beacon: "beacon",
L2Node: elNode,
})
svcManager.AddService("op-geth", &OpGeth{})

svcManager.AddService("op-batcher", &OpBatcher{
L1Node: "el",
L2Node: "op-geth",
Expand Down
Loading