Commit 3337c361 authored by Inphi's avatar Inphi Committed by GitHub

op-node: ChannelTimeout as a protocol constant (#11452)

* op-node: ChannelTimeout as a protocol constant

* Update op-chain-ops/genesis/config.go
Co-authored-by: default avatarSebastian Stammler <seb@oplabs.co>

* retain pre-granite channel timeout configurability

* check unused channelTimeoutGranite for invalid values

* gofmt

---------
Co-authored-by: default avatarSebastian Stammler <seb@oplabs.co>
parent e4d4cc17
......@@ -17,6 +17,7 @@ import (
"github.com/ethereum-optimism/optimism/op-batcher/metrics"
"github.com/ethereum-optimism/optimism/op-batcher/rpc"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/params"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/cliapp"
"github.com/ethereum-optimism/optimism/op-service/dial"
......@@ -189,7 +190,7 @@ func (bs *BatcherService) initChannelConfig(cfg *CLIConfig) error {
// Use lower channel timeout if granite is scheduled.
// Ensures channels are restricted to the tighter timeout even if granite hasn't activated yet
if bs.RollupConfig.GraniteTime != nil {
channelTimeout = bs.RollupConfig.ChannelTimeoutGranite
channelTimeout = params.ChannelTimeoutGranite
}
cc := ChannelConfig{
SeqWindowSize: bs.RollupConfig.SeqWindowSize,
......
......@@ -18,6 +18,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
altda "github.com/ethereum-optimism/optimism/op-alt-da"
opparams "github.com/ethereum-optimism/optimism/op-node/params"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/eth"
)
......@@ -450,8 +451,6 @@ type L2CoreDeployConfig struct {
SequencerWindowSize uint64 `json:"sequencerWindowSize"`
// ChannelTimeoutBedrock is the number of L1 blocks that a frame stays valid when included in L1.
ChannelTimeoutBedrock uint64 `json:"channelTimeout"`
// ChannelTimeoutGranite is the number of L1 blocks that a frame stays valid when included in L1 after granite.
ChannelTimeoutGranite uint64 `json:"channelTimeoutGranite,omitempty"`
// BatchInboxAddress is the L1 account that batches are sent to.
BatchInboxAddress common.Address `json:"batchInboxAddress"`
......@@ -549,9 +548,6 @@ func (d *L2InitializationConfig) Check(log log.Logger) error {
if err := checkConfigBundle(d, log); err != nil {
return err
}
if d.ChannelTimeoutGranite == 0 && d.L2GenesisGraniteTimeOffset != nil {
return fmt.Errorf("%w: ChannelTimeoutGranite cannot be 0", ErrInvalidDeployConfig)
}
return nil
}
......@@ -761,6 +757,17 @@ type LegacyDeployConfig struct {
// DeploymentWaitConfirmations is the number of confirmations to wait during
// deployment. This is DEPRECATED and should be removed in a future PR.
DeploymentWaitConfirmations int `json:"deploymentWaitConfirmations"`
UnusedChannelTimeoutGranite uint64 `json:"channelTimeoutGranite,omitempty"`
}
var _ ConfigChecker = (*LegacyDeployConfig)(nil)
func (d *LegacyDeployConfig) Check(log log.Logger) error {
if d.UnusedChannelTimeoutGranite != 0 && d.UnusedChannelTimeoutGranite != opparams.ChannelTimeoutGranite {
return fmt.Errorf("%w: channelTimeoutGranite is no longer used. Only valid values are 0 or the protocol constant (%d)", ErrInvalidDeployConfig, opparams.ChannelTimeoutGranite)
}
return nil
}
// DeployConfig represents the deployment configuration for an OP Stack chain.
......@@ -822,9 +829,6 @@ func (d *DeployConfig) Check(log log.Logger) error {
if d.L1BlockTime < d.L2BlockTime {
return fmt.Errorf("L2 block time (%d) is larger than L1 block time (%d)", d.L2BlockTime, d.L1BlockTime)
}
if d.ChannelTimeoutGranite == 0 && d.L2GenesisGraniteTimeOffset != nil {
return fmt.Errorf("%w: ChannelTimeoutGranite cannot be 0", ErrInvalidDeployConfig)
}
return checkConfigBundle(d, log)
}
......@@ -890,7 +894,6 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHas
MaxSequencerDrift: d.MaxSequencerDrift,
SeqWindowSize: d.SequencerWindowSize,
ChannelTimeoutBedrock: d.ChannelTimeoutBedrock,
ChannelTimeoutGranite: d.ChannelTimeoutGranite,
L1ChainID: new(big.Int).SetUint64(d.L1ChainID),
L2ChainID: new(big.Int).SetUint64(d.L2ChainID),
BatchInboxAddress: d.BatchInboxAddress,
......
......@@ -65,7 +65,6 @@ func mockConfig(t *testing.T) Config {
MaxSequencerDrift: 600,
SeqWindowSize: 3600,
ChannelTimeoutBedrock: 300,
ChannelTimeoutGranite: 50,
L1ChainID: big.NewInt(1),
L2ChainID: big.NewInt(2),
RegolithTime: &now,
......
......@@ -60,7 +60,6 @@ func MakeDeployParams(t require.TestingT, tp *TestParams) *DeployParams {
deployConfig.MaxSequencerDrift = tp.MaxSequencerDrift
deployConfig.SequencerWindowSize = tp.SequencerWindowSize
deployConfig.ChannelTimeoutBedrock = tp.ChannelTimeout
deployConfig.ChannelTimeoutGranite = tp.ChannelTimeout
deployConfig.L1BlockTime = tp.L1BlockTime
deployConfig.UseAltDA = tp.UseAltDA
ApplyDeployConfigForks(deployConfig)
......@@ -175,7 +174,6 @@ func Setup(t require.TestingT, deployParams *DeployParams, alloc *AllocParams) *
MaxSequencerDrift: deployConf.MaxSequencerDrift,
SeqWindowSize: deployConf.SequencerWindowSize,
ChannelTimeoutBedrock: deployConf.ChannelTimeoutBedrock,
ChannelTimeoutGranite: deployConf.ChannelTimeoutGranite,
L1ChainID: new(big.Int).SetUint64(deployConf.L1ChainID),
L2ChainID: new(big.Int).SetUint64(deployConf.L2ChainID),
BatchInboxAddress: deployConf.BatchInboxAddress,
......
......@@ -220,7 +220,6 @@ func FjordSystemConfig(t *testing.T, fjordTimeOffset *hexutil.Uint64) SystemConf
func GraniteSystemConfig(t *testing.T, graniteTimeOffset *hexutil.Uint64) SystemConfig {
cfg := FjordSystemConfig(t, &genesisTime)
cfg.DeployConfig.L2GenesisGraniteTimeOffset = graniteTimeOffset
cfg.DeployConfig.ChannelTimeoutGranite = 20
return cfg
}
......@@ -607,7 +606,6 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
MaxSequencerDrift: cfg.DeployConfig.MaxSequencerDrift,
SeqWindowSize: cfg.DeployConfig.SequencerWindowSize,
ChannelTimeoutBedrock: cfg.DeployConfig.ChannelTimeoutBedrock,
ChannelTimeoutGranite: cfg.DeployConfig.ChannelTimeoutGranite,
L1ChainID: cfg.L1ChainIDBig(),
L2ChainID: cfg.L2ChainIDBig(),
BatchInboxAddress: cfg.DeployConfig.BatchInboxAddress,
......
......@@ -56,7 +56,6 @@ var mainnetCfg = rollup.Config{
MaxSequencerDrift: 600,
SeqWindowSize: 3600,
ChannelTimeoutBedrock: 300,
ChannelTimeoutGranite: 50,
L1ChainID: big.NewInt(1),
L2ChainID: big.NewInt(10),
BatchInboxAddress: common.HexToAddress("0xff00000000000000000000000000000000000010"),
......@@ -93,7 +92,6 @@ var sepoliaCfg = rollup.Config{
MaxSequencerDrift: 600,
SeqWindowSize: 3600,
ChannelTimeoutBedrock: 300,
ChannelTimeoutGranite: 50,
L1ChainID: big.NewInt(11155111),
L2ChainID: big.NewInt(11155420),
BatchInboxAddress: common.HexToAddress("0xff00000000000000000000000000000011155420"),
......@@ -130,7 +128,6 @@ var sepoliaDev0Cfg = rollup.Config{
MaxSequencerDrift: 600,
SeqWindowSize: 3600,
ChannelTimeoutBedrock: 300,
ChannelTimeoutGranite: 50,
L1ChainID: big.NewInt(11155111),
L2ChainID: big.NewInt(11155421),
BatchInboxAddress: common.HexToAddress("0xff00000000000000000000000000000011155421"),
......
package params
const (
// Post-Granite constant: Number of L1 blocks between when a channel can be opened and when it must be closed by.
ChannelTimeoutGranite uint64 = 50
)
package rollup
import (
"github.com/ethereum-optimism/optimism/op-node/params"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/log"
)
......@@ -79,7 +80,7 @@ func (s *ChainSpec) MaxChannelBankSize(t uint64) uint64 {
// ChannelTimeout returns the channel timeout constant.
func (s *ChainSpec) ChannelTimeout(t uint64) uint64 {
if s.config.IsGranite(t) {
return s.config.ChannelTimeoutGranite
return params.ChannelTimeoutGranite
}
return s.config.ChannelTimeoutBedrock
}
......
......@@ -37,7 +37,6 @@ var testConfig = Config{
MaxSequencerDrift: 600,
SeqWindowSize: 3600,
ChannelTimeoutBedrock: 300,
ChannelTimeoutGranite: 50,
L1ChainID: big.NewInt(1),
L2ChainID: big.NewInt(10),
RegolithTime: u64ptr(10),
......
......@@ -100,7 +100,7 @@ func TestChannelBankSimple(t *testing.T) {
input.AddFrames("a:1:second")
input.AddFrame(Frame{}, io.EOF)
cfg := &rollup.Config{ChannelTimeoutBedrock: 10, ChannelTimeoutGranite: 10}
cfg := &rollup.Config{ChannelTimeoutBedrock: 10}
cb := NewChannelBank(testlog.Logger(t, log.LevelCrit), cfg, input, nil, metrics.NoopMetrics)
......@@ -144,7 +144,7 @@ func TestChannelBankInterleavedPreCanyon(t *testing.T) {
input.AddFrames("a:1:second")
input.AddFrame(Frame{}, io.EOF)
cfg := &rollup.Config{ChannelTimeoutBedrock: 10, ChannelTimeoutGranite: 10, CanyonTime: nil}
cfg := &rollup.Config{ChannelTimeoutBedrock: 10, CanyonTime: nil}
cb := NewChannelBank(testlog.Logger(t, log.LevelCrit), cfg, input, nil, metrics.NoopMetrics)
......@@ -209,7 +209,7 @@ func TestChannelBankInterleaved(t *testing.T) {
input.AddFrame(Frame{}, io.EOF)
ct := uint64(0)
cfg := &rollup.Config{ChannelTimeoutBedrock: 10, ChannelTimeoutGranite: 10, CanyonTime: &ct}
cfg := &rollup.Config{ChannelTimeoutBedrock: 10, CanyonTime: &ct}
cb := NewChannelBank(testlog.Logger(t, log.LevelCrit), cfg, input, nil, metrics.NoopMetrics)
......@@ -269,7 +269,7 @@ func TestChannelBankDuplicates(t *testing.T) {
input.AddFrames("a:1:second")
input.AddFrame(Frame{}, io.EOF)
cfg := &rollup.Config{ChannelTimeoutBedrock: 10, ChannelTimeoutGranite: 10}
cfg := &rollup.Config{ChannelTimeoutBedrock: 10}
cb := NewChannelBank(testlog.Logger(t, log.LevelCrit), cfg, input, nil, metrics.NoopMetrics)
......
......@@ -75,7 +75,6 @@ func LoadOPStackRollupConfig(chainID uint64) (*Config, error) {
MaxSequencerDrift: chConfig.MaxSequencerDrift,
SeqWindowSize: chConfig.SequencerWindowSize,
ChannelTimeoutBedrock: 300,
ChannelTimeoutGranite: 50,
L1ChainID: new(big.Int).SetUint64(superChain.Config.L1.ChainID),
L2ChainID: new(big.Int).SetUint64(chConfig.ChainID),
RegolithTime: &regolithTime,
......
......@@ -19,7 +19,6 @@ import (
var (
ErrBlockTimeZero = errors.New("block time cannot be 0")
ErrMissingChannelTimeout = errors.New("channel timeout must be set, this should cover at least a L1 block time")
ErrInvalidGraniteChannelTimeout = errors.New("channel timeout granite must be less than channel timeout")
ErrInvalidSeqWindowSize = errors.New("sequencing window size must at least be 2")
ErrInvalidMaxSeqDrift = errors.New("maximum sequencer drift must be greater than 0")
ErrMissingGenesisL1Hash = errors.New("genesis L1 hash cannot be empty")
......@@ -84,7 +83,6 @@ type Config struct {
SeqWindowSize uint64 `json:"seq_window_size"`
// Number of L1 blocks between when a channel can be opened and when it must be closed by.
ChannelTimeoutBedrock uint64 `json:"channel_timeout"`
ChannelTimeoutGranite uint64 `json:"channel_timeout_granite"`
// Required to verify L1 signatures
L1ChainID *big.Int `json:"l1_chain_id"`
// Required to identify the L2 network and create p2p signatures unique for this chain.
......@@ -258,14 +256,6 @@ func (cfg *Config) Check() error {
if cfg.ChannelTimeoutBedrock == 0 {
return ErrMissingChannelTimeout
}
if cfg.GraniteTime != nil {
if cfg.ChannelTimeoutGranite == 0 {
return ErrMissingChannelTimeout
}
if cfg.ChannelTimeoutGranite > cfg.ChannelTimeoutBedrock {
return ErrInvalidGraniteChannelTimeout
}
}
if cfg.SeqWindowSize < 2 {
return ErrInvalidSeqWindowSize
}
......
......@@ -43,7 +43,6 @@ func randConfig() *Config {
MaxSequencerDrift: 100,
SeqWindowSize: 2,
ChannelTimeoutBedrock: 123,
ChannelTimeoutGranite: 45,
L1ChainID: big.NewInt(900),
L2ChainID: big.NewInt(901),
BatchInboxAddress: randAddr(),
......@@ -380,25 +379,6 @@ func TestConfig_Check(t *testing.T) {
modifier: func(cfg *Config) { cfg.ChannelTimeoutBedrock = 0 },
expectedErr: ErrMissingChannelTimeout,
},
{
name: "ChannelTimeoutGraniteZeroNotEnabled",
modifier: func(cfg *Config) { cfg.ChannelTimeoutGranite = 0 },
expectedErr: nil,
},
{
name: "ChannelTimeoutGraniteZeroEnabled",
modifier: func(cfg *Config) {
genesis := uint64(0)
cfg.ChannelTimeoutGranite = 0
cfg.RegolithTime = &genesis
cfg.CanyonTime = &genesis
cfg.DeltaTime = &genesis
cfg.EcotoneTime = &genesis
cfg.FjordTime = &genesis
cfg.GraniteTime = &genesis
},
expectedErr: ErrMissingChannelTimeout,
},
{
name: "SeqWindowSizeZero",
modifier: func(cfg *Config) { cfg.SeqWindowSize = 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