api.go 3.67 KB
Newer Older
1 2 3 4
package rpc

import (
	"context"
5
	"errors"
6

7 8
	"github.com/ethereum/go-ethereum/rpc"

9
	"github.com/ethereum-optimism/optimism/op-conductor/consensus"
10
	"github.com/ethereum-optimism/optimism/op-node/rollup"
11
	"github.com/ethereum-optimism/optimism/op-service/eth"
12 13
)

14
var ErrNotLeader = errors.New("refusing to proxy request to non-leader sequencer")
15 16 17

// API defines the interface for the op-conductor API.
type API interface {
18 19 20 21
	// OverrideLeader is used to override the leader status, this is only used to return true for Leader() & LeaderWithID() calls.
	// It does not impact the actual raft consensus leadership status. It is supposed to be used when the cluster is unhealthy
	// and the node is the only one up, to allow batcher to be able to connect to the node, so that it could download blocks from the manually started sequencer.
	OverrideLeader(ctx context.Context) error
22 23 24 25
	// Pause pauses op-conductor.
	Pause(ctx context.Context) error
	// Resume resumes op-conductor.
	Resume(ctx context.Context) error
26 27
	// Stop stops op-conductor.
	Stop(ctx context.Context) error
28 29 30 31
	// Paused returns true if op-conductor is paused.
	Paused(ctx context.Context) (bool, error)
	// Stopped returns true if op-conductor is stopped.
	Stopped(ctx context.Context) (bool, error)
32 33
	// SequencerHealthy returns true if the sequencer is healthy.
	SequencerHealthy(ctx context.Context) (bool, error)
34 35 36 37 38

	// Consensus related APIs
	// Leader returns true if the server is the leader.
	Leader(ctx context.Context) (bool, error)
	// LeaderWithID returns the current leader's server info.
39
	LeaderWithID(ctx context.Context) (*consensus.ServerInfo, error)
40
	// AddServerAsVoter adds a server as a voter to the cluster.
41
	AddServerAsVoter(ctx context.Context, id string, addr string, version uint64) error
42
	// AddServerAsNonvoter adds a server as a non-voter to the cluster. non-voter will not participate in leader election.
43
	AddServerAsNonvoter(ctx context.Context, id string, addr string, version uint64) error
44
	// RemoveServer removes a server from the cluster.
45
	RemoveServer(ctx context.Context, id string, version uint64) error
46 47 48 49
	// TransferLeader transfers leadership to another server.
	TransferLeader(ctx context.Context) error
	// TransferLeaderToServer transfers leadership to a specific server.
	TransferLeaderToServer(ctx context.Context, id string, addr string) error
50
	// ClusterMembership returns the current cluster membership configuration.
51
	ClusterMembership(ctx context.Context) (*consensus.ClusterMembership, error)
52 53

	// APIs called by op-node
54
	// Active returns true if op-conductor is active (not paused or stopped).
55
	Active(ctx context.Context) (bool, error)
56
	// CommitUnsafePayload commits an unsafe payload (latest head) to the consensus layer.
57
	CommitUnsafePayload(ctx context.Context, payload *eth.ExecutionPayloadEnvelope) error
58
}
59 60 61 62

// ExecutionProxyAPI defines the methods proxied to the execution rpc backend
// This should include all methods that are called by op-batcher or op-proposer
type ExecutionProxyAPI interface {
63
	GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error)
64 65 66 67 68
}

// NodeProxyAPI defines the methods proxied to the node rpc backend
// This should include all methods that are called by op-batcher or op-proposer
type NodeProxyAPI interface {
69
	OutputAtBlock(ctx context.Context, blockNumString string) (*eth.OutputResponse, error)
70
	SyncStatus(ctx context.Context) (*eth.SyncStatus, error)
71 72 73 74 75 76 77
	RollupConfig(ctx context.Context) (*rollup.Config, error)
}

// NodeProxyAPI defines the methods proxied to the node rpc backend
// This should include all methods that are called by op-batcher or op-proposer
type NodeAdminProxyAPI interface {
	SequencerActive(ctx context.Context) (bool, error)
78
}