Skip to content
Merged
16 changes: 16 additions & 0 deletions op-supervisor/supervisor/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,14 @@ func (su *SupervisorBackend) SafeDerivedAt(ctx context.Context, chainID eth.Chai
return v.ID(), nil
}

func (su *SupervisorBackend) FindSealedBlock(ctx context.Context, chainID eth.ChainID, number uint64) (eth.BlockID, error) {
seal, err := su.chainDBs.FindSealedBlock(chainID, number)
if err != nil {
return eth.BlockID{}, err
}
return seal.ID(), nil
}

// AllSafeDerivedAt returns the last derived block for each chain, from the given L1 block
func (su *SupervisorBackend) AllSafeDerivedAt(ctx context.Context, source eth.BlockID) (map[eth.ChainID]eth.BlockID, error) {
chains := su.depSet.Chains()
Expand All @@ -548,6 +556,14 @@ func (su *SupervisorBackend) FinalizedL1() eth.BlockRef {
return su.chainDBs.FinalizedL1()
}

func (su *SupervisorBackend) IsLocalUnsafe(ctx context.Context, chainID eth.ChainID, block eth.BlockID) error {
return su.chainDBs.IsLocalUnsafe(chainID, block)
}

func (su *SupervisorBackend) IsLocalSafe(ctx context.Context, chainID eth.ChainID, block eth.BlockID) error {
return su.chainDBs.IsLocalSafe(chainID, block)
}

func (su *SupervisorBackend) CrossDerivedToSource(ctx context.Context, chainID eth.ChainID, derived eth.BlockID) (source eth.BlockRef, err error) {
v, err := su.chainDBs.CrossDerivedToSourceRef(chainID, derived)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions op-supervisor/supervisor/backend/db/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func (db *ChainsDB) IsLocalUnsafe(chainID eth.ChainID, block eth.BlockID) error
return nil
}

func (db *ChainsDB) IsLocalSafe(chainID eth.ChainID, block eth.BlockID) error {
ldb, ok := db.localDBs.Get(chainID)
if !ok {
return types.ErrUnknownChain
}
return ldb.ContainsDerived(block)
}

func (db *ChainsDB) SafeDerivedAt(chainID eth.ChainID, source eth.BlockID) (types.BlockSeal, error) {
lDB, ok := db.localDBs.Get(chainID)
if !ok {
Expand Down
5 changes: 0 additions & 5 deletions op-supervisor/supervisor/backend/db/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ func (db *ChainsDB) initializedUpdateLocalSafe(chain eth.ChainID, source eth.Blo
return
}
logger.Warn("Failed to update local safe", "err", err)
db.emitter.Emit(superevents.LocalSafeOutOfSyncEvent{
ChainID: chain,
L1Ref: source,
Err: err,
})
return
}
logger.Info("Updated local safe DB")
Expand Down
10 changes: 0 additions & 10 deletions op-supervisor/supervisor/backend/superevents/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ func (ev FinalizedL2UpdateEvent) String() string {
return "finalized-l2-update"
}

type LocalSafeOutOfSyncEvent struct {
ChainID eth.ChainID
L1Ref eth.BlockRef
Err error
}

func (ev LocalSafeOutOfSyncEvent) String() string {
return "local-safe-out-of-sync"
}

type LocalUnsafeReceivedEvent struct {
ChainID eth.ChainID
NewLocalUnsafe eth.BlockRef
Expand Down
42 changes: 41 additions & 1 deletion op-supervisor/supervisor/backend/syncnode/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type mockSyncControl struct {
updateCrossUnsafeFn func(ctx context.Context, derived eth.BlockID) error
updateFinalizedFn func(ctx context.Context, id eth.BlockID) error
pullEventFn func(ctx context.Context) (*types.ManagedEvent, error)
blockRefByNumFn func(ctx context.Context, number uint64) (eth.BlockRef, error)

subscribeEvents gethevent.FeedOf[*types.ManagedEvent]
}
Expand Down Expand Up @@ -86,17 +87,39 @@ func (m *mockSyncControl) UpdateFinalized(ctx context.Context, id eth.BlockID) e
return nil
}

func (m *mockSyncControl) BlockRefByNumber(ctx context.Context, number uint64) (eth.BlockRef, error) {
if m.blockRefByNumFn != nil {
return m.blockRefByNumFn(ctx, number)
}
return eth.BlockRef{}, nil
}

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

var _ SyncControl = (*mockSyncControl)(nil)

type mockBackend struct {
safeDerivedAtFn func(ctx context.Context, chainID eth.ChainID, source eth.BlockID) (eth.BlockID, error)
localSafeFn func(ctx context.Context, chainID eth.ChainID) (pair types.DerivedIDPair, err error)
finalizedFn func(ctx context.Context, chainID eth.ChainID) (eth.BlockID, error)
safeDerivedAtFn func(ctx context.Context, chainID eth.ChainID, source eth.BlockID) (eth.BlockID, error)
findSealedBlockFn func(ctx context.Context, chainID eth.ChainID, num uint64) (eth.BlockID, error)
isLocalSafeFn func(ctx context.Context, chainID eth.ChainID, blockID eth.BlockID) error
isLocalUnsafeFn func(ctx context.Context, chainID eth.ChainID, blockID eth.BlockID) error
}

func (m *mockBackend) FindSealedBlock(ctx context.Context, chainID eth.ChainID, num uint64) (eth.BlockID, error) {
if m.findSealedBlockFn != nil {
return m.findSealedBlockFn(ctx, chainID, num)
}
return eth.BlockID{}, nil
}

func (m *mockBackend) LocalSafe(ctx context.Context, chainID eth.ChainID) (pair types.DerivedIDPair, err error) {
if m.localSafeFn != nil {
return m.localSafeFn(ctx, chainID)
}
return types.DerivedIDPair{}, nil
}

Expand All @@ -108,6 +131,20 @@ func (m *mockBackend) LocalUnsafe(ctx context.Context, chainID eth.ChainID) (eth
return eth.BlockID{}, nil
}

func (m *mockBackend) IsLocalSafe(ctx context.Context, chainID eth.ChainID, blockID eth.BlockID) error {
if m.isLocalSafeFn != nil {
return m.isLocalSafeFn(ctx, chainID, blockID)
}
return nil
}

func (m *mockBackend) IsLocalUnsafe(ctx context.Context, chainID eth.ChainID, blockID eth.BlockID) error {
if m.isLocalUnsafeFn != nil {
return m.isLocalUnsafeFn(ctx, chainID, blockID)
}
return nil
}

func (m *mockBackend) SafeDerivedAt(ctx context.Context, chainID eth.ChainID, source eth.BlockID) (derived eth.BlockID, err error) {
if m.safeDerivedAtFn != nil {
return m.safeDerivedAtFn(ctx, chainID, source)
Expand All @@ -116,6 +153,9 @@ func (m *mockBackend) SafeDerivedAt(ctx context.Context, chainID eth.ChainID, so
}

func (m *mockBackend) Finalized(ctx context.Context, chainID eth.ChainID) (eth.BlockID, error) {
if m.finalizedFn != nil {
return m.finalizedFn(ctx, chainID)
}
return eth.BlockID{}, nil
}

Expand Down
1 change: 1 addition & 0 deletions op-supervisor/supervisor/backend/syncnode/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type SyncSource interface {
type SyncControl interface {
SubscribeEvents(ctx context.Context, c chan *types.ManagedEvent) (ethereum.Subscription, error)
PullEvent(ctx context.Context) (*types.ManagedEvent, error)
BlockRefByNumber(ctx context.Context, number uint64) (eth.BlockRef, error)

UpdateCrossUnsafe(ctx context.Context, id eth.BlockID) error
UpdateCrossSafe(ctx context.Context, derived eth.BlockID, source eth.BlockID) error
Expand Down
Loading