Skip to content

Commit

Permalink
handling empty next proposer case
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin committed Aug 14, 2024
1 parent 135d672 commit e1a5140
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ func (m *Manager) Start(ctx context.Context) error {
return fmt.Errorf("sync block manager from settlement: %w", err)
}
// check if sequencer in the middle of rotation
nextSeqAddr, err := m.MissingLastBatch()
nextSeqAddr, missing, err := m.MissingLastBatch()
if err != nil {
return fmt.Errorf("missing last batch: %w", err)
return fmt.Errorf("checking if missing last batch: %w", err)
}
// if sequencer is in the middle of rotation, complete rotation instead of running the main loop
if nextSeqAddr != "" {
if missing {
m.handleRotationReq(ctx, nextSeqAddr)
return nil
}
Expand Down
15 changes: 6 additions & 9 deletions block/sequencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func (m *Manager) MonitorSequencerRotation(ctx context.Context, rotateC chan str
// for this case, the old proposer counts as "sequencer" as well, so he'll be able to submit the last state update.
func (m *Manager) IsProposer() bool {
localProposerKey, _ := m.LocalKey.GetPublic().Raw()

l2Proposer := m.GetProposerPubKey().Bytes()

var expectedHubProposer []byte
Expand All @@ -70,22 +69,20 @@ func (m *Manager) IsProposer() bool {
}

// check rotation in progress (I'm the proposer, but needs to complete rotation)
func (m *Manager) MissingLastBatch() (string, error) {
func (m *Manager) MissingLastBatch() (string, bool, error) {
localProposerKey, _ := m.LocalKey.GetPublic().Raw()
next, err := m.SLClient.CheckRotationInProgress()
if err != nil {
return "", err
return "", false, err
}
if next == nil {
return "", nil
return "", false, nil
}
// rotation in progress,
// check if we're the old proposer and needs to complete rotation
if !bytes.Equal(next.PublicKey.Bytes(), localProposerKey) {
return next.Address, nil
}

return "", nil
curr := m.SLClient.GetProposer()
isProposer := bytes.Equal(curr.PublicKey.Bytes(), localProposerKey)
return next.Address, isProposer, nil
}

// handleRotationReq completes the rotation flow once a signal is received from the SL
Expand Down
2 changes: 1 addition & 1 deletion types/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *SequencerSet) SetProposer(proposer *types.Validator) {
s.ProposerHash = GetHash(proposer)

// Add proposer to bonded set if not already present
if !s.HasAddress(proposer.Address) {
if proposer != nil && !s.HasAddress(proposer.Address) {
s.Sequencers = append(s.Sequencers, proposer)
}
}
Expand Down

0 comments on commit e1a5140

Please sign in to comment.