Commit bbebb76e authored by Michael de Hoog's avatar Michael de Hoog

Add sequencer.stopped flag that can be used to start a node in sequencer mode...

Add sequencer.stopped flag that can be used to start a node in sequencer mode that doesn't produce blocks
parent 57a89fbb
...@@ -94,6 +94,11 @@ var ( ...@@ -94,6 +94,11 @@ var (
Usage: "Enable sequencing of new L2 blocks. A separate batch submitter has to be deployed to publish the data for verifiers.", Usage: "Enable sequencing of new L2 blocks. A separate batch submitter has to be deployed to publish the data for verifiers.",
EnvVar: prefixEnvVar("SEQUENCER_ENABLED"), EnvVar: prefixEnvVar("SEQUENCER_ENABLED"),
} }
SequencerStoppedFlag = cli.BoolFlag{
Name: "sequencer.stopped",
Usage: "Initialize the sequencer in a stopped state. The sequencer can be started using the admin_startSequencer RPC",
EnvVar: prefixEnvVar("SEQUENCER_STOPPED"),
}
SequencerL1Confs = cli.Uint64Flag{ SequencerL1Confs = cli.Uint64Flag{
Name: "sequencer.l1-confs", Name: "sequencer.l1-confs",
Usage: "Number of L1 blocks to keep distance from the L1 head as a sequencer for picking an L1 origin.", Usage: "Number of L1 blocks to keep distance from the L1 head as a sequencer for picking an L1 origin.",
...@@ -197,6 +202,7 @@ var optionalFlags = append([]cli.Flag{ ...@@ -197,6 +202,7 @@ var optionalFlags = append([]cli.Flag{
L2EngineJWTSecret, L2EngineJWTSecret,
VerifierL1Confs, VerifierL1Confs,
SequencerEnabledFlag, SequencerEnabledFlag,
SequencerStoppedFlag,
SequencerL1Confs, SequencerL1Confs,
L1EpochPollIntervalFlag, L1EpochPollIntervalFlag,
LogLevelFlag, LogLevelFlag,
......
...@@ -13,4 +13,7 @@ type Config struct { ...@@ -13,4 +13,7 @@ type Config struct {
// SequencerEnabled is true when the driver should sequence new blocks. // SequencerEnabled is true when the driver should sequence new blocks.
SequencerEnabled bool `json:"sequencer_enabled"` SequencerEnabled bool `json:"sequencer_enabled"`
// SequencerStopped is false when the driver should sequence new blocks.
SequencerStopped bool `json:"sequencer_stopped"`
} }
...@@ -284,7 +284,7 @@ func (s *Driver) eventLoop() { ...@@ -284,7 +284,7 @@ func (s *Driver) eventLoop() {
for { for {
// If we are sequencing, update the trigger for the next sequencer action. // If we are sequencing, update the trigger for the next sequencer action.
// This may adjust at any time based on fork-choice changes or previous errors. // This may adjust at any time based on fork-choice changes or previous errors.
if s.driverConfig.SequencerEnabled { if s.driverConfig.SequencerEnabled && !s.driverConfig.SequencerStopped {
// update sequencer time if the head changed // update sequencer time if the head changed
if sequencingPlannedOnto != s.derivation.UnsafeL2Head().ID() { if sequencingPlannedOnto != s.derivation.UnsafeL2Head().ID() {
planSequencerAction() planSequencerAction()
...@@ -379,22 +379,22 @@ func (s *Driver) eventLoop() { ...@@ -379,22 +379,22 @@ func (s *Driver) eventLoop() {
close(respCh) close(respCh)
case resp := <-s.startSequencer: case resp := <-s.startSequencer:
unsafeHead := s.derivation.UnsafeL2Head().Hash unsafeHead := s.derivation.UnsafeL2Head().Hash
if s.driverConfig.SequencerEnabled { if !s.driverConfig.SequencerStopped {
resp.err <- errors.New("sequencer already running") resp.err <- errors.New("sequencer already running")
} else if !bytes.Equal(unsafeHead[:], resp.hash[:]) { } 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()) resp.err <- fmt.Errorf("block hash does not match: head %s, received %s", unsafeHead.String(), resp.hash.String())
} else { } else {
s.log.Info("Sequencer has been started") s.log.Info("Sequencer has been started")
s.driverConfig.SequencerEnabled = true s.driverConfig.SequencerStopped = false
sequencingPlannedOnto = eth.BlockID{} sequencingPlannedOnto = eth.BlockID{}
close(resp.err) close(resp.err)
} }
case respCh := <-s.stopSequencer: case respCh := <-s.stopSequencer:
if !s.driverConfig.SequencerEnabled { if s.driverConfig.SequencerStopped {
respCh <- hashAndError{err: errors.New("sequencer not running")} respCh <- hashAndError{err: errors.New("sequencer not running")}
} else { } else {
s.log.Warn("Sequencer has been stopped") s.log.Warn("Sequencer has been stopped")
s.driverConfig.SequencerEnabled = false s.driverConfig.SequencerStopped = true
respCh <- hashAndError{hash: s.derivation.UnsafeL2Head().Hash} respCh <- hashAndError{hash: s.derivation.UnsafeL2Head().Hash}
} }
case <-s.done: case <-s.done:
...@@ -422,6 +422,9 @@ func (s *Driver) ResetDerivationPipeline(ctx context.Context) error { ...@@ -422,6 +422,9 @@ func (s *Driver) ResetDerivationPipeline(ctx context.Context) error {
} }
func (s *Driver) StartSequencer(ctx context.Context, blockHash common.Hash) error { func (s *Driver) StartSequencer(ctx context.Context, blockHash common.Hash) error {
if !s.driverConfig.SequencerEnabled {
return errors.New("sequencer is not enabled")
}
h := hashAndErrorChannel{ h := hashAndErrorChannel{
hash: blockHash, hash: blockHash,
err: make(chan error, 1), err: make(chan error, 1),
...@@ -440,6 +443,9 @@ func (s *Driver) StartSequencer(ctx context.Context, blockHash common.Hash) erro ...@@ -440,6 +443,9 @@ func (s *Driver) StartSequencer(ctx context.Context, blockHash common.Hash) erro
} }
func (s *Driver) StopSequencer(ctx context.Context) (common.Hash, error) { func (s *Driver) StopSequencer(ctx context.Context) (common.Hash, error) {
if !s.driverConfig.SequencerEnabled {
return common.Hash{}, errors.New("sequencer is not enabled")
}
respCh := make(chan hashAndError, 1) respCh := make(chan hashAndError, 1)
select { select {
case <-ctx.Done(): case <-ctx.Done():
......
...@@ -138,6 +138,7 @@ func NewDriverConfig(ctx *cli.Context) (*driver.Config, error) { ...@@ -138,6 +138,7 @@ func NewDriverConfig(ctx *cli.Context) (*driver.Config, error) {
VerifierConfDepth: ctx.GlobalUint64(flags.VerifierL1Confs.Name), VerifierConfDepth: ctx.GlobalUint64(flags.VerifierL1Confs.Name),
SequencerConfDepth: ctx.GlobalUint64(flags.SequencerL1Confs.Name), SequencerConfDepth: ctx.GlobalUint64(flags.SequencerL1Confs.Name),
SequencerEnabled: ctx.GlobalBool(flags.SequencerEnabledFlag.Name), SequencerEnabled: ctx.GlobalBool(flags.SequencerEnabledFlag.Name),
SequencerStopped: ctx.GlobalBool(flags.SequencerStoppedFlag.Name),
}, nil }, nil
} }
......
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