Skip to content

Commit

Permalink
[op-conductor] Add status check apis (#10196)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x00101010 authored Apr 17, 2024
1 parent 6f99544 commit 02c1193
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
6 changes: 5 additions & 1 deletion op-conductor/rpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type API interface {
Pause(ctx context.Context) error
// Resume resumes op-conductor.
Resume(ctx context.Context) error
// 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)
// SequencerHealthy returns true if the sequencer is healthy.
SequencerHealthy(ctx context.Context) (bool, error)

Expand All @@ -41,7 +45,7 @@ type API interface {
ClusterMembership(ctx context.Context) ([]*consensus.ServerInfo, error)

// APIs called by op-node
// Active returns true if op-conductor is active.
// Active returns true if op-conductor is active (not paused or stopped).
Active(ctx context.Context) (bool, error)
// CommitUnsafePayload commits a unsafe payload (latest head) to the consensus layer.
CommitUnsafePayload(ctx context.Context, payload *eth.ExecutionPayloadEnvelope) error
Expand Down
10 changes: 10 additions & 0 deletions op-conductor/rpc/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func NewAPIBackend(log log.Logger, con conductor) *APIBackend {

var _ API = (*APIBackend)(nil)

// Paused implements API.
func (api *APIBackend) Paused(ctx context.Context) (bool, error) {
return api.con.Paused(), nil
}

// Stopped implements API.
func (api *APIBackend) Stopped(ctx context.Context) (bool, error) {
return api.con.Stopped(), nil
}

// Active implements API.
func (api *APIBackend) Active(_ context.Context) (bool, error) {
return !api.con.Stopped() && !api.con.Paused(), nil
Expand Down
14 changes: 14 additions & 0 deletions op-conductor/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ func prefixRPC(method string) string {
return RPCNamespace + "_" + method
}

// Paused implements API.
func (c *APIClient) Paused(ctx context.Context) (bool, error) {
var paused bool
err := c.c.CallContext(ctx, &paused, prefixRPC("paused"))
return paused, err
}

// Stopped implements API.
func (c *APIClient) Stopped(ctx context.Context) (bool, error) {
var stopped bool
err := c.c.CallContext(ctx, &stopped, prefixRPC("stopped"))
return stopped, err
}

// Active implements API.
func (c *APIClient) Active(ctx context.Context) (bool, error) {
var active bool
Expand Down
18 changes: 18 additions & 0 deletions op-e2e/sequencer_failover_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func setupSequencerFailoverTest(t *testing.T) (*System, map[string]*conductor) {
require.NoError(t, c3.client.Resume(ctx))

// final check, make sure everything is in the right place
require.True(t, conductorResumed(t, ctx, c1))
require.True(t, conductorResumed(t, ctx, c2))
require.True(t, conductorResumed(t, ctx, c3))
require.False(t, conductorStopped(t, ctx, c1))
require.False(t, conductorStopped(t, ctx, c2))
require.False(t, conductorStopped(t, ctx, c3))
require.True(t, conductorActive(t, ctx, c1))
require.True(t, conductorActive(t, ctx, c2))
require.True(t, conductorActive(t, ctx, c3))
Expand Down Expand Up @@ -411,6 +417,18 @@ func conductorActive(t *testing.T, ctx context.Context, con *conductor) bool {
return active
}

func conductorResumed(t *testing.T, ctx context.Context, con *conductor) bool {
paused, err := con.client.Paused(ctx)
require.NoError(t, err)
return !paused
}

func conductorStopped(t *testing.T, ctx context.Context, con *conductor) bool {
stopped, err := con.client.Stopped(ctx)
require.NoError(t, err)
return stopped
}

func sequencerActive(t *testing.T, ctx context.Context, rollupClient *sources.RollupClient) bool {
active, err := rollupClient.SequencerActive(ctx)
require.NoError(t, err)
Expand Down

0 comments on commit 02c1193

Please sign in to comment.