• Evan Richard's avatar
    Ecotone/Dencun implementation changes (#8707) · 705db877
    Evan Richard authored
    * op-node: L2 Dencun implementation updates
    
    init branch
    
    Update reference to Eclipse/Ecotone in specs.
    
    Pull in Danyal's deposit source and add additional tests.
    
    Add notion of ParentBeaconRoot and build a contract deploy tx in attributes.go.
    
    Add a test for activating dencun l2 fork after genesis.
    
    Add draft ecotone setup.
    
    Add first pass of Eclipse upgrade txns
    
    Fix tests/compile
    
    Code review feedback
    
    Obey linter.
    
    Move ecotone setup to helpers.go; get the ParentBeaconBlockRoot from the l1Info in attributes.go.
    
    chore(op-node): Add tests for Ecotone deposit transactions (#8746)
    
    * Source hash teEvanJRichard <evan@oplabs.co>
    
    dencun review fixes
    
    derive: ecotone upgradeTo abi encoding
    
    op-e2e: test L2 exclusion of blob-txs in Ecotone
    
    op-node/rollup: deduplicate ecotone activation helper func, fix rollup config var name
    
    op-chain-ops: clarify 4788 contract nonce
    
    op-node/rollup: add setEcotone to ecotone upgrade txs
    
    dencun review fixes
    
    Dencun: P2P / EngineAPI / ExecutionPayloadEnvelope changes
    
    Includes:
    - Pass through execution payload (Envelope type everywhere) by Danyal,
      extended by Proto
    - Fix ecotone upgrade txns, by Danyal
    - ci fixes by Danyal
    - P2P Req/Resp (version based encoding/decoding) by Danyal
    - EngineAPI v3 usage by Danyl, rebased by Proto on EngineController (from
      trianglesphere)
    - Block v3 Gossip validation, by Danyal
    - Block v3 Gossip publishing, by Proto
    
    Rebased on updated Ecotone / Dencun base branch
    
    op-e2e: fix upgrade-txs count in test
    
    op-node: fix l1 info scalar migration, implement dencun review suggestions
    
    op-node: more dencun review nit fixes
    
    op-node: rabbit suggestions, but fixed
    
    Fix nil pointer in p2p sync for Ecotone blocks
    
    dencun: fix more nits
    
    op-e2e: fix lint
    Co-authored-by: default avatarDanyal Prout <me@dany.al>
    Co-authored-by: default avatarprotolambda <proto@protolambda.com>
    Co-authored-by: default avatarEvanJRichard <evan@oplabs.co>
    
    * Add tests for attribute matching
    
    * Provide a no-op blob fetcher to prevent derivation error
    
    Fail tests when there is an unknown error
    
    Fix typo / empty array to nil
    
    Update L2 tests to ecotone / add additional checks
    
    * op-e2e: dencun action-test setup fixes
    
    * op-node: op-conductor dencun todo
    
    * dencun: fix review nit about parent beacon block root gossip check style
    
    ---------
    Co-authored-by: default avatarDanyal Prout <me@dany.al>
    Co-authored-by: default avatarprotolambda <proto@protolambda.com>
    705db877
entrypoint.go 3.01 KB
package bootnode

import (
	"context"
	"errors"
	"fmt"

	"github.com/libp2p/go-libp2p/core/peer"
	"github.com/urfave/cli/v2"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/log"

	opnode "github.com/ethereum-optimism/optimism/op-node"
	"github.com/ethereum-optimism/optimism/op-node/metrics"
	"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"
	"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/opio"
)

type gossipNoop struct{}

func (g *gossipNoop) OnUnsafeL2Payload(_ context.Context, _ peer.ID, _ *eth.ExecutionPayloadEnvelope) error {
	return nil
}

type gossipConfig struct{}

func (g *gossipConfig) P2PSequencerAddress() common.Address {
	return common.Address{}
}

type l2Chain struct{}

func (l *l2Chain) PayloadByNumber(_ context.Context, _ uint64) (*eth.ExecutionPayloadEnvelope, error) {
	return nil, nil
}

func Main(cliCtx *cli.Context) error {
	log.Info("Initializing bootnode")
	logCfg := oplog.ReadCLIConfig(cliCtx)
	logger := oplog.NewLogger(oplog.AppOut(cliCtx), logCfg)
	oplog.SetGlobalLogHandler(logger.GetHandler())
	m := metrics.NewMetrics("default")
	ctx := context.Background()

	config, err := opnode.NewRollupConfig(logger, cliCtx)
	if err != nil {
		return err
	}
	if err = validateConfig(config); err != nil {
		return err
	}

	p2pConfig, err := p2pcli.NewConfig(cliCtx, config)
	if err != nil {
		return fmt.Errorf("failed to load p2p config: %w", err)
	}

	p2pNode, err := p2p.NewNodeP2P(ctx, config, logger, p2pConfig, &gossipNoop{}, &l2Chain{}, &gossipConfig{}, m, false)
	if err != nil || p2pNode == nil {
		return err
	}
	if p2pNode.Dv5Udp() == nil {
		return fmt.Errorf("uninitialized discovery service")
	}

	go p2pNode.DiscoveryProcess(ctx, logger, config, p2pConfig.TargetPeers())

	metricsCfg := opmetrics.ReadCLIConfig(cliCtx)
	if metricsCfg.Enabled {
		log.Debug("starting metrics server", "addr", metricsCfg.ListenAddr, "port", metricsCfg.ListenPort)
		metricsSrv, err := m.StartServer(metricsCfg.ListenAddr, metricsCfg.ListenPort)
		if err != nil {
			return fmt.Errorf("failed to start metrics server: %w", err)
		}
		defer func() {
			if err := metricsSrv.Stop(context.Background()); err != nil {
				log.Error("failed to stop metrics server", "err", err)
			}
		}()
		log.Info("started metrics server", "addr", metricsSrv.Addr())
		m.RecordUp()
	}

	opio.BlockOnInterrupts()

	return nil
}

// validateConfig ensures the minimal config required to run a bootnode
func validateConfig(config *rollup.Config) error {
	if config.L2ChainID == nil || config.L2ChainID.Uint64() == 0 {
		return errors.New("chain ID is not set")
	}
	if config.Genesis.L2Time <= 0 {
		return errors.New("genesis timestamp is not set")
	}
	if config.BlockTime <= 0 {
		return errors.New("block time is not set")
	}
	return nil
}