frontend.go 3.74 KB
Newer Older
1 2 3 4 5
package frontend

import (
	"context"

6
	"github.com/ethereum-optimism/optimism/op-service/eth"
7
	"github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types"
8
	"github.com/ethereum/go-ethereum/common"
9 10 11 12 13
)

type AdminBackend interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
14
	AddL2RPC(ctx context.Context, rpc string) error
15 16 17 18
}

type QueryBackend interface {
	CheckMessage(identifier types.Identifier, payloadHash common.Hash) (types.SafetyLevel, error)
19
	CheckMessages(messages []types.Message, minSafety types.SafetyLevel) error
20 21 22 23
	DerivedFrom(ctx context.Context, chainID types.ChainID, derived eth.BlockID) (derivedFrom eth.BlockID, err error)
	UnsafeView(ctx context.Context, chainID types.ChainID, unsafe types.ReferenceView) (types.ReferenceView, error)
	SafeView(ctx context.Context, chainID types.ChainID, safe types.ReferenceView) (types.ReferenceView, error)
	Finalized(ctx context.Context, chainID types.ChainID) (eth.BlockID, error)
24 25 26
}

type UpdatesBackend interface {
27 28 29
	UpdateLocalUnsafe(chainID types.ChainID, head eth.BlockRef) error
	UpdateLocalSafe(chainID types.ChainID, derivedFrom eth.BlockRef, lastDerived eth.BlockRef) error
	UpdateFinalizedL1(chainID types.ChainID, finalized eth.BlockRef) error
30 31 32 33 34
}

type Backend interface {
	AdminBackend
	QueryBackend
35
	UpdatesBackend
36 37 38 39 40 41 42 43 44 45 46 47
}

type QueryFrontend struct {
	Supervisor QueryBackend
}

// CheckMessage checks the safety-level of an individual message.
// The payloadHash references the hash of the message-payload of the message.
func (q *QueryFrontend) CheckMessage(identifier types.Identifier, payloadHash common.Hash) (types.SafetyLevel, error) {
	return q.Supervisor.CheckMessage(identifier, payloadHash)
}

48 49 50 51 52 53 54 55
// CheckMessage checks the safety-level of a collection of messages,
// and returns if the minimum safety-level is met for all messages.
func (q *QueryFrontend) CheckMessages(
	messages []types.Message,
	minSafety types.SafetyLevel) error {
	return q.Supervisor.CheckMessages(messages, minSafety)
}

56
func (q *QueryFrontend) UnsafeView(ctx context.Context, chainID types.ChainID, unsafe types.ReferenceView) (types.ReferenceView, error) {
57
	return q.Supervisor.UnsafeView(ctx, chainID, unsafe)
58 59 60
}

func (q *QueryFrontend) SafeView(ctx context.Context, chainID types.ChainID, safe types.ReferenceView) (types.ReferenceView, error) {
61
	return q.Supervisor.SafeView(ctx, chainID, safe)
62 63 64
}

func (q *QueryFrontend) Finalized(ctx context.Context, chainID types.ChainID) (eth.BlockID, error) {
65
	return q.Supervisor.Finalized(ctx, chainID)
66 67
}

68 69
func (q *QueryFrontend) DerivedFrom(ctx context.Context, chainID types.ChainID, derived eth.BlockID) (derivedFrom eth.BlockID, err error) {
	return q.Supervisor.DerivedFrom(ctx, chainID, derived)
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
}

type AdminFrontend struct {
	Supervisor Backend
}

// Start starts the service, if it was previously stopped.
func (a *AdminFrontend) Start(ctx context.Context) error {
	return a.Supervisor.Start(ctx)
}

// Stop stops the service, if it was previously started.
func (a *AdminFrontend) Stop(ctx context.Context) error {
	return a.Supervisor.Stop(ctx)
}
85 86 87 88 89

// AddL2RPC adds a new L2 chain to the supervisor backend
func (a *AdminFrontend) AddL2RPC(ctx context.Context, rpc string) error {
	return a.Supervisor.AddL2RPC(ctx, rpc)
}
90 91 92 93 94

type UpdatesFrontend struct {
	Supervisor UpdatesBackend
}

95 96
func (u *UpdatesFrontend) UpdateLocalUnsafe(chainID types.ChainID, head eth.BlockRef) error {
	return u.Supervisor.UpdateLocalUnsafe(chainID, head)
97 98
}

99 100
func (u *UpdatesFrontend) UpdateLocalSafe(chainID types.ChainID, derivedFrom eth.BlockRef, lastDerived eth.BlockRef) error {
	return u.Supervisor.UpdateLocalSafe(chainID, derivedFrom, lastDerived)
101 102
}

103 104
func (u *UpdatesFrontend) UpdateFinalizedL1(chainID types.ChainID, finalized eth.BlockRef) error {
	return u.Supervisor.UpdateFinalizedL1(chainID, finalized)
105
}