Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-supervisor: improve logging #14262

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions op-supervisor/supervisor/backend/db/anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,34 @@ import (
// maybeInitSafeDB initializes the chain database if it is not already initialized
// it checks if the Local Safe database is empty, and loads it with the Anchor Point if so
func (db *ChainsDB) maybeInitSafeDB(id eth.ChainID, anchor types.DerivedBlockRefPair) {
logger := db.logger.New("chain", id, "derived", anchor.Derived, "source", anchor.Source)
_, err := db.LocalSafe(id)
if errors.Is(err, types.ErrFuture) {
db.logger.Info("initializing chain database", "chain", id, "anchor", anchor)
logger.Info("initializing chain database")
if err := db.UpdateCrossSafe(id, anchor.Source, anchor.Derived); err != nil {
db.logger.Warn("failed to initialize cross safe", "chain", id, "error", err)
logger.Warn("failed to initialize cross safe", "err", err)
}
db.UpdateLocalSafe(id, anchor.Source, anchor.Derived)
} else if err != nil {
db.logger.Warn("failed to check if chain database is initialized", "chain", id, "error", err)
logger.Warn("failed to check if chain database is initialized", "err", err)
} else {
db.logger.Debug("chain database already initialized", "chain", id)
logger.Debug("chain database already initialized")
}
}

func (db *ChainsDB) maybeInitEventsDB(id eth.ChainID, anchor types.DerivedBlockRefPair) {
logger := db.logger.New("chain", id, "derived", anchor.Derived, "source", anchor.Source)
_, _, _, err := db.OpenBlock(id, 0)
if errors.Is(err, types.ErrFuture) {
db.logger.Debug("initializing events database", "chain", id)
logger.Debug("initializing events database")
err := db.SealBlock(id, anchor.Derived)
if err != nil {
db.logger.Warn("failed to seal initial block", "chain", id, "error", err)
logger.Warn("failed to seal initial block", "err", err)
}
db.logger.Debug("initialized events database", "chain", id)
logger.Info("Initialized events database")
} else if err != nil {
db.logger.Warn("failed to check if logDB is initialized", "chain", id, "error", err)
logger.Warn("Failed to check if logDB is initialized", "err", err)
} else {
db.logger.Debug("events database already initialized", "chain", id)
logger.Debug("Events database already initialized")
}
}
2 changes: 2 additions & 0 deletions op-supervisor/supervisor/backend/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ func (db *ChainsDB) AttachEmitter(em event.Emitter) {
func (db *ChainsDB) OnEvent(ev event.Event) bool {
switch x := ev.(type) {
case superevents.AnchorEvent:
db.logger.Info("Received chain anchor information",
"chain", x.ChainID, "derived", x.Anchor.Derived, "source", x.Anchor.Source)
db.maybeInitEventsDB(x.ChainID, x.Anchor)
db.maybeInitSafeDB(x.ChainID, x.Anchor)
case superevents.LocalDerivedEvent:
Expand Down
6 changes: 5 additions & 1 deletion op-supervisor/supervisor/backend/syncnode/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ func (snc *SyncNodesController) AttachNodeController(chainID eth.ChainID, ctrl S
return &locks.RWMap[*ManagedNode, struct{}]{}
})
controllersForChain, _ := snc.controllers.Get(chainID)
node := NewManagedNode(snc.logger, chainID, ctrl, snc.backend, noSubscribe)

nodeID := snc.id.Add(1)
name := fmt.Sprintf("syncnode-%s-%d", chainID, nodeID)
logger := snc.logger.New("syncnode", name, "endpoint", ctrl.String())

logger.Info("Attaching node", "chain", chainID, "passive", noSubscribe)

node := NewManagedNode(logger, chainID, ctrl, snc.backend, noSubscribe)
snc.eventSys.Register(name, node, event.DefaultRegisterOpts())

controllersForChain.Set(node, struct{}{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func (m *mockSyncControl) UpdateFinalized(ctx context.Context, id eth.BlockID) e
return nil
}

func (m *mockSyncControl) String() string {
return "mock"
}

var _ SyncControl = (*mockSyncControl)(nil)

type mockBackend struct {
Expand Down
3 changes: 3 additions & 0 deletions op-supervisor/supervisor/backend/syncnode/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package syncnode

import (
"context"
"fmt"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -45,6 +46,8 @@ type SyncControl interface {
Reset(ctx context.Context, unsafe, safe, finalized eth.BlockID) error
ProvideL1(ctx context.Context, nextL1 eth.BlockRef) error
AnchorPoint(ctx context.Context) (types.DerivedBlockRefPair, error)

fmt.Stringer
}

type SyncNode interface {
Expand Down
2 changes: 1 addition & 1 deletion op-supervisor/supervisor/backend/syncnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (m *ManagedNode) onFinalizedL2(seal types.BlockSeal) {
id := seal.ID()
err := m.Node.UpdateFinalized(ctx, id)
if err != nil {
m.log.Warn("Node failed finality updating", "err", err)
m.log.Warn("Node failed finality updating", "update", seal, "err", err)
return
}
}
Expand Down