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
{
Namespace: "admin",
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?
Authenticated: false,
},
......
......@@ -37,14 +37,16 @@ type rpcMetrics interface {
}
type adminAPI struct {
dr driverClient
m rpcMetrics
dr driverClient
m rpcMetrics
log log.Logger
}
func NewAdminAPI(dr driverClient, m rpcMetrics) *adminAPI {
func NewAdminAPI(dr driverClient, m rpcMetrics, log log.Logger) *adminAPI {
return &adminAPI{
dr: dr,
m: m,
dr: dr,
m: m,
log: log,
}
}
......@@ -72,10 +74,20 @@ func (n *adminAPI) SequencerActive(ctx context.Context) (bool, error) {
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")
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 {
......
......@@ -301,7 +301,7 @@ func (n *OpNode) initRPCServer(ctx context.Context, cfg *Config) error {
server.EnableP2P(p2p.NewP2PAPIBackend(n.p2pNode, n.log, n.metrics))
}
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("Starting JSON-RPC server")
......
......@@ -52,9 +52,6 @@ type Driver struct {
// true when the sequencer is active, false when it is not.
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 SequencerStateListener
......@@ -391,16 +388,6 @@ func (s *Driver) eventLoop() {
}
case respCh := <-s.sequencerActive:
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:
return
}
......@@ -483,19 +470,7 @@ func (s *Driver) SequencerActive(ctx context.Context) (bool, error) {
}
func (s *Driver) SetLogLevel(ctx context.Context, lvl string) error {
sCh := stringAndErrorChannel{
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()
}
}
return nil
}
// syncStatus returns the current sync status, and should only be called synchronously with
......@@ -575,11 +550,6 @@ type hashAndErrorChannel struct {
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.
// WARNING: This is only an outgoing signal, the blocks are not guaranteed to be retrieved.
// 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