Commit 10defcd1 authored by Axel Kingsley's avatar Axel Kingsley Committed by GitHub

interop: Add AllSafeDerived API (#13790)

* Add AllSafeDerived API

* Update op-supervisor/supervisor/backend/backend.go
Co-authored-by: default avatarAdrian Sutton <adrian@oplabs.co>

---------
Co-authored-by: default avatarAdrian Sutton <adrian@oplabs.co>
parent 4a82612b
......@@ -475,6 +475,20 @@ func (su *SupervisorBackend) SafeDerivedAt(ctx context.Context, chainID eth.Chai
return v.ID(), nil
}
// AllSafeDerivedAt returns the last derived block for each chain, from the given L1 block
func (su *SupervisorBackend) AllSafeDerivedAt(ctx context.Context, derivedFrom eth.BlockID) (map[eth.ChainID]eth.BlockID, error) {
chains := su.depSet.Chains()
ret := map[eth.ChainID]eth.BlockID{}
for _, chainID := range chains {
derived, err := su.SafeDerivedAt(ctx, chainID, derivedFrom)
if err != nil {
return nil, fmt.Errorf("failed to get last derived block for chain %v: %w", chainID, err)
}
ret[chainID] = derived
}
return ret, nil
}
func (su *SupervisorBackend) Finalized(ctx context.Context, chainID eth.ChainID) (eth.BlockID, error) {
v, err := su.chainDBs.Finalized(chainID)
if err != nil {
......
......@@ -39,6 +39,10 @@ func (m *MockBackend) Stop(ctx context.Context) error {
return nil
}
func (m *MockBackend) AllSafeDerivedAt(ctx context.Context, derivedFrom eth.BlockID) (derived map[eth.ChainID]eth.BlockID, err error) {
return nil, nil
}
func (m *MockBackend) AddL2RPC(ctx context.Context, rpc string, jwtSecret eth.Bytes32) error {
return nil
}
......
......@@ -24,6 +24,7 @@ type QueryBackend interface {
Finalized(ctx context.Context, chainID eth.ChainID) (eth.BlockID, error)
FinalizedL1() eth.BlockRef
SuperRootAtTimestamp(ctx context.Context, timestamp hexutil.Uint64) (eth.SuperRootResponse, error)
AllSafeDerivedAt(ctx context.Context, derivedFrom eth.BlockID) (derived map[eth.ChainID]eth.BlockID, err error)
}
type Backend interface {
......@@ -75,6 +76,10 @@ func (q *QueryFrontend) SuperRootAtTimestamp(ctx context.Context, timestamp hexu
return q.Supervisor.SuperRootAtTimestamp(ctx, timestamp)
}
func (q *QueryFrontend) AllSafeDerivedAt(ctx context.Context, derivedFrom eth.BlockID) (derived map[eth.ChainID]eth.BlockID, err error) {
return q.Supervisor.AllSafeDerivedAt(ctx, derivedFrom)
}
type AdminFrontend struct {
Supervisor Backend
}
......
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