forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsinglechain_build.go
More file actions
708 lines (645 loc) · 22.9 KB
/
singlechain_build.go
File metadata and controls
708 lines (645 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
package sysgo
import (
"context"
"encoding/hex"
"flag"
"fmt"
"time"
"github.com/urfave/cli/v2"
altda "github.com/ethereum-optimism/optimism/op-alt-da"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params/forks"
"github.com/ethereum-optimism/optimism/op-chain-ops/devkeys"
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/intentbuilder"
faucetConfig "github.com/ethereum-optimism/optimism/op-faucet/config"
"github.com/ethereum-optimism/optimism/op-faucet/faucet"
fconf "github.com/ethereum-optimism/optimism/op-faucet/faucet/backend/config"
ftypes "github.com/ethereum-optimism/optimism/op-faucet/faucet/backend/types"
"github.com/ethereum-optimism/optimism/op-node/config"
opNodeFlags "github.com/ethereum-optimism/optimism/op-node/flags"
"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/driver"
"github.com/ethereum-optimism/optimism/op-node/rollup/interop"
nodeSync "github.com/ethereum-optimism/optimism/op-node/rollup/sync"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum-optimism/optimism/op-service/dial"
"github.com/ethereum-optimism/optimism/op-service/endpoint"
"github.com/ethereum-optimism/optimism/op-service/eth"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/ethereum-optimism/optimism/op-service/oppprof"
"github.com/ethereum-optimism/optimism/op-service/retry"
oprpc "github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum-optimism/optimism/op-supervisor/supervisor/backend/depset"
sequencerConfig "github.com/ethereum-optimism/optimism/op-test-sequencer/config"
testmetrics "github.com/ethereum-optimism/optimism/op-test-sequencer/metrics"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/builders/fakepos"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/builders/standardbuilder"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/committers/noopcommitter"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/committers/standardcommitter"
workconfig "github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/config"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/publishers/nooppublisher"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/publishers/standardpublisher"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/sequencers/fullseq"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/signers/localkey"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/backend/work/signers/noopsigner"
"github.com/ethereum-optimism/optimism/op-test-sequencer/sequencer/seqtypes"
)
type testSequencer struct {
name string
adminRPC string
jwtSecret [32]byte
controlRPC map[eth.ChainID]string
service *sequencer.Service
}
func buildSingleChainWorld(t devtest.T, keys devkeys.Keys, localContractArtifactsPath string, deployerOpts ...DeployerOption) (*L1Network, *L2Network) {
wb := &worldBuilder{
p: t,
logger: t.Logger(),
require: t.Require(),
keys: keys,
builder: intentbuilder.New(),
}
applyConfigLocalContractSources(t, keys, wb.builder, localContractArtifactsPath)
applyConfigCommons(t, keys, DefaultL1ID, wb.builder)
applyConfigPrefundedL2(t, keys, DefaultL1ID, DefaultL2AID, wb.builder)
applyConfigDeployerOptions(t, keys, wb.builder, deployerOpts)
wb.Build()
t.Require().Len(wb.l2Chains, 1, "expected exactly one L2 chain in flashblocks world")
l2ID := wb.l2Chains[0]
l1ID := eth.ChainIDFromUInt64(wb.output.AppliedIntent.L1ChainID)
l1Net := &L1Network{
name: "l1",
chainID: l1ID,
genesis: wb.outL1Genesis,
blockTime: 6,
}
l2Net := &L2Network{
name: "l2a",
chainID: l2ID,
l1ChainID: l1ID,
genesis: wb.outL2Genesis[l2ID],
rollupCfg: wb.outL2RollupCfg[l2ID],
deployment: wb.outL2Deployment[l2ID],
opcmImpl: wb.output.ImplementationsDeployment.OpcmImpl,
mipsImpl: wb.output.ImplementationsDeployment.MipsImpl,
keys: keys,
}
return l1Net, l2Net
}
func applyConfigLocalContractSources(t devtest.T, _ devkeys.Keys, builder intentbuilder.Builder, artifactsPath string) {
contractArtifacts, err := localContractSourcesLocator(artifactsPath)
t.Require().NoError(err)
builder.WithL1ContractsLocator(contractArtifacts)
builder.WithL2ContractsLocator(contractArtifacts)
}
func applyConfigCommons(t devtest.T, keys devkeys.Keys, l1ChainID eth.ChainID, builder intentbuilder.Builder) {
_, l1Config := builder.WithL1(l1ChainID)
l1StartTimestamp := uint64(time.Now().Unix()) + 1
l1Config.WithTimestamp(l1StartTimestamp)
l1Config.WithL1ForkAtGenesis(forks.Prague)
faucetFunderAddr, err := keys.Address(devkeys.UserKey(funderMnemonicIndex))
t.Require().NoError(err, "need funder addr")
l1Config.WithPrefundedAccount(faucetFunderAddr, *eth.BillionEther.ToU256())
addrFor := intentbuilder.RoleToAddrProvider(t, keys, l1ChainID)
_, superCfg := builder.WithSuperchain()
intentbuilder.WithDevkeySuperRoles(t, keys, l1ChainID, superCfg)
l1Config.WithPrefundedAccount(addrFor(devkeys.SuperchainProxyAdminOwner), *millionEth)
l1Config.WithPrefundedAccount(addrFor(devkeys.SuperchainProtocolVersionsOwner), *millionEth)
l1Config.WithPrefundedAccount(addrFor(devkeys.SuperchainConfigGuardianKey), *millionEth)
l1Config.WithPrefundedAccount(addrFor(devkeys.L1ProxyAdminOwnerRole), *millionEth)
}
func applyConfigPrefundedL2(t devtest.T, keys devkeys.Keys, l1ChainID, l2ChainID eth.ChainID, builder intentbuilder.Builder) {
_, l2Config := builder.WithL2(l2ChainID)
intentbuilder.WithDevkeyVaults(t, keys, l2Config)
intentbuilder.WithDevkeyL2Roles(t, keys, l2Config)
intentbuilder.WithDevkeyL1Roles(t, keys, l2Config, l1ChainID)
faucetFunderAddr, err := keys.Address(devkeys.UserKey(funderMnemonicIndex))
t.Require().NoError(err, "need funder addr")
l2Config.WithPrefundedAccount(faucetFunderAddr, *eth.BillionEther.ToU256())
addrFor := intentbuilder.RoleToAddrProvider(t, keys, l2ChainID)
l1Config := l2Config.L1Config()
l1Config.WithPrefundedAccount(addrFor(devkeys.BatcherRole), *millionEth)
l1Config.WithPrefundedAccount(addrFor(devkeys.ProposerRole), *millionEth)
l1Config.WithPrefundedAccount(addrFor(devkeys.ChallengerRole), *millionEth)
l1Config.WithPrefundedAccount(addrFor(devkeys.SystemConfigOwner), *millionEth)
}
// startL2ELForKey starts an L2 EL node for the given key, respecting DEVSTACK_L2EL_KIND.
// This is the single env-aware dispatch point for L2 EL selection.
func startL2ELForKey(t devtest.T, l2Net *L2Network, jwtPath string, jwtSecret [32]byte, key string, identity *ELNodeIdentity) L2ELNode {
switch devstackL2ELKind() {
case MixedL2ELOpGeth:
return startL2ELNode(t, l2Net, jwtPath, jwtSecret, key, identity)
default: // op-reth
return startMixedOpRethNode(t, l2Net, key, jwtPath, jwtSecret, nil, "v1")
}
}
// startL2CLForKey starts an L2 CL node for the given key, respecting DEVSTACK_L2CL_KIND.
// This is the single env-aware dispatch point for L2 CL selection.
func startL2CLForKey(
t devtest.T,
keys devkeys.Keys,
l1Net *L1Network,
l2Net *L2Network,
l1EL L1ELNode,
l1CL *L1CLNode,
l2EL L2ELNode,
jwtSecret [32]byte,
clKey, elKey string,
isSequencer bool,
followSource string,
l2CLOpts []L2CLOption,
) L2CLNode {
switch devstackL2CLKind() {
case MixedL2CLKona:
return startMixedKonaNode(t, keys, l1Net, l2Net, l1EL, l1CL, l2EL, clKey, elKey, isSequencer, nil)
default: // op-node
return startL2CLNode(t, keys, l1Net, l2Net, l1EL, l1CL, l2EL, jwtSecret, l2CLNodeStartConfig{
Key: clKey,
IsSequencer: isSequencer,
NoDiscovery: true,
EnableReqResp: true,
UseReqResp: true,
L2FollowSource: followSource,
L2CLOptions: l2CLOpts,
})
}
}
func startSequencerEL(t devtest.T, l2Net *L2Network, jwtPath string, jwtSecret [32]byte, identity *ELNodeIdentity) L2ELNode {
return startL2ELForKey(t, l2Net, jwtPath, jwtSecret, "sequencer", identity)
}
func startL2ELNode(
t devtest.T,
l2Net *L2Network,
jwtPath string,
jwtSecret [32]byte,
key string,
identity *ELNodeIdentity,
) *OpGeth {
cfg := DefaultL2ELConfig()
cfg.P2PAddr = "127.0.0.1"
cfg.P2PPort = identity.Port
cfg.P2PNodeKeyHex = identity.KeyHex()
l2EL := &OpGeth{
name: key,
p: t,
logger: t.Logger().New("component", "l2el-"+key),
l2Net: l2Net,
jwtPath: jwtPath,
jwtSecret: jwtSecret,
cfg: cfg,
}
l2EL.Start()
t.Cleanup(l2EL.Stop)
return l2EL
}
func connectL2ELPeers(t devtest.T, logger log.Logger, initiatorRPC, acceptorRPC string, trusted bool) {
require := t.Require()
rpc1, err := dial.DialRPCClientWithTimeout(t.Ctx(), logger, initiatorRPC)
require.NoError(err, "failed to connect initiator EL RPC")
defer rpc1.Close()
rpc2, err := dial.DialRPCClientWithTimeout(t.Ctx(), logger, acceptorRPC)
require.NoError(err, "failed to connect acceptor EL RPC")
defer rpc2.Close()
ConnectP2P(t.Ctx(), require, rpc1, rpc2, trusted)
}
func connectL2CLPeers(t devtest.T, logger log.Logger, l2CL1, l2CL2 L2CLNode) {
require := t.Require()
ctx := t.Ctx()
p := getP2PClientsAndPeers(ctx, logger, require, l2CL1, l2CL2)
connectPeer := func(p2pClient *sources.P2PClient, multiAddress string) {
err := retry.Do0(ctx, 6, retry.Exponential(), func() error {
return p2pClient.ConnectPeer(ctx, multiAddress)
})
require.NoError(err, "failed to connect L2CL peer")
}
connectPeer(p.client1, p.peerInfo2.Addresses[0])
connectPeer(p.client2, p.peerInfo1.Addresses[0])
peerDump1, err := GetPeers(ctx, p.client1)
require.NoError(err)
peerDump2, err := GetPeers(ctx, p.client2)
require.NoError(err)
_, ok1 := peerDump1.Peers[p.peerInfo2.PeerID.String()]
require.True(ok1, "peer register invalid (cl1 missing cl2)")
_, ok2 := peerDump2.Peers[p.peerInfo1.PeerID.String()]
require.True(ok2, "peer register invalid (cl2 missing cl1)")
}
func startSequencerCL(
t devtest.T,
keys devkeys.Keys,
l1Net *L1Network,
l2Net *L2Network,
l1EL L1ELNode,
l1CL *L1CLNode,
l2EL L2ELNode,
jwtSecret [32]byte,
l2CLOpts []L2CLOption,
) L2CLNode {
return startL2CLForKey(t, keys, l1Net, l2Net, l1EL, l1CL, l2EL, jwtSecret, "sequencer", "sequencer", true, "", l2CLOpts)
}
type l2CLNodeStartConfig struct {
Key string
IsSequencer bool
NoDiscovery bool
EnableReqResp bool
UseReqResp bool
IndexingMode bool
L2FollowSource string
DependencySet depset.DependencySet
L2CLOptions []L2CLOption
}
func startL2CLNode(
t devtest.T,
keys devkeys.Keys,
l1Net *L1Network,
l2Net *L2Network,
l1EL L1ELNode,
l1CL *L1CLNode,
l2EL L2ELNode,
jwtSecret [32]byte,
startCfg l2CLNodeStartConfig,
) *OpNode {
require := t.Require()
cfg := DefaultL2CLConfig()
cfg.IsSequencer = startCfg.IsSequencer
cfg.NoDiscovery = startCfg.NoDiscovery
cfg.EnableReqRespSync = startCfg.EnableReqResp
cfg.UseReqRespSync = startCfg.UseReqResp
cfg.IndexingMode = startCfg.IndexingMode
cfg.FollowSource = startCfg.L2FollowSource
if len(startCfg.L2CLOptions) > 0 {
l2CLTarget := NewComponentTarget(startCfg.Key, l2Net.ChainID())
for _, opt := range startCfg.L2CLOptions {
if opt == nil {
continue
}
opt.Apply(t, l2CLTarget, cfg)
}
}
syncMode := cfg.VerifierSyncMode
if cfg.IsSequencer {
syncMode = cfg.SequencerSyncMode
}
logger := t.Logger().New("component", "l2cl-"+startCfg.Key)
// Build P2P config through the same path as sysgo op-node setup.
fs := flag.NewFlagSet("", flag.ContinueOnError)
for _, f := range opNodeFlags.P2PFlags(opNodeFlags.EnvVarPrefix) {
require.NoError(f.Apply(fs))
}
require.NoError(fs.Set(opNodeFlags.AdvertiseIPName, "127.0.0.1"))
require.NoError(fs.Set(opNodeFlags.AdvertiseTCPPortName, "0"))
require.NoError(fs.Set(opNodeFlags.AdvertiseUDPPortName, "0"))
require.NoError(fs.Set(opNodeFlags.ListenIPName, "127.0.0.1"))
require.NoError(fs.Set(opNodeFlags.ListenTCPPortName, "0"))
require.NoError(fs.Set(opNodeFlags.ListenUDPPortName, "0"))
require.NoError(fs.Set(opNodeFlags.DiscoveryPathName, "memory"))
require.NoError(fs.Set(opNodeFlags.PeerstorePathName, "memory"))
require.NoError(fs.Set(opNodeFlags.BootnodesName, ""))
networkPrivKey, err := crypto.GenerateKey()
require.NoError(err)
networkPrivKeyHex := hex.EncodeToString(crypto.FromECDSA(networkPrivKey))
require.NoError(fs.Set(opNodeFlags.P2PPrivRawName, networkPrivKeyHex))
cliCtx := cli.NewContext(&cli.App{}, fs, nil)
var p2pSignerSetup p2p.SignerSetup
if cfg.IsSequencer {
p2pKey, err := keys.Secret(devkeys.SequencerP2PRole.Key(l2Net.ChainID().ToBig()))
require.NoError(err, "need p2p key for sequencer")
p2pKeyHex := hex.EncodeToString(crypto.FromECDSA(p2pKey))
require.NoError(fs.Set(opNodeFlags.SequencerP2PKeyName, p2pKeyHex))
p2pSignerSetup, err = p2pcli.LoadSignerSetup(cliCtx, logger)
require.NoError(err, "failed to load p2p signer")
}
p2pConfig, err := p2pcli.NewConfig(cliCtx, l2Net.rollupCfg.BlockTime)
require.NoError(err, "failed to load p2p config")
p2pConfig.NoDiscovery = cfg.NoDiscovery
p2pConfig.EnableReqRespSync = cfg.EnableReqRespSync
interopCfg := &interop.Config{}
if startCfg.IndexingMode {
interopCfg = &interop.Config{
RPCAddr: "127.0.0.1",
RPCPort: 0,
RPCJwtSecretPath: l2EL.JWTPath(),
}
}
nodeCfg := &config.Config{
L1: &config.L1EndpointConfig{
L1NodeAddr: l1EL.UserRPC(),
L1TrustRPC: false,
L1RPCKind: sources.RPCKindDebugGeth,
RateLimit: 0,
BatchSize: 20,
HttpPollInterval: 100,
MaxConcurrency: 10,
CacheSize: 0,
},
L1ChainConfig: l1Net.genesis.Config,
L2: &config.L2EndpointConfig{
L2EngineAddr: l2EL.EngineRPC(),
L2EngineJWTSecret: jwtSecret,
},
L2FollowSource: &config.L2FollowSourceConfig{
L2RPCAddr: cfg.FollowSource,
},
Beacon: &config.L1BeaconEndpointConfig{
BeaconAddr: l1CL.beaconHTTPAddr,
},
Driver: driver.Config{
SequencerEnabled: cfg.IsSequencer,
SequencerConfDepth: 2,
},
Rollup: *l2Net.rollupCfg,
DependencySet: startCfg.DependencySet,
SupervisorEnabled: cfg.IndexingMode,
P2PSigner: p2pSignerSetup,
RPC: oprpc.CLIConfig{
ListenAddr: "127.0.0.1",
ListenPort: 0,
EnableAdmin: true,
},
InteropConfig: interopCfg,
P2P: p2pConfig,
L1EpochPollInterval: time.Second * 2,
RuntimeConfigReloadInterval: 0,
Tracer: nil,
Sync: nodeSync.Config{
SyncMode: syncMode,
SyncModeReqResp: cfg.UseReqRespSync,
SkipSyncStartCheck: false,
SupportsPostFinalizationELSync: false,
L2FollowSourceEndpoint: cfg.FollowSource,
NeedInitialResetEngine: false,
},
ConfigPersistence: config.DisabledConfigPersistence{},
Metrics: opmetrics.CLIConfig{},
Pprof: oppprof.CLIConfig{},
SafeDBPath: cfg.SafeDBPath,
RollupHalt: "",
Cancel: nil,
ConductorEnabled: false,
ConductorRpc: nil,
ConductorRpcTimeout: 0,
AltDA: altda.CLIConfig{},
IgnoreMissingPectraBlobSchedule: false,
ExperimentalOPStackAPI: true,
}
l2CL := &OpNode{
name: startCfg.Key,
opNode: nil,
cfg: nodeCfg,
p: t,
logger: logger,
clock: clock.SystemClock,
}
l2CL.Start()
t.Cleanup(l2CL.Stop)
return l2CL
}
func startTestSequencer(
t devtest.T,
keys devkeys.Keys,
jwtPath string,
jwtSecret [32]byte,
l1Net *L1Network,
l1EL *L1Geth,
l1CL *L1CLNode,
l2EL L2ELNode,
l2Net *L2Network,
l2CL *OpNode,
) *testSequencer {
require := t.Require()
logger := t.Logger().New("component", "test-sequencer")
l1ELClient, err := ethclient.DialContext(t.Ctx(), l1EL.UserRPC())
require.NoError(err, "failed to dial L1 EL RPC for test-sequencer")
t.Cleanup(l1ELClient.Close)
engineCl, err := dialEngine(t.Ctx(), l1EL.AuthRPC(), jwtSecret)
require.NoError(err, "failed to dial L1 engine API for test-sequencer")
t.Cleanup(func() {
engineCl.inner.Close()
})
l1ChainID := l1Net.ChainID()
l2ChainID := l2Net.ChainID()
// L1 sequencer components: fakepos builder + noop signer/committer/publisher.
bidL1 := seqtypes.BuilderID("test-l1-builder")
cidL1 := seqtypes.CommitterID("test-noop-committer")
sidL1 := seqtypes.SignerID("test-noop-signer")
pidL1 := seqtypes.PublisherID("test-noop-publisher")
seqIDL1 := seqtypes.SequencerID(fmt.Sprintf("test-seq-%s", l1ChainID))
ensemble := &workconfig.Ensemble{
Builders: map[seqtypes.BuilderID]*workconfig.BuilderEntry{
bidL1: {
L1: &fakepos.Config{
ChainConfig: l1Net.genesis.Config,
EngineAPI: engineCl,
Backend: l1ELClient,
Beacon: l1CL.beacon,
FinalizedDistance: 20,
SafeDistance: 10,
BlockTime: 6,
},
},
},
Signers: map[seqtypes.SignerID]*workconfig.SignerEntry{
sidL1: {
Noop: &noopsigner.Config{},
},
},
Committers: map[seqtypes.CommitterID]*workconfig.CommitterEntry{
cidL1: {
Noop: &noopcommitter.Config{},
},
},
Publishers: map[seqtypes.PublisherID]*workconfig.PublisherEntry{
pidL1: {
Noop: &nooppublisher.Config{},
},
},
Sequencers: map[seqtypes.SequencerID]*workconfig.SequencerEntry{
seqIDL1: {
Full: &fullseq.Config{
ChainID: l1ChainID,
Builder: bidL1,
Signer: sidL1,
Committer: cidL1,
Publisher: pidL1,
},
},
},
}
// L2 sequencer components: standard builder/committer/publisher + local signer.
bidL2 := seqtypes.BuilderID("test-standard-builder")
cidL2 := seqtypes.CommitterID("test-standard-committer")
sidL2 := seqtypes.SignerID("test-local-signer")
pidL2 := seqtypes.PublisherID("test-standard-publisher")
seqIDL2 := seqtypes.SequencerID(fmt.Sprintf("test-seq-%s", l2ChainID))
p2pKey, err := keys.Secret(devkeys.SequencerP2PRole.Key(l2ChainID.ToBig()))
require.NoError(err, "need p2p key for test sequencer")
rawKey := hexutil.Bytes(crypto.FromECDSA(p2pKey))
ensemble.Builders[bidL2] = &workconfig.BuilderEntry{
Standard: &standardbuilder.Config{
L1ChainConfig: l1Net.genesis.Config,
L1EL: endpoint.MustRPC{
Value: endpoint.HttpURL(l1EL.UserRPC()),
},
L2EL: endpoint.MustRPC{
Value: endpoint.HttpURL(l2EL.UserRPC()),
},
L2CL: endpoint.MustRPC{
Value: endpoint.HttpURL(l2CL.UserRPC()),
},
},
}
ensemble.Signers[sidL2] = &workconfig.SignerEntry{
LocalKey: &localkey.Config{
RawKey: &rawKey,
ChainID: l2ChainID,
},
}
ensemble.Committers[cidL2] = &workconfig.CommitterEntry{
Standard: &standardcommitter.Config{
RPC: endpoint.MustRPC{
Value: endpoint.HttpURL(l2CL.UserRPC()),
},
},
}
ensemble.Publishers[pidL2] = &workconfig.PublisherEntry{
Standard: &standardpublisher.Config{
RPC: endpoint.MustRPC{
Value: endpoint.HttpURL(l2CL.UserRPC()),
},
},
}
ensemble.Sequencers[seqIDL2] = &workconfig.SequencerEntry{
Full: &fullseq.Config{
ChainID: l2ChainID,
Builder: bidL2,
Signer: sidL2,
Committer: cidL2,
Publisher: pidL2,
SequencerConfDepth: 2,
SequencerEnabled: true,
SequencerStopped: false,
SequencerMaxSafeLag: 0,
},
}
sequencerIDs := map[eth.ChainID]seqtypes.SequencerID{
l1ChainID: seqIDL1,
l2ChainID: seqIDL2,
}
jobs := work.NewJobRegistry()
startedEnsemble, err := ensemble.Start(t.Ctx(), &work.StartOpts{
Log: logger,
Metrics: &testmetrics.NoopMetrics{},
Jobs: jobs,
})
require.NoError(err, "failed to start test-sequencer ensemble")
cfg := &sequencerConfig.Config{
MetricsConfig: opmetrics.CLIConfig{
Enabled: false,
},
PprofConfig: oppprof.CLIConfig{
ListenEnabled: false,
},
LogConfig: oplog.CLIConfig{
Level: log.LevelDebug,
Format: oplog.FormatText,
},
RPC: oprpc.CLIConfig{
ListenAddr: "127.0.0.1",
ListenPort: 0,
EnableAdmin: true,
},
Ensemble: startedEnsemble,
JWTSecretPath: jwtPath,
Version: "dev",
MockRun: false,
}
sq, err := sequencer.FromConfig(t.Ctx(), cfg, logger)
require.NoError(err, "failed to initialize test-sequencer service")
require.NoError(sq.Start(t.Ctx()), "failed to start test-sequencer service")
t.Cleanup(func() {
ctx, cancel := context.WithCancel(t.Ctx())
cancel()
logger.Info("Closing test-sequencer service")
closeErr := sq.Stop(ctx)
logger.Info("Closed test-sequencer service", "err", closeErr)
})
adminRPC := sq.RPC()
controlRPCs := make(map[eth.ChainID]string, len(sequencerIDs))
for chainID, seqID := range sequencerIDs {
controlRPCs[chainID] = adminRPC + "/sequencers/" + seqID.String()
}
return &testSequencer{
name: "test-sequencer",
adminRPC: adminRPC,
jwtSecret: jwtSecret,
controlRPC: controlRPCs,
service: sq,
}
}
func startFaucets(
t devtest.T,
keys devkeys.Keys,
l1ChainID eth.ChainID,
l2ChainID eth.ChainID,
l1ELRPC string,
l2ELRPC string,
) *faucet.Service {
require := t.Require()
logger := t.Logger().New("component", "faucet")
funderKey, err := keys.Secret(devkeys.UserKey(funderMnemonicIndex))
require.NoError(err, "need faucet funder key")
funderKeyStr := hexutil.Encode(crypto.FromECDSA(funderKey))
faucets := map[ftypes.FaucetID]*fconf.FaucetEntry{
ftypes.FaucetID(fmt.Sprintf("dev-faucet-%s", l1ChainID)): {
ELRPC: endpoint.MustRPC{Value: endpoint.URL(l1ELRPC)},
ChainID: l1ChainID,
TxCfg: fconf.TxManagerConfig{
PrivateKey: funderKeyStr,
},
},
ftypes.FaucetID(fmt.Sprintf("dev-faucet-%s", l2ChainID)): {
ELRPC: endpoint.MustRPC{Value: endpoint.URL(l2ELRPC)},
ChainID: l2ChainID,
TxCfg: fconf.TxManagerConfig{
PrivateKey: funderKeyStr,
},
},
}
cfg := &faucetConfig.Config{
RPC: oprpc.CLIConfig{
ListenAddr: "127.0.0.1",
},
Faucets: &fconf.Config{
Faucets: faucets,
},
}
srv, err := faucet.FromConfig(t.Ctx(), cfg, logger)
require.NoError(err, "failed to create faucet service")
require.NoError(srv.Start(t.Ctx()), "failed to start faucet service")
t.Cleanup(func() {
ctx, cancel := context.WithCancel(context.Background())
cancel() // force-close
logger.Info("Closing faucet service")
closeErr := srv.Stop(ctx)
logger.Info("Closed faucet service", "err", closeErr)
})
return srv
}
func copyControlRPCMap(in map[eth.ChainID]string) map[eth.ChainID]string {
if len(in) == 0 {
return nil
}
out := make(map[eth.ChainID]string, len(in))
for chainID, endpoint := range in {
out[chainID] = endpoint
}
return out
}