Skip to content

Commit b44f9a3

Browse files
authored
Add bootnode (#147)
* Add bootnode * Use Op-geth as bootnode * Remove comment * Remove empty statement * Remove useless thing * Fix * Better * Revert one change
1 parent 4ce6399 commit b44f9a3

File tree

6 files changed

+46
-6
lines changed

6 files changed

+46
-6
lines changed

playground/artifacts.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/ethereum/go-ethereum/common/hexutil"
3131
"github.com/ethereum/go-ethereum/core/types"
3232
ecrypto "github.com/ethereum/go-ethereum/crypto"
33-
"github.com/ethereum/go-ethereum/p2p/enode"
3433
"github.com/hashicorp/go-uuid"
3534
keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4"
3635
"gopkg.in/yaml.v2"
@@ -407,6 +406,11 @@ func ConnectRaw(service, port, protocol, user string) string {
407406
return fmt.Sprintf(`{{Service "%s" "%s" "%s" "%s"}}`, service, port, protocol, user)
408407
}
409408

409+
func ConnectEnode(service, id string) string {
410+
// Note, this assumes that all the enode ports are registered with the 'rpc' label.
411+
return ConnectRaw(service, "rpc", "enode", id)
412+
}
413+
410414
func Connect(service, port string) string {
411415
return ConnectRaw(service, port, "http", "")
412416
}
@@ -706,8 +710,13 @@ type EnodeAddr struct {
706710
Artifact string
707711
}
708712

709-
func (e *EnodeAddr) ID() enode.ID {
710-
return enode.PubkeyToIDV4(&e.PrivKey.PublicKey)
713+
func (e *EnodeAddr) PrivKeyHex() string {
714+
return hex.EncodeToString(gethcommon.LeftPadBytes(e.PrivKey.D.Bytes(), 32))
715+
}
716+
717+
func (e *EnodeAddr) NodeID() string {
718+
nodeid := fmt.Sprintf("%x", ecrypto.FromECDSAPub(&e.PrivKey.PublicKey)[1:])
719+
return nodeid
711720
}
712721

713722
func (o *output) GetEnodeAddr() *EnodeAddr {

playground/artifacts_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestEnodeGeneration(t *testing.T) {
1111
o2 := newTestOutput(t)
1212

1313
for i := 0; i < 10; i++ {
14-
if o1.GetEnodeAddr().ID() != o2.GetEnodeAddr().ID() {
14+
if o1.GetEnodeAddr().NodeID() != o2.GetEnodeAddr().NodeID() {
1515
t.Fatalf("enode IDs are not the same")
1616
}
1717
}

playground/components.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func (o *OpRbuilder) Run(service *Service, ctx *ExContext) {
7676
WithArtifact("/data/l2-genesis.json", "l2-genesis.json").
7777
WithVolume("data", "/data_op_reth")
7878

79+
if ctx.Bootnode != nil {
80+
service.WithArgs("--trusted-peers", ctx.Bootnode.Connect())
81+
}
82+
7983
if o.Flashblocks {
8084
service.WithArgs(
8185
"--flashblocks.enabled",
@@ -192,6 +196,11 @@ func logLevelToGethVerbosity(logLevel LogLevel) string {
192196
func (o *OpGeth) Run(service *Service, ctx *ExContext) {
193197
o.Enode = ctx.Output.GetEnodeAddr()
194198

199+
var trustedPeers string
200+
if ctx.Bootnode != nil {
201+
trustedPeers = fmt.Sprintf("--bootnodes %s ", ctx.Bootnode.Connect())
202+
}
203+
195204
service.
196205
WithImage("us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth").
197206
WithTag("v1.101503.2-rc.5").
@@ -226,6 +235,7 @@ func (o *OpGeth) Run(service *Service, ctx *ExContext) {
226235
"--state.scheme hash "+
227236
"--port "+`{{Port "rpc" 30303}} `+
228237
"--nodekey /data/p2p_key.txt "+
238+
trustedPeers+
229239
"--metrics "+
230240
"--metrics.addr 0.0.0.0 "+
231241
"--metrics.port "+`{{Port "metrics" 6061}}`,

playground/local_runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func printAddr(protocol, serviceName string, port int, user string) string {
554554
}
555555

556556
if user != "" {
557-
return fmt.Sprintf("%s%s@%s:%s", protocolPrefix, user, serviceName, serviceName)
557+
return fmt.Sprintf("%s%s@%s:%d", protocolPrefix, user, serviceName, port)
558558
}
559559

560560
return fmt.Sprintf("%s%s:%d", protocolPrefix, serviceName, port)

playground/manifest.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ type ExContext struct {
7878
// have to modify the serviceDesc interface to give services
7979
// access to the output.
8080
Output *output
81+
82+
// Bootnode reference for EL nodes.
83+
// TODO: Extend for CL nodes too
84+
Bootnode *BootnodeRef
85+
}
86+
87+
type BootnodeRef struct {
88+
Service string
89+
ID string
90+
}
91+
92+
func (b *BootnodeRef) Connect() string {
93+
return ConnectEnode(b.Service, b.ID)
8194
}
8295

8396
type ServiceGen interface {

playground/recipe_opstack.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ func (o *OpRecipe) Apply(ctx *ExContext, artifacts *Artifacts) *Manifest {
7070
flashblocksBuilderURLRef := o.flashblocksBuilderURL
7171
externalBuilderRef := o.externalBuilder
7272

73+
opGeth := &OpGeth{}
74+
svcManager.AddService("op-geth", opGeth)
75+
76+
ctx.Bootnode = &BootnodeRef{
77+
Service: "op-geth",
78+
ID: opGeth.Enode.NodeID(),
79+
}
80+
7381
if o.externalBuilder == "op-reth" {
7482
// Add a new op-reth service and connect it to Rollup-boost
7583
svcManager.AddService("op-reth", &OpReth{})
@@ -103,7 +111,7 @@ func (o *OpRecipe) Apply(ctx *ExContext, artifacts *Artifacts) *Manifest {
103111
L1Beacon: "beacon",
104112
L2Node: elNode,
105113
})
106-
svcManager.AddService("op-geth", &OpGeth{})
114+
107115
svcManager.AddService("op-batcher", &OpBatcher{
108116
L1Node: "el",
109117
L2Node: "op-geth",

0 commit comments

Comments
 (0)