Commit 63b952a0 authored by protolambda's avatar protolambda Committed by GitHub

op-chain-ops: Organize deploy-config, improve check-logging (#11189)

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

* op-chain-ops: fix DAChallengeProxy check

* op-chain-ops: add godocs
parent 8198bfca
...@@ -46,8 +46,11 @@ func entrypoint(ctx *cli.Context) error { ...@@ -46,8 +46,11 @@ func entrypoint(ctx *cli.Context) error {
return err return err
} }
cfg := oplog.DefaultCLIConfig()
logger := oplog.NewLogger(ctx.App.Writer, cfg)
// Check the config, no need to call `CheckAddresses()` // Check the config, no need to call `CheckAddresses()`
if err := config.Check(); err != nil { if err := config.Check(logger); err != nil {
return err return err
} }
......
This diff is collapsed.
...@@ -9,9 +9,12 @@ import ( ...@@ -9,9 +9,12 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-service/testlog"
) )
func TestConfigDataMarshalUnmarshal(t *testing.T) { func TestConfigDataMarshalUnmarshal(t *testing.T) {
...@@ -23,6 +26,8 @@ func TestConfigDataMarshalUnmarshal(t *testing.T) { ...@@ -23,6 +26,8 @@ func TestConfigDataMarshalUnmarshal(t *testing.T) {
require.NoError(t, dec.Decode(decoded)) require.NoError(t, dec.Decode(decoded))
require.EqualValues(t, "non-default value", string(decoded.L2GenesisBlockExtraData)) require.EqualValues(t, "non-default value", string(decoded.L2GenesisBlockExtraData))
require.NoError(t, decoded.Check(testlog.Logger(t, log.LevelDebug)))
encoded, err := json.MarshalIndent(decoded, "", " ") encoded, err := json.MarshalIndent(decoded, "", " ")
require.NoError(t, err) require.NoError(t, err)
require.JSONEq(t, string(b), string(encoded)) require.JSONEq(t, string(b), string(encoded))
...@@ -39,25 +44,37 @@ func TestUnmarshalL1StartingBlockTag(t *testing.T) { ...@@ -39,25 +44,37 @@ func TestUnmarshalL1StartingBlockTag(t *testing.T) {
func TestRegolithTimeZero(t *testing.T) { func TestRegolithTimeZero(t *testing.T) {
regolithOffset := hexutil.Uint64(0) regolithOffset := hexutil.Uint64(0)
config := &DeployConfig{L2GenesisRegolithTimeOffset: &regolithOffset} config := &DeployConfig{
L2InitializationConfig: L2InitializationConfig{
UpgradeScheduleDeployConfig: UpgradeScheduleDeployConfig{
L2GenesisRegolithTimeOffset: &regolithOffset}}}
require.Equal(t, uint64(0), *config.RegolithTime(1234)) require.Equal(t, uint64(0), *config.RegolithTime(1234))
} }
func TestRegolithTimeAsOffset(t *testing.T) { func TestRegolithTimeAsOffset(t *testing.T) {
regolithOffset := hexutil.Uint64(1500) 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)) require.Equal(t, uint64(1500+5000), *config.RegolithTime(5000))
} }
func TestCanyonTimeZero(t *testing.T) { func TestCanyonTimeZero(t *testing.T) {
canyonOffset := hexutil.Uint64(0) canyonOffset := hexutil.Uint64(0)
config := &DeployConfig{L2GenesisCanyonTimeOffset: &canyonOffset} config := &DeployConfig{
L2InitializationConfig: L2InitializationConfig{
UpgradeScheduleDeployConfig: UpgradeScheduleDeployConfig{
L2GenesisCanyonTimeOffset: &canyonOffset}}}
require.Equal(t, uint64(0), *config.CanyonTime(1234)) require.Equal(t, uint64(0), *config.CanyonTime(1234))
} }
func TestCanyonTimeOffset(t *testing.T) { func TestCanyonTimeOffset(t *testing.T) {
canyonOffset := hexutil.Uint64(1500) 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)) require.Equal(t, uint64(1234+1500), *config.CanyonTime(1234))
} }
......
...@@ -45,6 +45,8 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) { ...@@ -45,6 +45,8 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
genesisBlock := hexutil.Uint64(0) genesisBlock := hexutil.Uint64(0)
ecotoneOffset := hexutil.Uint64(4) ecotoneOffset := hexutil.Uint64(4)
log := testlog.Logger(t, log.LevelDebug)
dp.DeployConfig.L1CancunTimeOffset = &genesisBlock // can be removed once Cancun on L1 is the default 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 // Activate all forks at genesis, and schedule Ecotone the block after
...@@ -52,10 +54,9 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) { ...@@ -52,10 +54,9 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
dp.DeployConfig.L2GenesisCanyonTimeOffset = &genesisBlock dp.DeployConfig.L2GenesisCanyonTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &ecotoneOffset 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) sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
_, _, miner, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log) _, _, miner, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log)
ethCl := engine.EthClient() ethCl := engine.EthClient()
......
...@@ -34,6 +34,8 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) { ...@@ -34,6 +34,8 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) {
genesisBlock := hexutil.Uint64(0) genesisBlock := hexutil.Uint64(0)
fjordOffset := hexutil.Uint64(2) fjordOffset := hexutil.Uint64(2)
log := testlog.Logger(t, log.LvlDebug)
dp.DeployConfig.L1CancunTimeOffset = &genesisBlock // can be removed once Cancun on L1 is the default 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 // Activate all forks at genesis, and schedule Fjord the block after
...@@ -42,10 +44,9 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) { ...@@ -42,10 +44,9 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) {
dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &genesisBlock dp.DeployConfig.L2GenesisEcotoneTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisFjordTimeOffset = &fjordOffset 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) sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LvlDebug)
_, _, _, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log) _, _, _, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log)
ethCl := engine.EthClient() ethCl := engine.EthClient()
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -63,7 +64,8 @@ func MakeDeployParams(t require.TestingT, tp *TestParams) *DeployParams { ...@@ -63,7 +64,8 @@ func MakeDeployParams(t require.TestingT, tp *TestParams) *DeployParams {
deployConfig.UsePlasma = tp.UsePlasma deployConfig.UsePlasma = tp.UsePlasma
ApplyDeployConfigForks(deployConfig) 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.Batcher, deployConfig.BatchSenderAddress)
require.Equal(t, addresses.Proposer, deployConfig.L2OutputOracleProposer) require.Equal(t, addresses.Proposer, deployConfig.L2OutputOracleProposer)
require.Equal(t, addresses.SequencerP2P, deployConfig.P2PSequencerAddress) require.Equal(t, addresses.SequencerP2P, deployConfig.P2PSequencerAddress)
...@@ -105,7 +107,8 @@ func Ether(v uint64) *big.Int { ...@@ -105,7 +107,8 @@ func Ether(v uint64) *big.Int {
func Setup(t require.TestingT, deployParams *DeployParams, alloc *AllocParams) *SetupData { func Setup(t require.TestingT, deployParams *DeployParams, alloc *AllocParams) *SetupData {
deployConf := deployParams.DeployConfig.Copy() deployConf := deployParams.DeployConfig.Copy()
deployConf.L1GenesisBlockTimestamp = hexutil.Uint64(time.Now().Unix()) 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() l1Deployments := config.L1Deployments.Copy()
require.NoError(t, l1Deployments.Check(deployConf)) require.NoError(t, l1Deployments.Check(deployConf))
......
...@@ -101,7 +101,8 @@ func DefaultSystemConfig(t testing.TB) SystemConfig { ...@@ -101,7 +101,8 @@ func DefaultSystemConfig(t testing.TB) SystemConfig {
deployConfig := config.DeployConfig.Copy() deployConfig := config.DeployConfig.Copy()
deployConfig.L1GenesisBlockTimestamp = hexutil.Uint64(time.Now().Unix()) deployConfig.L1GenesisBlockTimestamp = hexutil.Uint64(time.Now().Unix())
e2eutils.ApplyDeployConfigForks(deployConfig) 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() l1Deployments := config.L1Deployments.Copy()
require.NoError(t, l1Deployments.Check(deployConfig)) require.NoError(t, l1Deployments.Check(deployConfig))
...@@ -507,7 +508,7 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste ...@@ -507,7 +508,7 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
c = sys.TimeTravelClock 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 return nil, err
} }
......
...@@ -9,13 +9,12 @@ import ( ...@@ -9,13 +9,12 @@ import (
"github.com/ethereum-optimism/optimism/op-service/sources/batching" "github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/urfave/cli/v2" "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/foundry"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis" "github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-service/jsonutil" "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 ( var (
...@@ -97,7 +96,9 @@ var Subcommands = cli.Commands{ ...@@ -97,7 +96,9 @@ var Subcommands = cli.Commands{
config.SetDeployments(deployments) 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) return fmt.Errorf("deploy config at %s invalid: %w", deployConfig, err)
} }
...@@ -132,8 +133,11 @@ var Subcommands = cli.Commands{ ...@@ -132,8 +133,11 @@ var Subcommands = cli.Commands{
"or it can be provided as a JSON file.", "or it can be provided as a JSON file.",
Flags: l2Flags, Flags: l2Flags,
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
cfg := oplog.DefaultCLIConfig()
logger := oplog.NewLogger(ctx.App.Writer, cfg)
deployConfig := ctx.Path(deployConfigFlag.Name) deployConfig := ctx.Path(deployConfigFlag.Name)
log.Info("Deploy config", "path", deployConfig) logger.Info("Deploy config", "path", deployConfig)
config, err := genesis.NewDeployConfig(deployConfig) config, err := genesis.NewDeployConfig(deployConfig)
if err != nil { if err != nil {
return err return err
...@@ -171,16 +175,17 @@ var Subcommands = cli.Commands{ ...@@ -171,16 +175,17 @@ var Subcommands = cli.Commands{
return fmt.Errorf("failed to fetch startBlock from SystemConfig: %w", err) 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 // 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) }) 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 { if err != nil {
return fmt.Errorf("fetching start block by number: %w", err) 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 // Sanity check the config. Do this after filling in the L1StartingBlockTag
if err := config.Check(); err != nil { // if it is not defined.
if err := config.Check(logger); err != nil {
return err return err
} }
......
...@@ -273,14 +273,22 @@ func setupOracleBackedChainWithLowerHead(t *testing.T, blockCount int, headBlock ...@@ -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) { func setupOracle(t *testing.T, blockCount int, headBlockNumber int, enableEcotone bool) (*params.ChainConfig, []*types.Block, *l2test.StubBlockOracle) {
deployConfig := &genesis.DeployConfig{ deployConfig := &genesis.DeployConfig{
L1ChainID: 900, L2InitializationConfig: genesis.L2InitializationConfig{
L2ChainID: 901, DevDeployConfig: genesis.DevDeployConfig{
L2BlockTime: 2, FundDevAccounts: true,
FundDevAccounts: true, },
L2GenesisBlockGasLimit: 30_000_000, L2GenesisBlockDeployConfig: genesis.L2GenesisBlockDeployConfig{
// Arbitrary non-zero difficulty in genesis. L2GenesisBlockGasLimit: 30_000_000,
// This is slightly weird for a chain starting post-merge but it happens so need to make sure it works // Arbitrary non-zero difficulty in genesis.
L2GenesisBlockDifficulty: (*hexutil.Big)(big.NewInt(100)), // 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 { if enableEcotone {
ts := hexutil.Uint64(0) ts := hexutil.Uint64(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment