Skip to content

Commit

Permalink
op-chain-ops: Organize deploy-config, improve check-logging (ethereum…
Browse files Browse the repository at this point in the history
…-optimism#11189)

* op-chain-ops: Organize deploy-config, improve check-logging

* op-chain-ops: fix DAChallengeProxy check

* op-chain-ops: add godocs
  • Loading branch information
protolambda authored Jul 30, 2024
1 parent 8198bfc commit 63b952a
Show file tree
Hide file tree
Showing 9 changed files with 701 additions and 442 deletions.
5 changes: 4 additions & 1 deletion op-chain-ops/cmd/check-deploy-config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ func entrypoint(ctx *cli.Context) error {
return err
}

cfg := oplog.DefaultCLIConfig()
logger := oplog.NewLogger(ctx.App.Writer, cfg)

// Check the config, no need to call `CheckAddresses()`
if err := config.Check(); err != nil {
if err := config.Check(logger); err != nil {
return err
}

Expand Down
1,042 changes: 631 additions & 411 deletions op-chain-ops/genesis/config.go

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions op-chain-ops/genesis/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import (

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

"github.com/stretchr/testify/require"

"github.com/ethereum-optimism/optimism/op-service/testlog"
)

func TestConfigDataMarshalUnmarshal(t *testing.T) {
Expand All @@ -23,6 +26,8 @@ func TestConfigDataMarshalUnmarshal(t *testing.T) {
require.NoError(t, dec.Decode(decoded))
require.EqualValues(t, "non-default value", string(decoded.L2GenesisBlockExtraData))

require.NoError(t, decoded.Check(testlog.Logger(t, log.LevelDebug)))

encoded, err := json.MarshalIndent(decoded, "", " ")
require.NoError(t, err)
require.JSONEq(t, string(b), string(encoded))
Expand All @@ -39,25 +44,37 @@ func TestUnmarshalL1StartingBlockTag(t *testing.T) {

func TestRegolithTimeZero(t *testing.T) {
regolithOffset := hexutil.Uint64(0)
config := &DeployConfig{L2GenesisRegolithTimeOffset: &regolithOffset}
config := &DeployConfig{
L2InitializationConfig: L2InitializationConfig{
UpgradeScheduleDeployConfig: UpgradeScheduleDeployConfig{
L2GenesisRegolithTimeOffset: &regolithOffset}}}
require.Equal(t, uint64(0), *config.RegolithTime(1234))
}

func TestRegolithTimeAsOffset(t *testing.T) {
regolithOffset := hexutil.Uint64(1500)
config := &DeployConfig{L2GenesisRegolithTimeOffset: &regolithOffset}
config := &DeployConfig{
L2InitializationConfig: L2InitializationConfig{
UpgradeScheduleDeployConfig: UpgradeScheduleDeployConfig{
L2GenesisRegolithTimeOffset: &regolithOffset}}}
require.Equal(t, uint64(1500+5000), *config.RegolithTime(5000))
}

func TestCanyonTimeZero(t *testing.T) {
canyonOffset := hexutil.Uint64(0)
config := &DeployConfig{L2GenesisCanyonTimeOffset: &canyonOffset}
config := &DeployConfig{
L2InitializationConfig: L2InitializationConfig{
UpgradeScheduleDeployConfig: UpgradeScheduleDeployConfig{
L2GenesisCanyonTimeOffset: &canyonOffset}}}
require.Equal(t, uint64(0), *config.CanyonTime(1234))
}

func TestCanyonTimeOffset(t *testing.T) {
canyonOffset := hexutil.Uint64(1500)
config := &DeployConfig{L2GenesisCanyonTimeOffset: &canyonOffset}
config := &DeployConfig{
L2InitializationConfig: L2InitializationConfig{
UpgradeScheduleDeployConfig: UpgradeScheduleDeployConfig{
L2GenesisCanyonTimeOffset: &canyonOffset}}}
require.Equal(t, uint64(1234+1500), *config.CanyonTime(1234))
}

Expand Down
5 changes: 3 additions & 2 deletions op-e2e/actions/ecotone_fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
genesisBlock := hexutil.Uint64(0)
ecotoneOffset := hexutil.Uint64(4)

log := testlog.Logger(t, log.LevelDebug)

dp.DeployConfig.L1CancunTimeOffset = &genesisBlock // can be removed once Cancun on L1 is the default

// Activate all forks at genesis, and schedule Ecotone the block after
dp.DeployConfig.L2GenesisRegolithTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisCanyonTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &ecotoneOffset
require.NoError(t, dp.DeployConfig.Check(), "must have valid config")
require.NoError(t, dp.DeployConfig.Check(log), "must have valid config")

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
_, _, miner, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log)
ethCl := engine.EthClient()

Expand Down
5 changes: 3 additions & 2 deletions op-e2e/actions/fjord_fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) {
genesisBlock := hexutil.Uint64(0)
fjordOffset := hexutil.Uint64(2)

log := testlog.Logger(t, log.LvlDebug)

dp.DeployConfig.L1CancunTimeOffset = &genesisBlock // can be removed once Cancun on L1 is the default

// Activate all forks at genesis, and schedule Fjord the block after
Expand All @@ -42,10 +44,9 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) {
dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisFjordTimeOffset = &fjordOffset
require.NoError(t, dp.DeployConfig.Check(), "must have valid config")
require.NoError(t, dp.DeployConfig.Check(log), "must have valid config")

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LvlDebug)
_, _, _, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log)
ethCl := engine.EthClient()

Expand Down
7 changes: 5 additions & 2 deletions op-e2e/e2eutils/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -63,7 +64,8 @@ func MakeDeployParams(t require.TestingT, tp *TestParams) *DeployParams {
deployConfig.UsePlasma = tp.UsePlasma
ApplyDeployConfigForks(deployConfig)

require.NoError(t, deployConfig.Check())
logger := log.NewLogger(log.DiscardHandler())
require.NoError(t, deployConfig.Check(logger))
require.Equal(t, addresses.Batcher, deployConfig.BatchSenderAddress)
require.Equal(t, addresses.Proposer, deployConfig.L2OutputOracleProposer)
require.Equal(t, addresses.SequencerP2P, deployConfig.P2PSequencerAddress)
Expand Down Expand Up @@ -105,7 +107,8 @@ func Ether(v uint64) *big.Int {
func Setup(t require.TestingT, deployParams *DeployParams, alloc *AllocParams) *SetupData {
deployConf := deployParams.DeployConfig.Copy()
deployConf.L1GenesisBlockTimestamp = hexutil.Uint64(time.Now().Unix())
require.NoError(t, deployConf.Check())
logger := log.NewLogger(log.DiscardHandler())
require.NoError(t, deployConf.Check(logger))

l1Deployments := config.L1Deployments.Copy()
require.NoError(t, l1Deployments.Check(deployConf))
Expand Down
5 changes: 3 additions & 2 deletions op-e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func DefaultSystemConfig(t testing.TB) SystemConfig {
deployConfig := config.DeployConfig.Copy()
deployConfig.L1GenesisBlockTimestamp = hexutil.Uint64(time.Now().Unix())
e2eutils.ApplyDeployConfigForks(deployConfig)
require.NoError(t, deployConfig.Check(), "Deploy config is invalid, do you need to run make devnet-allocs?")
require.NoError(t, deployConfig.Check(testlog.Logger(t, log.LevelInfo)),
"Deploy config is invalid, do you need to run make devnet-allocs?")
l1Deployments := config.L1Deployments.Copy()
require.NoError(t, l1Deployments.Check(deployConfig))

Expand Down Expand Up @@ -507,7 +508,7 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
c = sys.TimeTravelClock
}

if err := cfg.DeployConfig.Check(); err != nil {
if err := cfg.DeployConfig.Check(testlog.Logger(t, log.LevelInfo)); err != nil {
return nil, err
}

Expand Down
25 changes: 15 additions & 10 deletions op-node/cmd/genesis/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/urfave/cli/v2"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
)

var (
Expand Down Expand Up @@ -97,7 +96,9 @@ var Subcommands = cli.Commands{
config.SetDeployments(deployments)
}

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

Expand Down Expand Up @@ -132,8 +133,11 @@ var Subcommands = cli.Commands{
"or it can be provided as a JSON file.",
Flags: l2Flags,
Action: func(ctx *cli.Context) error {
cfg := oplog.DefaultCLIConfig()
logger := oplog.NewLogger(ctx.App.Writer, cfg)

deployConfig := ctx.Path(deployConfigFlag.Name)
log.Info("Deploy config", "path", deployConfig)
logger.Info("Deploy config", "path", deployConfig)
config, err := genesis.NewDeployConfig(deployConfig)
if err != nil {
return err
Expand Down Expand Up @@ -171,16 +175,17 @@ var Subcommands = cli.Commands{
return fmt.Errorf("failed to fetch startBlock from SystemConfig: %w", err)
}

log.Info("Using L1 Start Block", "number", startBlock)
logger.Info("Using L1 Start Block", "number", startBlock)
// retry because local devnet can experience a race condition where L1 geth isn't ready yet
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)
}
log.Info("Fetched L1 Start Block", "hash", l1StartBlock.Hash().Hex())
logger.Info("Fetched L1 Start Block", "hash", l1StartBlock.Hash().Hex())

// Sanity check the config
if err := config.Check(); err != nil {
// Sanity check the config. Do this after filling in the L1StartingBlockTag
// if it is not defined.
if err := config.Check(logger); err != nil {
return err
}

Expand Down
24 changes: 16 additions & 8 deletions op-program/client/l2/engine_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,22 @@ func setupOracleBackedChainWithLowerHead(t *testing.T, blockCount int, headBlock

func setupOracle(t *testing.T, blockCount int, headBlockNumber int, enableEcotone bool) (*params.ChainConfig, []*types.Block, *l2test.StubBlockOracle) {
deployConfig := &genesis.DeployConfig{
L1ChainID: 900,
L2ChainID: 901,
L2BlockTime: 2,
FundDevAccounts: true,
L2GenesisBlockGasLimit: 30_000_000,
// Arbitrary non-zero difficulty in genesis.
// This is slightly weird for a chain starting post-merge but it happens so need to make sure it works
L2GenesisBlockDifficulty: (*hexutil.Big)(big.NewInt(100)),
L2InitializationConfig: genesis.L2InitializationConfig{
DevDeployConfig: genesis.DevDeployConfig{
FundDevAccounts: true,
},
L2GenesisBlockDeployConfig: genesis.L2GenesisBlockDeployConfig{
L2GenesisBlockGasLimit: 30_000_000,
// Arbitrary non-zero difficulty in genesis.
// This is slightly weird for a chain starting post-merge but it happens so need to make sure it works
L2GenesisBlockDifficulty: (*hexutil.Big)(big.NewInt(100)),
},
L2CoreDeployConfig: genesis.L2CoreDeployConfig{
L1ChainID: 900,
L2ChainID: 901,
L2BlockTime: 2,
},
},
}
if enableEcotone {
ts := hexutil.Uint64(0)
Expand Down

0 comments on commit 63b952a

Please sign in to comment.