Commit 449321bd authored by Adrian Sutton's avatar Adrian Sutton

op-node: Notify sequencer state listener when starting and stopping sequencer

parent d252ea2b
......@@ -199,7 +199,7 @@ func (n *OpNode) initL2(ctx context.Context, cfg *Config, snapshotLog log.Logger
return err
}
n.l2Driver = driver.NewDriver(&cfg.Driver, &cfg.Rollup, n.l2Source, n.l1Source, n, n, n.log, snapshotLog, n.metrics)
n.l2Driver = driver.NewDriver(&cfg.Driver, &cfg.Rollup, n.l2Source, n.l1Source, n, n, n.log, snapshotLog, n.metrics, DisabledConfigPersistence{})
return nil
}
......
......@@ -102,8 +102,13 @@ type AltSync interface {
RequestL2Range(ctx context.Context, start, end eth.L2BlockRef) error
}
type SequencerStateListener interface {
SequencerStarted() error
SequencerStopped() error
}
// NewDriver composes an events handler that tracks L1 state, triggers L2 derivation, and optionally sequences new L2 blocks.
func NewDriver(driverCfg *Config, cfg *rollup.Config, l2 L2Chain, l1 L1Chain, altSync AltSync, network Network, log log.Logger, snapshotLog log.Logger, metrics Metrics) *Driver {
func NewDriver(driverCfg *Config, cfg *rollup.Config, l2 L2Chain, l1 L1Chain, altSync AltSync, network Network, log log.Logger, snapshotLog log.Logger, metrics Metrics, sequencerStateListener SequencerStateListener) *Driver {
l1 = NewMeteredL1Fetcher(l1, metrics)
l1State := NewL1State(log, metrics)
sequencerConfDepth := NewConfDepth(driverCfg.SequencerConfDepth, l1State.L1Head, l1)
......@@ -122,6 +127,7 @@ func NewDriver(driverCfg *Config, cfg *rollup.Config, l2 L2Chain, l1 L1Chain, al
forceReset: make(chan chan struct{}, 10),
startSequencer: make(chan hashAndErrorChannel, 10),
stopSequencer: make(chan chan hashAndError, 10),
sequencerNotifs: sequencerStateListener,
config: cfg,
driverConfig: driverCfg,
done: make(chan struct{}),
......
......@@ -47,6 +47,9 @@ type Driver struct {
// It tells the caller that the sequencer stopped by returning the latest sequenced L2 block hash.
stopSequencer chan chan hashAndError
// sequencerNotifs is notified when the sequencer is started or stopped
sequencerNotifs SequencerStateListener
// Rollup config: rollup chain configuration
config *rollup.Config
......@@ -334,6 +337,10 @@ func (s *Driver) eventLoop() {
} else if !bytes.Equal(unsafeHead[:], resp.hash[:]) {
resp.err <- fmt.Errorf("block hash does not match: head %s, received %s", unsafeHead.String(), resp.hash.String())
} else {
if err := s.sequencerNotifs.SequencerStarted(); err != nil {
resp.err <- fmt.Errorf("sequencer start notification: %w", err)
continue
}
s.log.Info("Sequencer has been started")
s.driverConfig.SequencerStopped = false
close(resp.err)
......@@ -343,6 +350,10 @@ func (s *Driver) eventLoop() {
if s.driverConfig.SequencerStopped {
respCh <- hashAndError{err: errors.New("sequencer not running")}
} else {
if err := s.sequencerNotifs.SequencerStopped(); err != nil {
respCh <- hashAndError{err: fmt.Errorf("sequencer start notification: %w", err)}
continue
}
s.log.Warn("Sequencer has been stopped")
s.driverConfig.SequencerStopped = true
respCh <- hashAndError{hash: s.derivation.UnsafeL2Head().Hash}
......
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