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
9dd1b384
Commit
9dd1b384
authored
Sep 29, 2023
by
Seungju Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: standardize admin api into op-service
parent
f94019c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
40 deletions
+62
-40
api.go
op-batcher/rpc/api.go
+3
-0
api.go
op-node/node/api.go
+12
-40
api.go
op-service/rpc/api.go
+47
-0
No files found.
op-batcher/rpc/api.go
View file @
9dd1b384
...
@@ -2,6 +2,8 @@ package rpc
...
@@ -2,6 +2,8 @@ package rpc
import
(
import
(
"context"
"context"
"github.com/ethereum-optimism/optimism/op-service/rpc"
)
)
type
batcherClient
interface
{
type
batcherClient
interface
{
...
@@ -10,6 +12,7 @@ type batcherClient interface {
...
@@ -10,6 +12,7 @@ type batcherClient interface {
}
}
type
adminAPI
struct
{
type
adminAPI
struct
{
*
rpc
.
CommonAdminAPI
b
batcherClient
b
batcherClient
}
}
...
...
op-node/node/api.go
View file @
9dd1b384
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/version"
"github.com/ethereum-optimism/optimism/op-node/version"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/eth"
oplog
"github.com/ethereum-optimism/optimism/op-service/log
"
"github.com/ethereum-optimism/optimism/op-service/rpc
"
)
)
type
l2EthClient
interface
{
type
l2EthClient
interface
{
...
@@ -31,79 +31,51 @@ type driverClient interface {
...
@@ -31,79 +31,51 @@ type driverClient interface {
SequencerActive
(
context
.
Context
)
(
bool
,
error
)
SequencerActive
(
context
.
Context
)
(
bool
,
error
)
}
}
type
rpcMetrics
interface
{
// RecordRPCServerRequest returns a function that records the duration of serving the given RPC method
RecordRPCServerRequest
(
method
string
)
func
()
}
type
adminAPI
struct
{
type
adminAPI
struct
{
dr
driverClient
*
rpc
.
CommonAdminAPI
m
rpcMetrics
dr
driverClient
log
log
.
Logger
}
}
func
NewAdminAPI
(
dr
driverClient
,
m
rpcMetrics
,
log
log
.
Logger
)
*
adminAPI
{
func
NewAdminAPI
(
dr
driverClient
,
m
rpc
.
Rpc
Metrics
,
log
log
.
Logger
)
*
adminAPI
{
return
&
adminAPI
{
return
&
adminAPI
{
dr
:
dr
,
dr
:
dr
,
m
:
m
,
CommonAdminAPI
:
rpc
.
NewCommonAdminAPI
(
m
,
log
),
log
:
log
,
}
}
}
}
func
(
n
*
adminAPI
)
ResetDerivationPipeline
(
ctx
context
.
Context
)
error
{
func
(
n
*
adminAPI
)
ResetDerivationPipeline
(
ctx
context
.
Context
)
error
{
recordDur
:=
n
.
m
.
RecordRPCServerRequest
(
"admin_resetDerivationPipeline"
)
recordDur
:=
n
.
M
.
RecordRPCServerRequest
(
"admin_resetDerivationPipeline"
)
defer
recordDur
()
defer
recordDur
()
return
n
.
dr
.
ResetDerivationPipeline
(
ctx
)
return
n
.
dr
.
ResetDerivationPipeline
(
ctx
)
}
}
func
(
n
*
adminAPI
)
StartSequencer
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
error
{
func
(
n
*
adminAPI
)
StartSequencer
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
error
{
recordDur
:=
n
.
m
.
RecordRPCServerRequest
(
"admin_startSequencer"
)
recordDur
:=
n
.
M
.
RecordRPCServerRequest
(
"admin_startSequencer"
)
defer
recordDur
()
defer
recordDur
()
return
n
.
dr
.
StartSequencer
(
ctx
,
blockHash
)
return
n
.
dr
.
StartSequencer
(
ctx
,
blockHash
)
}
}
func
(
n
*
adminAPI
)
StopSequencer
(
ctx
context
.
Context
)
(
common
.
Hash
,
error
)
{
func
(
n
*
adminAPI
)
StopSequencer
(
ctx
context
.
Context
)
(
common
.
Hash
,
error
)
{
recordDur
:=
n
.
m
.
RecordRPCServerRequest
(
"admin_stopSequencer"
)
recordDur
:=
n
.
M
.
RecordRPCServerRequest
(
"admin_stopSequencer"
)
defer
recordDur
()
defer
recordDur
()
return
n
.
dr
.
StopSequencer
(
ctx
)
return
n
.
dr
.
StopSequencer
(
ctx
)
}
}
func
(
n
*
adminAPI
)
SequencerActive
(
ctx
context
.
Context
)
(
bool
,
error
)
{
func
(
n
*
adminAPI
)
SequencerActive
(
ctx
context
.
Context
)
(
bool
,
error
)
{
recordDur
:=
n
.
m
.
RecordRPCServerRequest
(
"admin_sequencerActive"
)
recordDur
:=
n
.
M
.
RecordRPCServerRequest
(
"admin_sequencerActive"
)
defer
recordDur
()
defer
recordDur
()
return
n
.
dr
.
SequencerActive
(
ctx
)
return
n
.
dr
.
SequencerActive
(
ctx
)
}
}
func
(
n
*
adminAPI
)
SetLogLevel
(
ctx
context
.
Context
,
lvlStr
string
)
error
{
recordDur
:=
n
.
m
.
RecordRPCServerRequest
(
"admin_setLogLevel"
)
defer
recordDur
()
h
:=
n
.
log
.
GetHandler
()
lvl
,
err
:=
log
.
LvlFromString
(
lvlStr
)
if
err
!=
nil
{
return
err
}
// We set the log level, and do not wrap the handler with an additional filter handler,
// as the underlying handler would otherwise also still filter with the previous log level.
lvlSetter
,
ok
:=
h
.
(
oplog
.
LvlSetter
)
if
!
ok
{
return
fmt
.
Errorf
(
"log handler type %T cannot change log level"
,
h
)
}
lvlSetter
.
SetLogLevel
(
lvl
)
return
nil
}
type
nodeAPI
struct
{
type
nodeAPI
struct
{
config
*
rollup
.
Config
config
*
rollup
.
Config
client
l2EthClient
client
l2EthClient
dr
driverClient
dr
driverClient
log
log
.
Logger
log
log
.
Logger
m
rpcMetrics
m
rpc
.
Rpc
Metrics
}
}
func
NewNodeAPI
(
config
*
rollup
.
Config
,
l2Client
l2EthClient
,
dr
driverClient
,
log
log
.
Logger
,
m
rpcMetrics
)
*
nodeAPI
{
func
NewNodeAPI
(
config
*
rollup
.
Config
,
l2Client
l2EthClient
,
dr
driverClient
,
log
log
.
Logger
,
m
rpc
.
Rpc
Metrics
)
*
nodeAPI
{
return
&
nodeAPI
{
return
&
nodeAPI
{
config
:
config
,
config
:
config
,
client
:
l2Client
,
client
:
l2Client
,
...
...
op-service/rpc/api.go
0 → 100644
View file @
9dd1b384
package
rpc
import
(
"context"
"fmt"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum/go-ethereum/log"
)
type
RpcMetrics
interface
{
// RecordRPCServerRequest returns a function that records the duration of serving the given RPC method
RecordRPCServerRequest
(
method
string
)
func
()
}
type
CommonAdminAPI
struct
{
M
RpcMetrics
log
log
.
Logger
}
func
NewCommonAdminAPI
(
m
RpcMetrics
,
log
log
.
Logger
)
*
CommonAdminAPI
{
return
&
CommonAdminAPI
{
M
:
m
,
log
:
log
,
}
}
func
(
n
*
CommonAdminAPI
)
SetLogLevel
(
ctx
context
.
Context
,
lvlStr
string
)
error
{
recordDur
:=
n
.
M
.
RecordRPCServerRequest
(
"admin_setLogLevel"
)
defer
recordDur
()
h
:=
n
.
log
.
GetHandler
()
lvl
,
err
:=
log
.
LvlFromString
(
lvlStr
)
if
err
!=
nil
{
return
err
}
// We set the log level, and do not wrap the handler with an additional filter handler,
// as the underlying handler would otherwise also still filter with the previous log level.
lvlSetter
,
ok
:=
h
.
(
oplog
.
LvlSetter
)
if
!
ok
{
return
fmt
.
Errorf
(
"log handler type %T cannot change log level"
,
h
)
}
lvlSetter
.
SetLogLevel
(
lvl
)
return
nil
}
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