@@ -25,6 +25,7 @@ import (
2525 "github.com/ethereum-optimism/optimism/op-batcher/flags"
2626 "github.com/ethereum-optimism/optimism/op-e2e/config"
2727 "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/geth"
28+ "github.com/ethereum-optimism/optimism/op-e2e/faultproofs"
2829 "github.com/ethereum-optimism/optimism/op-e2e/system/e2esys"
2930 "github.com/ethereum/go-ethereum/common"
3031 "github.com/ethereum/go-ethereum/common/hexutil"
@@ -246,8 +247,8 @@ func (e EspressoDevNodeContainerInfo) Stop() error {
246247// is meant to be.
247248var ErrUnableToDetermineEspressoDevNodeSequencerHost = errors .New ("unable to determine the host for the espresso-dev-node sequencer api" )
248249
249- func ( l * EspressoDevNodeLauncherDocker ) StartDevNet ( ctx context. Context , t * testing. T , options ... DevNetLauncherOption ) ( * e2esys. System , EspressoDevNode , error ) {
250- originalCtx := ctx
250+ // GetDevNetConfig returns a configuration for a devnet
251+ func ( l * EspressoDevNodeLauncherDocker ) GetDevNetSysConfig ( ctx context. Context , t * testing. T , options ... DevNetLauncherOption ) e2esys. SystemConfig {
251252
252253 var allocOpt e2esys.SystemConfigOpt
253254 if l .EnclaveBatcher {
@@ -289,6 +290,57 @@ func (l *EspressoDevNodeLauncherDocker) StartDevNet(ctx context.Context, t *test
289290 sysConfig .L1Allocs [address ] = account .State
290291 }
291292
293+ return sysConfig
294+ }
295+
296+ // GetDevNetWithFaultDisputeSysConfig returns a configuration for a devnet with a Fault Dispute System
297+ func (l * EspressoDevNodeLauncherDocker ) GetDevNetWithFaultDisputeSysConfig (ctx context.Context , t * testing.T , options ... DevNetLauncherOption ) e2esys.SystemConfig {
298+ var allocOpt e2esys.SystemConfigOpt
299+ if l .EnclaveBatcher {
300+ allocOpt = e2esys .WithAllocType (config .AllocTypeEspressoWithEnclave )
301+ } else {
302+ allocOpt = e2esys .WithAllocType (config .AllocTypeEspressoWithoutEnclave )
303+ }
304+
305+ // Get a Fault Dispute System configuration with Espresso Dev Node allocation
306+ sysConfig := faultproofs .GetFaultDisputeSystemConfigForEspresso (t , []e2esys.SystemConfigOpt {allocOpt })
307+
308+ if l .AltDa {
309+ sysConfig .DeployConfig .UseAltDA = true
310+ sysConfig .DeployConfig .DACommitmentType = "KeccakCommitment"
311+ sysConfig .DeployConfig .DAChallengeWindow = 16
312+ sysConfig .DeployConfig .DAResolveWindow = 16
313+ sysConfig .DeployConfig .DABondSize = 1000000
314+ sysConfig .DeployConfig .DAResolverRefundPercentage = 0
315+ sysConfig .BatcherMaxPendingTransactions = 0
316+ sysConfig .BatcherBatchType = 0
317+ sysConfig .DataAvailabilityType = flags .CalldataType
318+ }
319+
320+ // Set a short L1 block time and finalized distance to make tests faster and reach finality sooner
321+ sysConfig .DeployConfig .L1BlockTime = 2
322+
323+ sysConfig .DeployConfig .DeployCeloContracts = true
324+
325+ // Ensure that we fund the dev accounts
326+ sysConfig .DeployConfig .FundDevAccounts = true
327+
328+ espressoPremine := new (big.Int ).Mul (new (big.Int ).SetUint64 (1_000_000 ), new (big.Int ).SetUint64 (params .Ether ))
329+ sysConfig .L1Allocs [ESPRESSO_CONTRACT_ACCOUNT ] = types.Account {
330+ Nonce : 100000 , // Set the nonce to avoid collisions with predeployed contracts
331+ Balance : espressoPremine , // Pre-fund Espresso deployer acount with 1M Ether
332+ }
333+
334+ //Set up the L1Allocs in the system config
335+ for address , account := range ESPRESSO_ALLOCS {
336+ sysConfig .L1Allocs [address ] = account .State
337+ }
338+
339+ return sysConfig
340+ }
341+
342+ // GetDevNetStartOptions returns the start options for the devnet
343+ func (l * EspressoDevNodeLauncherDocker ) GetDevNetStartOptions (originalCtx context.Context , t * testing.T , sysConfig * e2esys.SystemConfig , options ... DevNetLauncherOption ) ([]e2esys.StartOption , * DevNetLauncherContext ) {
292344 initialOptions := []DevNetLauncherOption {
293345 allowHostDockerInternalVirtualHost (),
294346 launchEspressoDevNodeDocker (),
@@ -300,12 +352,11 @@ func (l *EspressoDevNodeLauncherDocker) StartDevNet(ctx context.Context, t *test
300352
301353 launchContext := DevNetLauncherContext {
302354 Ctx : originalCtx ,
303- SystemCfg : & sysConfig ,
355+ SystemCfg : sysConfig ,
304356 }
305357
306358 allOptions := append (initialOptions , options ... )
307359
308- // getOptions := map[string][]geth.GethOption{}
309360 startOptions := []e2esys.StartOption {}
310361
311362 for _ , opt := range allOptions {
@@ -322,10 +373,20 @@ func (l *EspressoDevNodeLauncherDocker) StartDevNet(ctx context.Context, t *test
322373 }
323374
324375 if sysConfigOption := options .SysConfigOption ; sysConfigOption != nil {
325- sysConfigOption (& sysConfig )
376+ sysConfigOption (sysConfig )
326377 }
327378 }
328379
380+ return startOptions , & launchContext
381+ }
382+
383+ func (l * EspressoDevNodeLauncherDocker ) StartDevNet (ctx context.Context , t * testing.T , options ... DevNetLauncherOption ) (* e2esys.System , EspressoDevNode , error ) {
384+
385+ sysConfig := l .GetDevNetSysConfig (ctx , t , options ... )
386+
387+ originalCtx := ctx
388+ startOptions , launchContext := l .GetDevNetStartOptions (originalCtx , t , & sysConfig , options ... )
389+
329390 // We want to run the espresso-dev-node. But we need it to be able to
330391 // access the L1 node.
331392
@@ -334,7 +395,47 @@ func (l *EspressoDevNodeLauncherDocker) StartDevNet(ctx context.Context, t *test
334395
335396 startOptions ... ,
336397 )
337- launchContext .System = system
398+
399+ if err != nil {
400+ if system != nil {
401+ // We don't want the system running in a partial / incomplete
402+ // state. So we'll tell it to stop here, just in case.
403+ system .Close ()
404+ }
405+
406+ return system , nil , err
407+ }
408+
409+ // Auto System Cleanup tied to the passed in context.
410+ {
411+ // We want to ensure that the lifecycle of the system node is tied to
412+ // the context we were given, just like the espresso-dev-node. So if
413+ // the context is canceled, or otherwise closed, it will automatically
414+ // clean up the system.
415+ go (func (ctx context.Context ) {
416+ <- ctx .Done ()
417+
418+ // The system is guaranteed to not be null here.
419+ system .Close ()
420+ })(originalCtx )
421+ }
422+
423+ return system , launchContext .EspressoDevNode , launchContext .Error
424+ }
425+
426+ // StartDevNetWithFaultDisputeSystem starts a Fault Dispute System with an Espresso Dev Node
427+ func (l * EspressoDevNodeLauncherDocker ) StartDevNetWithFaultDisputeSystem (ctx context.Context , t * testing.T , options ... DevNetLauncherOption ) (* e2esys.System , EspressoDevNode , error ) {
428+
429+ sysConfig := l .GetDevNetWithFaultDisputeSysConfig (ctx , t , options ... )
430+
431+ originalCtx := ctx
432+ startOptions , launchContext := l .GetDevNetStartOptions (originalCtx , t , & sysConfig , options ... )
433+
434+ system , err := sysConfig .Start (
435+ t ,
436+
437+ startOptions ... ,
438+ )
338439
339440 if err != nil {
340441 if system != nil {
0 commit comments