Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
5efcefe5
Unverified
Commit
5efcefe5
authored
Feb 15, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use variables for errors.
Improve error wording
parent
7c8538b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
41 deletions
+62
-41
types.go
op-node/rollup/types.go
+39
-18
types_test.go
op-node/rollup/types_test.go
+23
-23
No files found.
op-node/rollup/types.go
View file @
5efcefe5
...
@@ -12,6 +12,27 @@ import (
...
@@ -12,6 +12,27 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
)
)
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"
)
ErrInvalidSeqWindowSize
=
errors
.
New
(
"sequencing window size must at least be 2"
)
ErrMissingGenesisL1Hash
=
errors
.
New
(
"genesis L1 hash cannot be empty"
)
ErrMissingGenesisL2Hash
=
errors
.
New
(
"genesis L2 hash cannot be empty"
)
ErrGenesisHashesSame
=
errors
.
New
(
"achievement get! rollup inception: L1 and L2 genesis cannot be the same"
)
ErrMissingGenesisL2Time
=
errors
.
New
(
"missing L2 genesis time"
)
ErrMissingBatcherAddr
=
errors
.
New
(
"missing genesis system config batcher address"
)
ErrMissingOverhead
=
errors
.
New
(
"missing genesis system config overhead"
)
ErrMissingScalar
=
errors
.
New
(
"missing genesis system config scalar"
)
ErrMissingGasLimit
=
errors
.
New
(
"missing genesis system config gas limit"
)
ErrMissingBatchInboxAddress
=
errors
.
New
(
"missing batch inbox address"
)
ErrMissingDepositContractAddress
=
errors
.
New
(
"missing deposit contract address"
)
ErrMissingL1ChainID
=
errors
.
New
(
"L1 chain ID must not be nil"
)
ErrMissingL2ChainID
=
errors
.
New
(
"L2 chain ID must not be nil"
)
ErrChainIDsSame
=
errors
.
New
(
"L1 and L2 chain IDs must be different"
)
ErrL1ChainIDNotPositive
=
errors
.
New
(
"L1 chain ID must be non-zero and positive"
)
ErrL2ChainIDNotPositive
=
errors
.
New
(
"L2 chain ID must be non-zero and positive"
)
)
type
Genesis
struct
{
type
Genesis
struct
{
// The L1 block that the rollup starts *after* (no derived transactions)
// The L1 block that the rollup starts *after* (no derived transactions)
L1
eth
.
BlockID
`json:"l1"`
L1
eth
.
BlockID
`json:"l1"`
...
@@ -147,58 +168,58 @@ func (cfg *Config) CheckL2GenesisBlockHash(ctx context.Context, client L2Client)
...
@@ -147,58 +168,58 @@ func (cfg *Config) CheckL2GenesisBlockHash(ctx context.Context, client L2Client)
// Check verifies that the given configuration makes sense
// Check verifies that the given configuration makes sense
func
(
cfg
*
Config
)
Check
()
error
{
func
(
cfg
*
Config
)
Check
()
error
{
if
cfg
.
BlockTime
==
0
{
if
cfg
.
BlockTime
==
0
{
return
fmt
.
Errorf
(
"block time cannot be 0, got %d"
,
cfg
.
BlockTime
)
return
ErrBlockTimeZero
}
}
if
cfg
.
ChannelTimeout
==
0
{
if
cfg
.
ChannelTimeout
==
0
{
return
fmt
.
Errorf
(
"channel timeout must be set, this should cover at least a L1 block time"
)
return
ErrMissingChannelTimeout
}
}
if
cfg
.
SeqWindowSize
<
2
{
if
cfg
.
SeqWindowSize
<
2
{
return
fmt
.
Errorf
(
"sequencing window size must at least be 2, got %d"
,
cfg
.
SeqWindowSize
)
return
ErrInvalidSeqWindowSize
}
}
if
cfg
.
Genesis
.
L1
.
Hash
==
(
common
.
Hash
{})
{
if
cfg
.
Genesis
.
L1
.
Hash
==
(
common
.
Hash
{})
{
return
errors
.
New
(
"genesis l1 hash cannot be empty"
)
return
ErrMissingGenesisL1Hash
}
}
if
cfg
.
Genesis
.
L2
.
Hash
==
(
common
.
Hash
{})
{
if
cfg
.
Genesis
.
L2
.
Hash
==
(
common
.
Hash
{})
{
return
errors
.
New
(
"genesis l2 hash cannot be empty"
)
return
ErrMissingGenesisL2Hash
}
}
if
cfg
.
Genesis
.
L2
.
Hash
==
cfg
.
Genesis
.
L1
.
Hash
{
if
cfg
.
Genesis
.
L2
.
Hash
==
cfg
.
Genesis
.
L1
.
Hash
{
return
errors
.
New
(
"achievement get! rollup inception: L1 and L2 genesis cannot be the same"
)
return
ErrGenesisHashesSame
}
}
if
cfg
.
Genesis
.
L2Time
==
0
{
if
cfg
.
Genesis
.
L2Time
==
0
{
return
errors
.
New
(
"missing L2 genesis time"
)
return
ErrMissingGenesisL2Time
}
}
if
cfg
.
Genesis
.
SystemConfig
.
BatcherAddr
==
(
common
.
Address
{})
{
if
cfg
.
Genesis
.
SystemConfig
.
BatcherAddr
==
(
common
.
Address
{})
{
return
errors
.
New
(
"missing genesis system config batcher address"
)
return
ErrMissingBatcherAddr
}
}
if
cfg
.
Genesis
.
SystemConfig
.
Overhead
==
(
eth
.
Bytes32
{})
{
if
cfg
.
Genesis
.
SystemConfig
.
Overhead
==
(
eth
.
Bytes32
{})
{
return
errors
.
New
(
"missing genesis system config overhead"
)
return
ErrMissingOverhead
}
}
if
cfg
.
Genesis
.
SystemConfig
.
Scalar
==
(
eth
.
Bytes32
{})
{
if
cfg
.
Genesis
.
SystemConfig
.
Scalar
==
(
eth
.
Bytes32
{})
{
return
errors
.
New
(
"missing genesis system config scalar"
)
return
ErrMissingScalar
}
}
if
cfg
.
Genesis
.
SystemConfig
.
GasLimit
==
0
{
if
cfg
.
Genesis
.
SystemConfig
.
GasLimit
==
0
{
return
errors
.
New
(
"missing genesis system config gas limit"
)
return
ErrMissingGasLimit
}
}
if
cfg
.
BatchInboxAddress
==
(
common
.
Address
{})
{
if
cfg
.
BatchInboxAddress
==
(
common
.
Address
{})
{
return
errors
.
New
(
"missing batch inbox address"
)
return
ErrMissingBatchInboxAddress
}
}
if
cfg
.
DepositContractAddress
==
(
common
.
Address
{})
{
if
cfg
.
DepositContractAddress
==
(
common
.
Address
{})
{
return
errors
.
New
(
"missing deposit contract address"
)
return
ErrMissingDepositContractAddress
}
}
if
cfg
.
L1ChainID
==
nil
{
if
cfg
.
L1ChainID
==
nil
{
return
errors
.
New
(
"l1 chain ID must not be nil"
)
return
ErrMissingL1ChainID
}
}
if
cfg
.
L2ChainID
==
nil
{
if
cfg
.
L2ChainID
==
nil
{
return
errors
.
New
(
"l2 chain ID must not be nil"
)
return
ErrMissingL2ChainID
}
}
if
cfg
.
L1ChainID
.
Cmp
(
cfg
.
L2ChainID
)
==
0
{
if
cfg
.
L1ChainID
.
Cmp
(
cfg
.
L2ChainID
)
==
0
{
return
errors
.
New
(
"l1 and l2 chain IDs must be different"
)
return
ErrChainIDsSame
}
}
if
cfg
.
L1ChainID
.
Sign
()
<
1
{
if
cfg
.
L1ChainID
.
Sign
()
<
1
{
return
errors
.
New
(
"l1 chain ID must be positive"
)
return
ErrL1ChainIDNotPositive
}
}
if
cfg
.
L2ChainID
.
Sign
()
<
1
{
if
cfg
.
L2ChainID
.
Sign
()
<
1
{
return
errors
.
New
(
"l2 chain ID must be positive"
)
return
ErrL2ChainIDNotPositive
}
}
return
nil
return
nil
}
}
...
...
op-node/rollup/types_test.go
View file @
5efcefe5
...
@@ -217,112 +217,112 @@ func TestConfig_Check(t *testing.T) {
...
@@ -217,112 +217,112 @@ func TestConfig_Check(t *testing.T) {
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
modifier
func
(
cfg
*
Config
)
modifier
func
(
cfg
*
Config
)
expectedErr
string
expectedErr
error
}{
}{
{
{
name
:
"BlockTimeZero"
,
name
:
"BlockTimeZero"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
BlockTime
=
0
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
BlockTime
=
0
},
expectedErr
:
"block time cannot be 0"
,
expectedErr
:
ErrBlockTimeZero
,
},
},
{
{
name
:
"ChannelTimeoutZero"
,
name
:
"ChannelTimeoutZero"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
ChannelTimeout
=
0
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
ChannelTimeout
=
0
},
expectedErr
:
"channel timeout must be set"
,
expectedErr
:
ErrMissingChannelTimeout
,
},
},
{
{
name
:
"SeqWindowSizeZero"
,
name
:
"SeqWindowSizeZero"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
SeqWindowSize
=
0
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
SeqWindowSize
=
0
},
expectedErr
:
"sequencing window size must at least be 2"
,
expectedErr
:
ErrInvalidSeqWindowSize
,
},
},
{
{
name
:
"SeqWindowSizeOne"
,
name
:
"SeqWindowSizeOne"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
SeqWindowSize
=
1
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
SeqWindowSize
=
1
},
expectedErr
:
"sequencing window size must at least be 2"
,
expectedErr
:
ErrInvalidSeqWindowSize
,
},
},
{
{
name
:
"NoL1Genesis"
,
name
:
"NoL1Genesis"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
L1
.
Hash
=
common
.
Hash
{}
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
L1
.
Hash
=
common
.
Hash
{}
},
expectedErr
:
"genesis l1 hash cannot be empty"
,
expectedErr
:
ErrMissingGenesisL1Hash
,
},
},
{
{
name
:
"NoL2Genesis"
,
name
:
"NoL2Genesis"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
L2
.
Hash
=
common
.
Hash
{}
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
L2
.
Hash
=
common
.
Hash
{}
},
expectedErr
:
"genesis l2 hash cannot be empty"
,
expectedErr
:
ErrMissingGenesisL2Hash
,
},
},
{
{
name
:
"GenesisHashesEqual"
,
name
:
"GenesisHashesEqual"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
L2
.
Hash
=
cfg
.
Genesis
.
L1
.
Hash
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
L2
.
Hash
=
cfg
.
Genesis
.
L1
.
Hash
},
expectedErr
:
"L1 and L2 genesis cannot be the same"
,
expectedErr
:
ErrGenesisHashesSame
,
},
},
{
{
name
:
"GenesisL2TimeZero"
,
name
:
"GenesisL2TimeZero"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
L2Time
=
0
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
L2Time
=
0
},
expectedErr
:
"missing L2 genesis time"
,
expectedErr
:
ErrMissingGenesisL2Time
,
},
},
{
{
name
:
"NoBatcherAddr"
,
name
:
"NoBatcherAddr"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
SystemConfig
.
BatcherAddr
=
common
.
Address
{}
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
SystemConfig
.
BatcherAddr
=
common
.
Address
{}
},
expectedErr
:
"missing genesis system config batcher address"
,
expectedErr
:
ErrMissingBatcherAddr
,
},
},
{
{
name
:
"NoOverhead"
,
name
:
"NoOverhead"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
SystemConfig
.
Overhead
=
eth
.
Bytes32
{}
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
SystemConfig
.
Overhead
=
eth
.
Bytes32
{}
},
expectedErr
:
"missing genesis system config overhead"
,
expectedErr
:
ErrMissingOverhead
,
},
},
{
{
name
:
"NoScalar"
,
name
:
"NoScalar"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
SystemConfig
.
Scalar
=
eth
.
Bytes32
{}
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
SystemConfig
.
Scalar
=
eth
.
Bytes32
{}
},
expectedErr
:
"missing genesis system config scalar"
,
expectedErr
:
ErrMissingScalar
,
},
},
{
{
name
:
"NoGasLimit"
,
name
:
"NoGasLimit"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
SystemConfig
.
GasLimit
=
0
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
Genesis
.
SystemConfig
.
GasLimit
=
0
},
expectedErr
:
"missing genesis system config gas limit"
,
expectedErr
:
ErrMissingGasLimit
,
},
},
{
{
name
:
"NoBatchInboxAddress"
,
name
:
"NoBatchInboxAddress"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
BatchInboxAddress
=
common
.
Address
{}
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
BatchInboxAddress
=
common
.
Address
{}
},
expectedErr
:
"missing batch inbox address"
,
expectedErr
:
ErrMissingBatchInboxAddress
,
},
},
{
{
name
:
"NoDepositContractAddress"
,
name
:
"NoDepositContractAddress"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
DepositContractAddress
=
common
.
Address
{}
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
DepositContractAddress
=
common
.
Address
{}
},
expectedErr
:
"missing deposit contract address"
,
expectedErr
:
ErrMissingDepositContractAddress
,
},
},
{
{
name
:
"NoL1ChainId"
,
name
:
"NoL1ChainId"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L1ChainID
=
nil
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L1ChainID
=
nil
},
expectedErr
:
"l1 chain ID must not be nil"
,
expectedErr
:
ErrMissingL1ChainID
,
},
},
{
{
name
:
"NoL2ChainId"
,
name
:
"NoL2ChainId"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L2ChainID
=
nil
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L2ChainID
=
nil
},
expectedErr
:
"l2 chain ID must not be nil"
,
expectedErr
:
ErrMissingL2ChainID
,
},
},
{
{
name
:
"ChainIDsEqual"
,
name
:
"ChainIDsEqual"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L2ChainID
=
cfg
.
L1ChainID
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L2ChainID
=
cfg
.
L1ChainID
},
expectedErr
:
"l1 and l2 chain IDs must be different"
,
expectedErr
:
ErrChainIDsSame
,
},
},
{
{
name
:
"L1ChainIdNegative"
,
name
:
"L1ChainIdNegative"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L1ChainID
=
big
.
NewInt
(
-
1
)
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L1ChainID
=
big
.
NewInt
(
-
1
)
},
expectedErr
:
"l1 chain ID must be positive"
,
expectedErr
:
ErrL1ChainIDNotPositive
,
},
},
{
{
name
:
"L1ChainIdZero"
,
name
:
"L1ChainIdZero"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L1ChainID
=
big
.
NewInt
(
0
)
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L1ChainID
=
big
.
NewInt
(
0
)
},
expectedErr
:
"l1 chain ID must be positive"
,
expectedErr
:
ErrL1ChainIDNotPositive
,
},
},
{
{
name
:
"L2ChainIdNegative"
,
name
:
"L2ChainIdNegative"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L2ChainID
=
big
.
NewInt
(
-
1
)
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L2ChainID
=
big
.
NewInt
(
-
1
)
},
expectedErr
:
"l2 chain ID must be positive"
,
expectedErr
:
ErrL2ChainIDNotPositive
,
},
},
{
{
name
:
"L2ChainIdZero"
,
name
:
"L2ChainIdZero"
,
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L2ChainID
=
big
.
NewInt
(
0
)
},
modifier
:
func
(
cfg
*
Config
)
{
cfg
.
L2ChainID
=
big
.
NewInt
(
0
)
},
expectedErr
:
"l2 chain ID must be positive"
,
expectedErr
:
ErrL2ChainIDNotPositive
,
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
...
@@ -330,7 +330,7 @@ func TestConfig_Check(t *testing.T) {
...
@@ -330,7 +330,7 @@ func TestConfig_Check(t *testing.T) {
cfg
:=
randConfig
()
cfg
:=
randConfig
()
test
.
modifier
(
cfg
)
test
.
modifier
(
cfg
)
err
:=
cfg
.
Check
()
err
:=
cfg
.
Check
()
assert
.
ErrorContains
(
t
,
err
,
test
.
expectedErr
)
assert
.
Same
(
t
,
err
,
test
.
expectedErr
)
})
})
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment