Skip to content

Commit

Permalink
Merge pull request #2067 from OffchainLabs/fix-liveliness-fetch
Browse files Browse the repository at this point in the history
Handle long sequencer URLs and fix fetching the list of live sequencers
  • Loading branch information
ganeshvanahalli authored Jan 11, 2024
2 parents 27d9d44 + 9dd8556 commit 4bafeaf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
22 changes: 18 additions & 4 deletions cmd/seq-coordinator-manager/seq-coordinator-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type manager struct {
livelinessSet map[string]bool
priorityList []string
nonPriorityList []string
maxURLSize int
}

func main() {
Expand All @@ -57,6 +58,9 @@ func main() {
},
prioritiesSet: make(map[string]bool),
livelinessSet: make(map[string]bool),
// maxURLSize dictates the allowed max length for sequencer urls
// urls exceeding this size will be truncated with an ellipsis
maxURLSize: 100,
}

seqManager.refreshAllLists(ctx)
Expand Down Expand Up @@ -160,11 +164,12 @@ func main() {
flex.SetDirection(tview.FlexRow).
AddItem(priorityHeading, 0, 1, false).
AddItem(tview.NewFlex().
AddItem(prioritySeqList, 0, 2, true).
// fixedSize is maxURLSize plus 20 characters to accomodate ellipsis, statuses and emojis
AddItem(prioritySeqList, seqManager.maxURLSize+20, 0, true).
AddItem(priorityForm, 0, 3, true), 0, 12, true).
AddItem(nonPriorityHeading, 0, 1, false).
AddItem(tview.NewFlex().
AddItem(nonPrioritySeqList, 0, 2, true).
AddItem(nonPrioritySeqList, seqManager.maxURLSize+20, 0, true).
AddItem(nonPriorityForm, 0, 3, true), 0, 12, true).
AddItem(instructions, 0, 3, false).SetBorder(true)

Expand Down Expand Up @@ -243,13 +248,22 @@ func (sm *manager) populateLists(ctx context.Context) {
if _, ok := sm.livelinessSet[seqURL]; ok {
status = fmt.Sprintf("(%d) %v ", index, emoji.GreenCircle)
}
prioritySeqList.AddItem(status+seqURL+sec, "", rune(0), nil).SetSecondaryTextColor(tcell.ColorPurple)
url := seqURL
if len(seqURL) > sm.maxURLSize {
url = seqURL[:sm.maxURLSize] + "..."
}
prioritySeqList.AddItem(status+url+sec, "", rune(0), nil).SetSecondaryTextColor(tcell.ColorPurple)

}

nonPrioritySeqList.Clear()
status := fmt.Sprintf("(-) %v ", emoji.GreenCircle)
for _, seqURL := range sm.nonPriorityList {
nonPrioritySeqList.AddItem(status+seqURL, "", rune(0), nil)
url := seqURL
if len(seqURL) > sm.maxURLSize {
url = seqURL[:sm.maxURLSize] + "..."
}
nonPrioritySeqList.AddItem(status+url, "", rune(0), nil)
}
}

Expand Down
16 changes: 12 additions & 4 deletions util/redisutil/redis_coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,19 @@ func (rc *RedisCoordinator) GetPriorities(ctx context.Context) ([]string, error)
return prioritiesList, nil
}

// GetLiveliness returns a map whose keys are sequencers that have their liveliness set to OK
// GetLiveliness returns a list of sequencers that have their liveliness set to OK
func (rc *RedisCoordinator) GetLiveliness(ctx context.Context) ([]string, error) {
livelinessList, _, err := rc.Client.Scan(ctx, 0, WANTS_LOCKOUT_KEY_PREFIX+"*", 0).Result()
if err != nil {
return []string{}, err
var livelinessList []string
cursor := uint64(0)
for {
keySlice, cursor, err := rc.Client.Scan(ctx, cursor, WANTS_LOCKOUT_KEY_PREFIX+"*", 0).Result()
if err != nil {
return []string{}, err
}
livelinessList = append(livelinessList, keySlice...)
if cursor == 0 {
break
}
}
for i, elem := range livelinessList {
url := strings.TrimPrefix(elem, WANTS_LOCKOUT_KEY_PREFIX)
Expand Down

0 comments on commit 4bafeaf

Please sign in to comment.