Commit e3ecfc47 authored by dhanu's avatar dhanu

cleanup-logging-service-utils - move driver changes to adminAPI

parent dd604bd9
...@@ -88,7 +88,7 @@ func NewL2Verifier(t Testing, log log.Logger, l1 derive.L1Fetcher, eng L2API, cf ...@@ -88,7 +88,7 @@ func NewL2Verifier(t Testing, log log.Logger, l1 derive.L1Fetcher, eng L2API, cf
{ {
Namespace: "admin", Namespace: "admin",
Version: "", Version: "",
Service: node.NewAdminAPI(backend, m), Service: node.NewAdminAPI(backend, m, log),
Public: true, // TODO: this field is deprecated. Do we even need this anymore? Public: true, // TODO: this field is deprecated. Do we even need this anymore?
Authenticated: false, Authenticated: false,
}, },
......
...@@ -39,12 +39,14 @@ type rpcMetrics interface { ...@@ -39,12 +39,14 @@ type rpcMetrics interface {
type adminAPI struct { type adminAPI struct {
dr driverClient dr driverClient
m rpcMetrics m rpcMetrics
log log.Logger
} }
func NewAdminAPI(dr driverClient, m rpcMetrics) *adminAPI { func NewAdminAPI(dr driverClient, m rpcMetrics, log log.Logger) *adminAPI {
return &adminAPI{ return &adminAPI{
dr: dr, dr: dr,
m: m, m: m,
log: log,
} }
} }
...@@ -72,10 +74,20 @@ func (n *adminAPI) SequencerActive(ctx context.Context) (bool, error) { ...@@ -72,10 +74,20 @@ func (n *adminAPI) SequencerActive(ctx context.Context) (bool, error) {
return n.dr.SequencerActive(ctx) return n.dr.SequencerActive(ctx)
} }
func (n *adminAPI) SetLogLevel(ctx context.Context, lvl string) error { func (n *adminAPI) SetLogLevel(ctx context.Context, lvlStr string) error {
recordDur := n.m.RecordRPCServerRequest("admin_setLogLevel") recordDur := n.m.RecordRPCServerRequest("admin_setLogLevel")
defer recordDur() defer recordDur()
return n.dr.SetLogLevel(ctx, lvl)
h := n.log.GetHandler()
lvl, err := log.LvlFromString(lvlStr)
if err != nil {
return err
}
h = log.LvlFilterHandler(lvl, h)
n.log.SetHandler(h)
return nil
} }
type nodeAPI struct { type nodeAPI struct {
......
...@@ -301,7 +301,7 @@ func (n *OpNode) initRPCServer(ctx context.Context, cfg *Config) error { ...@@ -301,7 +301,7 @@ func (n *OpNode) initRPCServer(ctx context.Context, cfg *Config) error {
server.EnableP2P(p2p.NewP2PAPIBackend(n.p2pNode, n.log, n.metrics)) server.EnableP2P(p2p.NewP2PAPIBackend(n.p2pNode, n.log, n.metrics))
} }
if cfg.RPC.EnableAdmin { if cfg.RPC.EnableAdmin {
server.EnableAdminAPI(NewAdminAPI(n.l2Driver, n.metrics)) server.EnableAdminAPI(NewAdminAPI(n.l2Driver, n.metrics, n.log))
n.log.Info("Admin RPC enabled") n.log.Info("Admin RPC enabled")
} }
n.log.Info("Starting JSON-RPC server") n.log.Info("Starting JSON-RPC server")
......
...@@ -52,9 +52,6 @@ type Driver struct { ...@@ -52,9 +52,6 @@ type Driver struct {
// true when the sequencer is active, false when it is not. // true when the sequencer is active, false when it is not.
sequencerActive chan chan bool sequencerActive chan chan bool
// Upon receiving a channel in this channel, set the log level.
seLogLevel chan stringAndErrorChannel
// sequencerNotifs is notified when the sequencer is started or stopped // sequencerNotifs is notified when the sequencer is started or stopped
sequencerNotifs SequencerStateListener sequencerNotifs SequencerStateListener
...@@ -391,16 +388,6 @@ func (s *Driver) eventLoop() { ...@@ -391,16 +388,6 @@ func (s *Driver) eventLoop() {
} }
case respCh := <-s.sequencerActive: case respCh := <-s.sequencerActive:
respCh <- !s.driverConfig.SequencerStopped respCh <- !s.driverConfig.SequencerStopped
case respCh := <-s.seLogLevel:
lvlStr := respCh.str
h := s.log.GetHandler()
lvl, err := log.LvlFromString(lvlStr)
if err != nil {
respCh.err <- err
continue
}
h = log.LvlFilterHandler(lvl, h)
s.log.SetHandler(h)
case <-s.done: case <-s.done:
return return
} }
...@@ -483,19 +470,7 @@ func (s *Driver) SequencerActive(ctx context.Context) (bool, error) { ...@@ -483,19 +470,7 @@ func (s *Driver) SequencerActive(ctx context.Context) (bool, error) {
} }
func (s *Driver) SetLogLevel(ctx context.Context, lvl string) error { func (s *Driver) SetLogLevel(ctx context.Context, lvl string) error {
sCh := stringAndErrorChannel{ return nil
str: lvl,
err: make(chan error, 1),
}
select {
case <-ctx.Done():
return ctx.Err()
case s.seLogLevel <- sCh:
select {
case <-ctx.Done():
return ctx.Err()
}
}
} }
// syncStatus returns the current sync status, and should only be called synchronously with // syncStatus returns the current sync status, and should only be called synchronously with
...@@ -575,11 +550,6 @@ type hashAndErrorChannel struct { ...@@ -575,11 +550,6 @@ type hashAndErrorChannel struct {
err chan error err chan error
} }
type stringAndErrorChannel struct {
str string
err chan error
}
// checkForGapInUnsafeQueue checks if there is a gap in the unsafe queue and attempts to retrieve the missing payloads from an alt-sync method. // checkForGapInUnsafeQueue checks if there is a gap in the unsafe queue and attempts to retrieve the missing payloads from an alt-sync method.
// WARNING: This is only an outgoing signal, the blocks are not guaranteed to be retrieved. // WARNING: This is only an outgoing signal, the blocks are not guaranteed to be retrieved.
// Results are received through OnUnsafeL2Payload. // Results are received through OnUnsafeL2Payload.
......
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