Commit d005e41a authored by protolambda's avatar protolambda

uncomment snapshot logging, defer json encoding

parent a704a097
...@@ -144,8 +144,7 @@ func (n *OpNode) initL2(ctx context.Context, cfg *Config, snapshotLog log.Logger ...@@ -144,8 +144,7 @@ func (n *OpNode) initL2(ctx context.Context, cfg *Config, snapshotLog log.Logger
return err return err
} }
snap := snapshotLog.New() n.l2Engine = driver.NewDriver(&cfg.Driver, &cfg.Rollup, source, n.l1Source, n, n.log, snapshotLog)
n.l2Engine = driver.NewDriver(&cfg.Driver, &cfg.Rollup, source, n.l1Source, n, n.log, snap)
return nil return nil
} }
......
...@@ -2,6 +2,7 @@ package driver ...@@ -2,6 +2,7 @@ package driver
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"io" "io"
gosync "sync" gosync "sync"
...@@ -341,18 +342,22 @@ func (s *state) eventLoop() { ...@@ -341,18 +342,22 @@ func (s *state) eventLoop() {
} }
} }
// deferJSONString helps avoid a JSON-encoding performance hit if the snapshot logger does not run
type deferJSONString struct {
x any
}
func (v deferJSONString) String() string {
out, _ := json.Marshal(v.x)
return string(out)
}
func (s *state) snapshot(event string) { func (s *state) snapshot(event string) {
// l1HeadJSON, _ := json.Marshal(s.l1Head) s.snapshotLog.Info("Rollup State Snapshot",
// l1CurrentJSON, _ := json.Marshal(s.derivation.CurrentL1()) "event", event,
// l2HeadJSON, _ := json.Marshal(s.l2Head) "l1Head", deferJSONString{s.l1Head},
// l2SafeHeadJSON, _ := json.Marshal(s.l2SafeHead) "l1Current", deferJSONString{s.derivation.Progress().Origin},
// l2FinalizedHeadJSON, _ := json.Marshal(s.l2Finalized) "l2Head", deferJSONString{s.l2Head},
"l2SafeHead", deferJSONString{s.l2SafeHead},
// s.snapshotLog.Info("Rollup State Snapshot", "l2FinalizedHead", deferJSONString{s.l2Finalized})
// "event", event,
// "l1Head", string(l1HeadJSON),
// "l1Current", string(l1CurrentJSON),
// "l2Head", string(l2HeadJSON),
// "l2SafeHead", string(l2SafeHeadJSON),
// "l2FinalizedHead", string(l2FinalizedHeadJSON))
} }
...@@ -161,8 +161,8 @@ func NewSnapshotLogger(ctx *cli.Context) (log.Logger, error) { ...@@ -161,8 +161,8 @@ func NewSnapshotLogger(ctx *cli.Context) (log.Logger, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
handler = log.SyncHandler(handler) handler = log.SyncHandler(handler)
}
logger := log.New() logger := log.New()
logger.SetHandler(handler) logger.SetHandler(handler)
return logger, nil return logger, nil
......
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