Skip to content

Commit

Permalink
[op-conductor] resume logic improvement (ethereum-optimism#9197)
Browse files Browse the repository at this point in the history
* Add conductor transition diagram

* Update sequencer active status upon resume
  • Loading branch information
0x00101010 authored Jan 26, 2024
1 parent 640b4cb commit 288ada2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
8 changes: 8 additions & 0 deletions op-conductor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ On a high level, op-conductor serves the following functions:
3. monitor sequencer (op-node) health
4. control loop => control sequencer (op-node) status (start / stop) based on different scenarios

### Conductor State Transition

![conductor state transition](./assets/op-conductor-state-transition.svg)

Helpful tips:
To better understand the graph, focus on one node at a time, understand what can be transitioned to this current state and how it can transition to other states.
This way you could understand how we handle the state transitions.

This is initial version of README, more details will be added later.
1 change: 1 addition & 0 deletions op-conductor/assets/op-conductor-state-transition.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 15 additions & 7 deletions op-conductor/conductor/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,7 @@ func (c *OpConductor) initSequencerControl(ctx context.Context) error {
node := sources.NewRollupClient(nc)
c.ctrl = client.NewSequencerControl(exec, node)

active, err := c.ctrl.SequencerActive(ctx)
if err != nil {
return errors.Wrap(err, "failed to get sequencer active status")
}
c.seqActive.Store(active)

return nil
return c.updateSequencerActiveStatus()
}

func (c *OpConductor) initConsensus(ctx context.Context) error {
Expand Down Expand Up @@ -358,6 +352,11 @@ func (oc *OpConductor) Pause(ctx context.Context) error {

// Resume resumes the control loop of OpConductor.
func (oc *OpConductor) Resume(ctx context.Context) error {
err := oc.updateSequencerActiveStatus()
if err != nil {
return errors.Wrap(err, "cannot resume because failed to get sequencer active status")
}

select {
case oc.resumeCh <- struct{}{}:
<-oc.resumeDoneCh
Expand Down Expand Up @@ -612,3 +611,12 @@ func (oc *OpConductor) startSequencer() error {
oc.seqActive.Store(true)
return nil
}

func (oc *OpConductor) updateSequencerActiveStatus() error {
active, err := oc.ctrl.SequencerActive(oc.shutdownCtx)
if err != nil {
return errors.Wrap(err, "failed to get sequencer active status")
}
oc.seqActive.Store(active)
return nil
}
2 changes: 2 additions & 0 deletions op-conductor/conductor/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func (s *OpConductorTestSuite) TestControlLoop1() {
s.healthUpdateCh <- true

// Resume
s.ctrl.EXPECT().SequencerActive(mock.Anything).Return(false, nil)
err = s.conductor.Resume(s.ctx)
s.NoError(err)
s.False(s.conductor.Paused())
Expand All @@ -200,6 +201,7 @@ func (s *OpConductorTestSuite) TestControlLoop2() {
s.True(s.conductor.Paused())

// Resume
s.ctrl.EXPECT().SequencerActive(mock.Anything).Return(false, nil)
err = s.conductor.Resume(s.ctx)
s.NoError(err)
s.False(s.conductor.Paused())
Expand Down

0 comments on commit 288ada2

Please sign in to comment.