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
614b1723
Unverified
Commit
614b1723
authored
Jan 18, 2023
by
mergify[bot]
Committed by
GitHub
Jan 18, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into feat/better-encode-wd
parents
6e657870
b002d657
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
330 additions
and
77 deletions
+330
-77
message.go
op-chain-ops/crossdomain/message.go
+6
-6
cmd.go
op-node/cmd/doc/cmd.go
+54
-0
main.go
op-node/cmd/main.go
+6
-0
go.mod
op-node/go.mod
+1
-1
caching.go
op-node/metrics/caching.go
+5
-5
events.go
op-node/metrics/events.go
+5
-4
metrics.go
op-node/metrics/metrics.go
+46
-33
system_config.go
op-node/rollup/derive/system_config.go
+83
-28
factory.go
op-service/metrics/factory.go
+124
-0
No files found.
op-chain-ops/crossdomain/message.go
View file @
614b1723
...
...
@@ -14,12 +14,12 @@ import (
// version 1 messages have a value and the most significant
// byte of the nonce is a 1
type
CrossDomainMessage
struct
{
Nonce
*
big
.
Int
Sender
*
common
.
Address
Target
*
common
.
Address
Value
*
big
.
Int
GasLimit
*
big
.
Int
Data
[]
byte
Nonce
*
big
.
Int
`json:"nonce"`
Sender
*
common
.
Address
`json:"sender"`
Target
*
common
.
Address
`json:"target"`
Value
*
big
.
Int
`json:"value"`
GasLimit
*
big
.
Int
`json:"gasLimit"`
Data
[]
byte
`json:"data"`
}
// NewCrossDomainMessage creates a CrossDomainMessage.
...
...
op-node/cmd/doc/cmd.go
0 → 100644
View file @
614b1723
package
doc
import
(
"encoding/json"
"fmt"
"os"
"strings"
"github.com/ethereum-optimism/optimism/op-node/metrics"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli"
)
var
Subcommands
=
cli
.
Commands
{
{
Name
:
"metrics"
,
Usage
:
"Dumps a list of supported metrics to stdout"
,
Flags
:
[]
cli
.
Flag
{
cli
.
StringFlag
{
Name
:
"format"
,
Value
:
"markdown"
,
Usage
:
"Output format (json|markdown)"
,
},
},
Action
:
func
(
ctx
*
cli
.
Context
)
error
{
m
:=
metrics
.
NewMetrics
(
"default"
)
supportedMetrics
:=
m
.
Document
()
format
:=
ctx
.
String
(
"format"
)
if
format
!=
"markdown"
&&
format
!=
"json"
{
return
fmt
.
Errorf
(
"invalid format: %s"
,
format
)
}
if
format
==
"json"
{
enc
:=
json
.
NewEncoder
(
os
.
Stdout
)
return
enc
.
Encode
(
supportedMetrics
)
}
table
:=
tablewriter
.
NewWriter
(
os
.
Stdout
)
table
.
SetBorders
(
tablewriter
.
Border
{
Left
:
true
,
Top
:
false
,
Right
:
true
,
Bottom
:
false
})
table
.
SetCenterSeparator
(
"|"
)
table
.
SetAutoWrapText
(
false
)
table
.
SetHeader
([]
string
{
"Metric"
,
"Description"
,
"Labels"
,
"Type"
})
var
data
[][]
string
for
_
,
metric
:=
range
supportedMetrics
{
labels
:=
strings
.
Join
(
metric
.
Labels
,
","
)
data
=
append
(
data
,
[]
string
{
metric
.
Name
,
metric
.
Help
,
labels
,
metric
.
Type
})
}
table
.
AppendBulk
(
data
)
table
.
Render
()
return
nil
},
},
}
op-node/cmd/main.go
View file @
614b1723
...
...
@@ -9,6 +9,8 @@ import (
"syscall"
"time"
"github.com/ethereum-optimism/optimism/op-node/cmd/doc"
"github.com/urfave/cli"
opnode
"github.com/ethereum-optimism/optimism/op-node"
...
...
@@ -68,6 +70,10 @@ func main() {
Name
:
"genesis"
,
Subcommands
:
genesis
.
Subcommands
,
},
{
Name
:
"doc"
,
Subcommands
:
doc
.
Subcommands
,
},
}
err
:=
app
.
Run
(
os
.
Args
)
...
...
op-node/go.mod
View file @
614b1723
...
...
@@ -23,6 +23,7 @@ require (
github.com/libp2p/go-libp2p-testing v0.12.0
github.com/multiformats/go-multiaddr v0.7.0
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/olekukonko/tablewriter v0.0.5
github.com/prometheus/client_golang v1.13.0
github.com/stretchr/testify v1.8.1
github.com/urfave/cli v1.22.9
...
...
@@ -115,7 +116,6 @@ require (
github.com/multiformats/go-multistream v0.3.3 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
...
...
op-node/metrics/caching.go
View file @
614b1723
package
metrics
import
(
"github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// CacheMetrics implements the Metrics interface in the caching package,
...
...
@@ -34,16 +34,16 @@ func (m *CacheMetrics) CacheGet(typeLabel string, hit bool) {
}
}
func
NewCacheMetrics
(
registry
prometheus
.
Registerer
,
ns
string
,
name
string
,
displayName
string
)
*
CacheMetrics
{
func
NewCacheMetrics
(
factory
metrics
.
Factory
,
ns
string
,
name
string
,
displayName
string
)
*
CacheMetrics
{
return
&
CacheMetrics
{
SizeVec
:
promauto
.
With
(
registry
)
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
SizeVec
:
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Name
:
name
+
"_size"
,
Help
:
displayName
+
" cache size"
,
},
[]
string
{
"type"
,
}),
GetVec
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
GetVec
:
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Name
:
name
+
"_get"
,
Help
:
displayName
+
" lookups, hitting or not"
,
...
...
@@ -51,7 +51,7 @@ func NewCacheMetrics(registry prometheus.Registerer, ns string, name string, dis
"type"
,
"hit"
,
}),
AddVec
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
AddVec
:
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Name
:
name
+
"_add"
,
Help
:
displayName
+
" additions, evicting previous values or not"
,
...
...
op-node/metrics/events.go
View file @
614b1723
...
...
@@ -4,8 +4,9 @@ import (
"fmt"
"time"
"github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type
EventMetrics
struct
{
...
...
@@ -18,14 +19,14 @@ func (e *EventMetrics) RecordEvent() {
e
.
LastTime
.
Set
(
float64
(
time
.
Now
()
.
Unix
()))
}
func
NewEventMetrics
(
registry
prometheus
.
Registerer
,
ns
string
,
name
string
,
displayName
string
)
*
EventMetrics
{
func
NewEventMetrics
(
factory
metrics
.
Factory
,
ns
string
,
name
string
,
displayName
string
)
*
EventMetrics
{
return
&
EventMetrics
{
Total
:
promauto
.
With
(
registry
)
.
NewCounter
(
prometheus
.
CounterOpts
{
Total
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Name
:
fmt
.
Sprintf
(
"%s_total"
,
name
),
Help
:
fmt
.
Sprintf
(
"Count of %s events"
,
displayName
),
}),
LastTime
:
promauto
.
With
(
registry
)
.
NewGauge
(
prometheus
.
GaugeOpts
{
LastTime
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Name
:
fmt
.
Sprintf
(
"last_%s_unix"
,
name
),
Help
:
fmt
.
Sprintf
(
"Timestamp of last %s event"
,
displayName
),
...
...
op-node/metrics/metrics.go
View file @
614b1723
This diff is collapsed.
Click to expand it.
op-node/rollup/derive/system_config.go
View file @
614b1723
...
...
@@ -27,6 +27,17 @@ var (
ConfigUpdateEventVersion0
=
common
.
Hash
{}
)
var
(
// A left-padded uint256 equal to 32.
oneWordUint
=
common
.
Hash
{
31
:
32
}
// A left-padded uint256 equal to 64.
twoWordUint
=
common
.
Hash
{
31
:
64
}
// 24 zero bytes (the padding for a uint64 in a 32 byte word)
uint64Padding
=
make
([]
byte
,
24
)
// 12 zero bytes (the padding for an Ethereum address in a 32 byte word)
addressPadding
=
make
([]
byte
,
12
)
)
// UpdateSystemConfigWithL1Receipts filters all L1 receipts to find config updates and applies the config updates to the given sysCfg
func
UpdateSystemConfigWithL1Receipts
(
sysCfg
*
eth
.
SystemConfig
,
receipts
[]
*
types
.
Receipt
,
cfg
*
rollup
.
Config
)
error
{
var
result
error
...
...
@@ -69,50 +80,94 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
}
// indexed 1
updateType
:=
ev
.
Topics
[
2
]
// unindexed data
// Create a reader of the unindexed data
reader
:=
bytes
.
NewReader
(
ev
.
Data
)
// Counter for the number of bytes read from `reader` via `readWord`
countReadBytes
:=
0
// Helper function to read a word from the log data reader
readWord
:=
func
()
(
b
[
32
]
byte
)
{
if
_
,
err
:=
reader
.
Read
(
b
[
:
]);
err
!=
nil
{
// If there is an error reading the next 32 bytes from the reader, return an empty
// 32 byte array. We always check that the number of bytes read (`countReadBytes`)
// is equal to the expected amount at the end of each switch case.
return
b
}
countReadBytes
+=
32
return
b
}
// Attempt to read unindexed data
switch
updateType
{
case
SystemConfigUpdateBatcher
:
if
len
(
ev
.
Data
)
!=
32
*
3
{
return
fmt
.
Errorf
(
"expected 32*3 bytes in batcher hash update, but got %d bytes"
,
len
(
ev
.
Data
))
// Read the pointer, it should always equal 32.
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
}
if
x
:=
common
.
BytesToHash
(
ev
.
Data
[
:
32
]);
x
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
x
)
// Read the length, it should also always equal 32.
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
fmt
.
Errorf
(
"expected length to be 32 bytes, but got %s"
,
word
)
}
if
x
:=
common
.
BytesToHash
(
ev
.
Data
[
32
:
64
]);
x
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected length of 1 bytes32, but got %s"
,
x
)
// Indexing `word` directly is always safe here, it is guaranteed to be 32 bytes in length.
// Check that the batcher address is correctly zero-padded.
word
:=
readWord
()
if
!
bytes
.
Equal
(
word
[
:
12
],
addressPadding
)
{
return
fmt
.
Errorf
(
"expected version 0 batcher hash with zero padding, but got %x"
,
word
)
}
if
!
bytes
.
Equal
(
ev
.
Data
[
64
:
64
+
12
],
make
([]
byte
,
12
))
{
return
fmt
.
Errorf
(
"expected version 0 batcher hash with zero padding, but got %x"
,
ev
.
Data
)
destSysCfg
.
BatcherAddr
.
SetBytes
(
word
[
12
:
])
if
countReadBytes
!=
32
*
3
{
return
NewCriticalError
(
fmt
.
Errorf
(
"expected 32*3 bytes in batcher hash update, but got %d bytes"
,
len
(
ev
.
Data
)))
}
destSysCfg
.
BatcherAddr
.
SetBytes
(
ev
.
Data
[
64
+
12
:
])
return
nil
case
SystemConfigUpdateGasConfig
:
// left padded uint8
if
len
(
ev
.
Data
)
!=
32
*
4
{
return
fmt
.
Errorf
(
"expected 32*4 bytes in GPO params update data, but got %d"
,
len
(
ev
.
Data
))
case
SystemConfigUpdateGasConfig
:
// Read the pointer, it should always equal 32.
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
}
if
x
:=
common
.
BytesToHash
(
ev
.
Data
[
:
32
]);
x
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
x
)
// Read the length, it should always equal 64.
if
word
:=
readWord
();
word
!=
twoWordUint
{
return
fmt
.
Errorf
(
"expected length to be 64 bytes, but got %s"
,
word
)
}
if
x
:=
common
.
BytesToHash
(
ev
.
Data
[
32
:
64
]);
x
!=
(
common
.
Hash
{
31
:
64
})
{
return
fmt
.
Errorf
(
"expected length of 2 bytes32, but got %s"
,
x
)
// Set the system config's overhead and scalar values to the values read from the log
destSysCfg
.
Overhead
=
readWord
()
destSysCfg
.
Scalar
=
readWord
()
if
countReadBytes
!=
32
*
4
{
return
NewCriticalError
(
fmt
.
Errorf
(
"expected 32*4 bytes in GPO params update data, but got %d"
,
len
(
ev
.
Data
)))
}
copy
(
destSysCfg
.
Overhead
[
:
],
ev
.
Data
[
64
:
96
])
copy
(
destSysCfg
.
Scalar
[
:
],
ev
.
Data
[
96
:
128
])
return
nil
case
SystemConfigUpdateGasLimit
:
if
len
(
ev
.
Data
)
!=
32
*
3
{
return
fmt
.
Errorf
(
"expected 32*3 bytes in gas limit update, but got %d bytes"
,
len
(
ev
.
Data
))
// Read the pointer, it should always equal 32.
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
}
if
x
:=
common
.
BytesToHash
(
ev
.
Data
[
:
32
]);
x
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
x
)
// Read the length, it should also always equal 32.
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
fmt
.
Errorf
(
"expected length to be 32 bytes, but got %s"
,
word
)
}
if
x
:=
common
.
BytesToHash
(
ev
.
Data
[
32
:
64
]);
x
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected length of 1 bytes32, but got %s"
,
x
)
// Indexing `word` directly is always safe here, it is guaranteed to be 32 bytes in length.
// Check that the gas limit is correctly zero-padded.
word
:=
readWord
()
if
!
bytes
.
Equal
(
word
[
:
24
],
uint64Padding
)
{
return
fmt
.
Errorf
(
"expected zero padding for gaslimit, but got %x"
,
word
)
}
if
!
bytes
.
Equal
(
ev
.
Data
[
64
:
64
+
24
],
make
([]
byte
,
24
))
{
return
fmt
.
Errorf
(
"expected zero padding for gaslimit, but got %x"
,
ev
.
Data
)
destSysCfg
.
GasLimit
=
binary
.
BigEndian
.
Uint64
(
word
[
24
:
])
if
countReadBytes
!=
32
*
3
{
return
NewCriticalError
(
fmt
.
Errorf
(
"expected 32*3 bytes in gas limit update, but got %d bytes"
,
len
(
ev
.
Data
)))
}
destSysCfg
.
GasLimit
=
binary
.
BigEndian
.
Uint64
(
ev
.
Data
[
64
+
24
:
])
return
nil
case
SystemConfigUpdateUnsafeBlockSigner
:
// Ignored in derivation. This configurable applies to runtime configuration outside of the derivation.
...
...
op-service/metrics/factory.go
0 → 100644
View file @
614b1723
package
metrics
import
(
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type
Factory
interface
{
NewCounter
(
opts
prometheus
.
CounterOpts
)
prometheus
.
Counter
NewCounterVec
(
opts
prometheus
.
CounterOpts
,
labelNames
[]
string
)
*
prometheus
.
CounterVec
NewGauge
(
opts
prometheus
.
GaugeOpts
)
prometheus
.
Gauge
NewGaugeVec
(
opts
prometheus
.
GaugeOpts
,
labelNames
[]
string
)
*
prometheus
.
GaugeVec
NewHistogram
(
opts
prometheus
.
HistogramOpts
)
prometheus
.
Histogram
NewHistogramVec
(
opts
prometheus
.
HistogramOpts
,
labelNames
[]
string
)
*
prometheus
.
HistogramVec
NewSummary
(
opts
prometheus
.
SummaryOpts
)
prometheus
.
Summary
NewSummaryVec
(
opts
prometheus
.
SummaryOpts
,
labelNames
[]
string
)
*
prometheus
.
SummaryVec
Document
()
[]
DocumentedMetric
}
type
DocumentedMetric
struct
{
Type
string
`json:"type"`
Name
string
`json:"name"`
Help
string
`json:"help"`
Labels
[]
string
`json:"labels"`
}
type
documentor
struct
{
metrics
[]
DocumentedMetric
factory
promauto
.
Factory
}
func
With
(
registry
*
prometheus
.
Registry
)
Factory
{
return
&
documentor
{
factory
:
promauto
.
With
(
registry
),
}
}
func
(
d
*
documentor
)
NewCounter
(
opts
prometheus
.
CounterOpts
)
prometheus
.
Counter
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"counter"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
})
return
d
.
factory
.
NewCounter
(
opts
)
}
func
(
d
*
documentor
)
NewCounterVec
(
opts
prometheus
.
CounterOpts
,
labelNames
[]
string
)
*
prometheus
.
CounterVec
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"counter"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
Labels
:
labelNames
,
})
return
d
.
factory
.
NewCounterVec
(
opts
,
labelNames
)
}
func
(
d
*
documentor
)
NewGauge
(
opts
prometheus
.
GaugeOpts
)
prometheus
.
Gauge
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"gauge"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
})
return
d
.
factory
.
NewGauge
(
opts
)
}
func
(
d
*
documentor
)
NewGaugeVec
(
opts
prometheus
.
GaugeOpts
,
labelNames
[]
string
)
*
prometheus
.
GaugeVec
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"gauge"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
Labels
:
labelNames
,
})
return
d
.
factory
.
NewGaugeVec
(
opts
,
labelNames
)
}
func
(
d
*
documentor
)
NewHistogram
(
opts
prometheus
.
HistogramOpts
)
prometheus
.
Histogram
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"histogram"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
})
return
d
.
factory
.
NewHistogram
(
opts
)
}
func
(
d
*
documentor
)
NewHistogramVec
(
opts
prometheus
.
HistogramOpts
,
labelNames
[]
string
)
*
prometheus
.
HistogramVec
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"histogram"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
Labels
:
labelNames
,
})
return
d
.
factory
.
NewHistogramVec
(
opts
,
labelNames
)
}
func
(
d
*
documentor
)
NewSummary
(
opts
prometheus
.
SummaryOpts
)
prometheus
.
Summary
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"summary"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
})
return
d
.
factory
.
NewSummary
(
opts
)
}
func
(
d
*
documentor
)
NewSummaryVec
(
opts
prometheus
.
SummaryOpts
,
labelNames
[]
string
)
*
prometheus
.
SummaryVec
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"summary"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
Labels
:
labelNames
,
})
return
d
.
factory
.
NewSummaryVec
(
opts
,
labelNames
)
}
func
(
d
*
documentor
)
Document
()
[]
DocumentedMetric
{
return
d
.
metrics
}
func
fullName
(
ns
,
subsystem
,
name
string
)
string
{
out
:=
ns
if
subsystem
!=
""
{
out
+=
"_"
+
subsystem
}
return
out
+
"_"
+
name
}
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