genesis

package
v1.19.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT, MIT Imports: 19 Imported by: 5 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Subcommands = cli.Commands{
	{
		Name:  "l1",
		Usage: "Generates a L1 genesis state file",
		Flags: l1Flags,
		Action: func(ctx *cli.Context) error {
			deployConfig := ctx.String(deployConfigFlag.Name)
			config, err := genesis.NewDeployConfig(deployConfig)
			if err != nil {
				return err
			}

			var deployments *genesis.L1Deployments
			if l1Deployments := ctx.String(l1DeploymentsFlag.Name); l1Deployments != "" {
				deployments, err = genesis.NewL1Deployments(l1Deployments)
				if err != nil {
					return err
				}
			}

			if deployments != nil {
				config.SetDeployments(deployments)
			}

			cfg := logcli.DefaultCLIConfig()
			logger := logcli.NewLogger(ctx.App.Writer, cfg)
			if err := config.Check(logger); err != nil {
				return fmt.Errorf("deploy config at %s invalid: %w", deployConfig, err)
			}

			if err := config.CheckAddresses(); err != nil {
				return fmt.Errorf("deploy config at %s invalid: %w", deployConfig, err)
			}

			var dump *foundry.ForgeAllocs
			if l1Allocs := ctx.String(l1AllocsFlag.Name); l1Allocs != "" {
				dump, err = foundry.LoadForgeAllocs(l1Allocs)
				if err != nil {
					return err
				}
			}

			l1Genesis, err := genesis.BuildL1DeveloperGenesis(config, dump, deployments)
			if err != nil {
				return err
			}

			return jsonutil.WriteJSON(l1Genesis, ioutil.ToStdOutOrFileOrNoop(ctx.String(outfileL1Flag.Name), 0o666))
		},
	},
	{
		Name:  "l2",
		Usage: "Generates an L2 genesis file and rollup config suitable for a deployed network",
		Description: "Generating the L2 genesis depends on knowledge of L1 contract addresses for the bridge to be secure. " +
			"A deploy config and either a deployment directory or an L1 deployments file are used to create the L2 genesis. " +
			"The deploy directory and L1 deployments file are generated by the L1 contract deployments. " +
			"An L1 starting block is necessary, it can either be fetched dynamically using config in the deploy config " +
			"or it can be provided as a JSON file.",
		Flags: l2Flags,
		Action: func(ctx *cli.Context) error {
			cfg := logcli.DefaultCLIConfig()
			logger := logcli.NewLogger(ctx.App.Writer, cfg)

			deployConfig := ctx.Path(deployConfigFlag.Name)
			logger.Info("Deploy config", "path", deployConfig)
			config, err := genesis.NewDeployConfig(deployConfig)
			if err != nil {
				return err
			}

			l1Deployments := ctx.Path(l1DeploymentsFlag.Name)
			l1RPC := ctx.String(l1RPCFlag.Name)

			deployments, err := genesis.NewL1Deployments(l1Deployments)
			if err != nil {
				return fmt.Errorf("cannot read L1 deployments at %s: %w", l1Deployments, err)
			}
			config.SetDeployments(deployments)

			var l2Allocs *foundry.ForgeAllocs
			if l2AllocsPath := ctx.String(l2AllocsFlag.Name); l2AllocsPath != "" {
				l2Allocs, err = foundry.LoadForgeAllocs(l2AllocsPath)
				if err != nil {
					return err
				}
			} else {
				return errors.New("missing l2-allocs")
			}

			client, err := ethclient.Dial(l1RPC)
			if err != nil {
				return fmt.Errorf("cannot dial %s: %w", l1RPC, err)
			}

			caller := batching.NewMultiCaller(client.Client(), batching.DefaultBatchSize)
			sysCfg := NewSystemConfigContract(caller, config.SystemConfigProxy)
			startBlock, err := sysCfg.StartBlock(ctx.Context)
			if err != nil {
				return fmt.Errorf("failed to fetch startBlock from SystemConfig: %w", err)
			}

			logger.Info("Using L1 Start Block", "number", startBlock)

			l1StartBlock, err := retry.Do(ctx.Context, 24, retry.Fixed(1*time.Second), func() (*types.Block, error) { return client.BlockByNumber(ctx.Context, startBlock) })
			if err != nil {
				return fmt.Errorf("fetching start block by number: %w", err)
			}
			logger.Info("Fetched L1 Start Block", "hash", l1StartBlock.Hash().Hex())

			if err := config.Check(logger); err != nil {
				return err
			}

			l2Genesis, err := genesis.BuildL2Genesis(config, l2Allocs, eth.BlockRefFromHeader(l1StartBlock.Header()))
			if err != nil {
				return fmt.Errorf("error creating l2 genesis: %w", err)
			}

			l2GenesisBlock := l2Genesis.ToBlock()
			rollupConfig, err := config.RollupConfig(eth.BlockRefFromHeader(l1StartBlock.Header()), l2GenesisBlock.Hash(), l2GenesisBlock.NumberU64())
			if err != nil {
				return err
			}
			if err := rollupConfig.Check(); err != nil {
				return fmt.Errorf("generated rollup config does not pass validation: %w", err)
			}

			if err := jsonutil.WriteJSON(l2Genesis, ioutil.ToAtomicFile(ctx.String(outfileL2Flag.Name), 0o666)); err != nil {
				return err
			}
			return jsonutil.WriteJSON(rollupConfig, ioutil.ToAtomicFile(ctx.String(outfileRollupFlag.Name), 0o666))
		},
	},
}

Functions

This section is empty.

Types

type SystemConfigContract

type SystemConfigContract struct {
	// contains filtered or unexported fields
}

func NewSystemConfigContract

func NewSystemConfigContract(caller *batching.MultiCaller, addr common.Address) *SystemConfigContract

func (*SystemConfigContract) StartBlock

func (c *SystemConfigContract) StartBlock(ctx context.Context) (*big.Int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL