Skip to content

Commit 10defcd

Browse files
interop: Add AllSafeDerived API (#13790)
* Add AllSafeDerived API * Update op-supervisor/supervisor/backend/backend.go Co-authored-by: Adrian Sutton <[email protected]> --------- Co-authored-by: Adrian Sutton <[email protected]>
1 parent 4a82612 commit 10defcd

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

op-supervisor/supervisor/backend/backend.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,20 @@ func (su *SupervisorBackend) SafeDerivedAt(ctx context.Context, chainID eth.Chai
475475
return v.ID(), nil
476476
}
477477

478+
// AllSafeDerivedAt returns the last derived block for each chain, from the given L1 block
479+
func (su *SupervisorBackend) AllSafeDerivedAt(ctx context.Context, derivedFrom eth.BlockID) (map[eth.ChainID]eth.BlockID, error) {
480+
chains := su.depSet.Chains()
481+
ret := map[eth.ChainID]eth.BlockID{}
482+
for _, chainID := range chains {
483+
derived, err := su.SafeDerivedAt(ctx, chainID, derivedFrom)
484+
if err != nil {
485+
return nil, fmt.Errorf("failed to get last derived block for chain %v: %w", chainID, err)
486+
}
487+
ret[chainID] = derived
488+
}
489+
return ret, nil
490+
}
491+
478492
func (su *SupervisorBackend) Finalized(ctx context.Context, chainID eth.ChainID) (eth.BlockID, error) {
479493
v, err := su.chainDBs.Finalized(chainID)
480494
if err != nil {

op-supervisor/supervisor/backend/mock.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func (m *MockBackend) Stop(ctx context.Context) error {
3939
return nil
4040
}
4141

42+
func (m *MockBackend) AllSafeDerivedAt(ctx context.Context, derivedFrom eth.BlockID) (derived map[eth.ChainID]eth.BlockID, err error) {
43+
return nil, nil
44+
}
45+
4246
func (m *MockBackend) AddL2RPC(ctx context.Context, rpc string, jwtSecret eth.Bytes32) error {
4347
return nil
4448
}

op-supervisor/supervisor/frontend/frontend.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type QueryBackend interface {
2424
Finalized(ctx context.Context, chainID eth.ChainID) (eth.BlockID, error)
2525
FinalizedL1() eth.BlockRef
2626
SuperRootAtTimestamp(ctx context.Context, timestamp hexutil.Uint64) (eth.SuperRootResponse, error)
27+
AllSafeDerivedAt(ctx context.Context, derivedFrom eth.BlockID) (derived map[eth.ChainID]eth.BlockID, err error)
2728
}
2829

2930
type Backend interface {
@@ -75,6 +76,10 @@ func (q *QueryFrontend) SuperRootAtTimestamp(ctx context.Context, timestamp hexu
7576
return q.Supervisor.SuperRootAtTimestamp(ctx, timestamp)
7677
}
7778

79+
func (q *QueryFrontend) AllSafeDerivedAt(ctx context.Context, derivedFrom eth.BlockID) (derived map[eth.ChainID]eth.BlockID, err error) {
80+
return q.Supervisor.AllSafeDerivedAt(ctx, derivedFrom)
81+
}
82+
7883
type AdminFrontend struct {
7984
Supervisor Backend
8085
}

0 commit comments

Comments
 (0)