Skip to content

Commit

Permalink
New footer, cleaner status, fast catchup support for other networks. (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
winder authored Apr 6, 2022
1 parent cd2f34e commit 961e710
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 46 deletions.
8 changes: 4 additions & 4 deletions daemon/algod/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func GetAccountStatusMsg(s *Server) tea.Cmd {
}
}

func StartFastCatchup(s *Server) tea.Cmd {
func StartFastCatchup(s *Server, network string) tea.Cmd {
return func() tea.Msg {
resp, err := http.Get("https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/testnet/latest.catchpoint")
resp, err := http.Get(fmt.Sprintf("https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/%s/latest.catchpoint", network))
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -138,9 +138,9 @@ func StartFastCatchup(s *Server) tea.Cmd {
}
}

func StopFastCatchup(s *Server) tea.Cmd {
func StopFastCatchup(s *Server, network string) tea.Cmd {
return func() tea.Msg {
resp, err := http.Get("https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/testnet/latest.catchpoint")
resp, err := http.Get(fmt.Sprintf("https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/%s/latest.catchpoint", network))
if err != nil {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions daemon/algod/tui/internal/bubbles/explorer/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (m *Model) initBlocks() {
t := table.New(blockTableHeader, 0, 0)
t.KeyMap.Up.SetKeys(append(t.KeyMap.Up.Keys(), "k")...)
t.KeyMap.Down.SetKeys(append(t.KeyMap.Down.Keys(), "j")...)
t.Styles.Title = m.style.StatusBoldText
m.table = t
m.SetSize(m.width, m.height)
m.updateBlockTable()
Expand Down
2 changes: 1 addition & 1 deletion daemon/algod/tui/internal/bubbles/explorer/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewModel(server *algod.Server, styles *style.Styles, width, widthMargin, he
width: width,
widthMargin: widthMargin,
height: height,
heightMargin: heightMargin,
heightMargin: heightMargin + 6,
}
m.initBlocks()
return m
Expand Down
1 change: 1 addition & 0 deletions daemon/algod/tui/internal/bubbles/explorer/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (m *Model) initTransactions() {
t := table.New(transactionTableHeader, 0, 0)
t.KeyMap.Up.SetKeys(append(t.KeyMap.Up.Keys(), "k")...)
t.KeyMap.Down.SetKeys(append(t.KeyMap.Down.Keys(), "j")...)
t.Styles.Title = m.style.StatusBoldText
m.table = t
m.SetSize(m.width, m.height)
m.updateTxnTable()
Expand Down
58 changes: 58 additions & 0 deletions daemon/algod/tui/internal/bubbles/footer/footer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package footer

import (
"fmt"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/daemon/algod"
"github.com/algorand/go-algorand/daemon/algod/tui/internal/style"
)

type Model struct {
width int
height int
style *style.Styles

network algod.NetworkMsg
}

func New(s *style.Styles) Model {
return Model{style: s}
}

func (m Model) Init() tea.Cmd {
return nil
}

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height

case algod.NetworkMsg:
m.network = msg
}

return m, nil
}

func (m Model) View() string {
left := m.style.FooterLeft.Render("Algorand Node UI")
right := m.style.FooterRight.Render(config.GetAlgorandVersion())
//middleText := fmt.Sprintf("%s (Gensis Hash %s)", m.network.GenesisID, m.network.GenesisHash)
middleText := fmt.Sprintf("%s", m.network.GenesisID)

middle := m.style.FooterMiddle.Copy().
Width(m.width - lipgloss.Width(left) - lipgloss.Width(right)).
Render(middleText)

return lipgloss.JoinHorizontal(lipgloss.Top,
left,
middle,
right,
)
}
82 changes: 54 additions & 28 deletions daemon/algod/tui/internal/bubbles/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@ import (

"github.com/charmbracelet/bubbles/progress"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/reflow/indent"

"github.com/algorand/go-algorand/daemon/algod"
"github.com/algorand/go-algorand/daemon/algod/tui/internal/style"
"github.com/algorand/go-algorand/node"
)

var bold = lipgloss.NewStyle().Bold(true)

type Model struct {
Status node.StatusReport
Network algod.NetworkMsg
Err error

style *style.Styles
server *algod.Server
progress progress.Model
processedAcctsPct float64
verifiedAcctsPct float64
acquiredBlksPct float64
}

func NewModel(server *algod.Server) Model {
func New(server *algod.Server, style *style.Styles) Model {
return Model{
style: style,
server: server,
progress: progress.New(progress.WithDefaultGradient()),
}
Expand All @@ -56,6 +55,8 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
m.verifiedAcctsPct = float64(m.Status.CatchpointCatchupVerifiedAccounts) / float64(m.Status.CatchpointCatchupTotalAccounts)
}
if m.Status.CatchpointCatchupTotalBlocks > 0 {
m.processedAcctsPct = 1
m.verifiedAcctsPct = 1
m.acquiredBlksPct = float64(m.Status.CatchpointCatchupAcquiredBlocks) / float64(m.Status.CatchpointCatchupTotalBlocks)
}
return m, tea.Tick(100*time.Millisecond, func(time.Time) tea.Msg {
Expand Down Expand Up @@ -89,41 +90,66 @@ func formatNextVersion(last, next string, round uint64) string {
return strconv.FormatUint(round, 10)
}

func writeProgress(b *strings.Builder, prefix string, progress progress.Model, pct float64) {
b.WriteString(prefix)
b.WriteString(progress.ViewAs(pct))
b.WriteString("\n")
}

func (m Model) View() string {
bold := m.style.StatusBoldText
key := m.style.BottomListItemKey.Copy().MarginLeft(0)
builder := strings.Builder{}

// general information
builder.WriteString(fmt.Sprintf("%s - %s\n", bold.Render("Network"), m.Network.GenesisID))
builder.WriteString(fmt.Sprintf("%s - %s\n", bold.Render("Genesis Hash"), m.Network.GenesisHash.String()))

builder.WriteString(fmt.Sprintf("%s %s\n", bold.Render("Network:"), m.Network.GenesisID))
builder.WriteString(fmt.Sprintf("%s %s\n", bold.Render("Genesis:"), m.Network.GenesisHash))
// status
if (m.Status != node.StatusReport{}) {
nextVersion := formatNextVersion(
string(m.Status.LastVersion),
string(m.Status.NextVersion),
uint64(m.Status.NextVersionRound))
report := strings.Builder{}
report.WriteString(fmt.Sprintf("%s\n------------- \n", bold.Render("Status Report")))
report.WriteString(fmt.Sprintf("Last committed block: %d\n", m.Status.LastRound))
report.WriteString(fmt.Sprintf("Time since last block: %s\n", m.Status.TimeSinceLastRound()))
report.WriteString(fmt.Sprintf("Sync time: %s\n", m.Status.SynchronizingTime))
report.WriteString(fmt.Sprintf("Last consensus protocol: %s\n", formatVersion(string(m.Status.LastVersion))))
report.WriteString(fmt.Sprintf("Next consensus protocol: %s\n", formatVersion(string(m.Status.NextVersion))))
report.WriteString(fmt.Sprintf("Next upgrade round: %s\n", nextVersion))
report.WriteString(fmt.Sprintf("Next protocol supported: %t\n", m.Status.NextVersionSupported))

if m.Status.Catchpoint != "" {
report.WriteString(fmt.Sprintf("Catchpoint: %s\n", m.Status.Catchpoint))
report.WriteString("Catchpoint processed accounts: ")
report.WriteString(m.progress.ViewAs(m.processedAcctsPct))
report.WriteString("\nCatchpoint verified accounts: ")
report.WriteString(m.progress.ViewAs(m.verifiedAcctsPct))
report.WriteString("\nCatchpoint acquired block: ")
report.WriteString(m.progress.ViewAs(m.acquiredBlksPct))

switch {
case m.Status.Catchpoint != "":
// Catchpoint view
report.WriteString(fmt.Sprintf("Catchpoint: %s\n\n", m.Status.Catchpoint))
var catchupStatus string
switch {
case m.Status.CatchpointCatchupAcquiredBlocks > 0:
catchupStatus = fmt.Sprintf("Verifying accounts: %d / %d\n", m.Status.CatchpointCatchupAcquiredBlocks, m.Status.CatchpointCatchupTotalBlocks)
case m.Status.CatchpointCatchupVerifiedAccounts > 0:
catchupStatus = fmt.Sprintf("Verifying accounts: %d / %d\n", m.Status.CatchpointCatchupVerifiedAccounts, m.Status.CatchpointCatchupTotalAccounts)
case m.Status.CatchpointCatchupProcessedAccounts > 0:
catchupStatus = fmt.Sprintf("Downloading accounts: %d / %d\n", m.Status.CatchpointCatchupProcessedAccounts, m.Status.CatchpointCatchupTotalAccounts)
}
report.WriteString(bold.Render(catchupStatus))
report.WriteString("\n")
writeProgress(&report, "Downloading accounts: ", m.progress, m.processedAcctsPct)
writeProgress(&report, "Processing accounts: ", m.progress, m.verifiedAcctsPct)
writeProgress(&report, "Downloading blocks: ", m.progress, m.acquiredBlksPct)
default:
report.WriteString(fmt.Sprintf("Current round: %s\n", key.Render(strconv.FormatUint(uint64(m.Status.LastRound), 10))))
report.WriteString(fmt.Sprintf("Block wait time: %s\n", m.Status.TimeSinceLastRound()))
report.WriteString(fmt.Sprintf("Sync time: %s\n", m.Status.SynchronizingTime))
// TODO: Display consensus upgrade progress
if m.Status.LastVersion == m.Status.NextVersion {
// no upgrade in progress
report.WriteString(fmt.Sprintf("Protocol: %s\n", formatVersion(string(m.Status.LastVersion))))
report.WriteString(fmt.Sprintf(" %s\n", bold.Render("No upgrade in progress.")))
} else {
// upgrade in progress
report.WriteString(fmt.Sprintf("%s\n", bold.Render("Consensus Upgrade Pending")))
report.WriteString(fmt.Sprintf("Current Protocol: %s\n", formatVersion(string(m.Status.LastVersion))))
report.WriteString(fmt.Sprintf("Next Protocol: %s\n", formatVersion(string(m.Status.NextVersion))))
report.WriteString(fmt.Sprintf("Upgrade round: %s\n", nextVersion))

}
}

builder.WriteString(indent.String(report.String(), 4))
builder.WriteString(report.String())
}

return builder.String()
return m.style.Status.Render(builder.String())
}
3 changes: 2 additions & 1 deletion daemon/algod/tui/internal/model/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ func (m Model) Init() tea.Cmd {
tea.EnterAltScreen,
m.Status.Init(),
m.Accounts.Init(),
m.BlockExplorer.Init())
m.BlockExplorer.Init(),
m.Footer.Init())
}
9 changes: 7 additions & 2 deletions daemon/algod/tui/internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"github.com/algorand/go-algorand/daemon/algod"
"github.com/algorand/go-algorand/daemon/algod/tui/internal/bubbles/accounts"
"github.com/algorand/go-algorand/daemon/algod/tui/internal/bubbles/explorer"
"github.com/algorand/go-algorand/daemon/algod/tui/internal/bubbles/footer"
"github.com/algorand/go-algorand/daemon/algod/tui/internal/bubbles/status"
"github.com/algorand/go-algorand/daemon/algod/tui/internal/style"
)

const (
// MaxTopBoxHeight is the height of the top boxes. Hard coded to avoid dynamic margins.
MaxTopBoxHeight = 20
MaxTopBoxHeight = style.TopHeight
initialWidth = 80
initialHeight = 50
)
Expand All @@ -24,6 +25,9 @@ type Model struct {
Accounts accounts.Model
BlockExplorer explorer.Model
Help help.Model
Footer footer.Model

network algod.NetworkMsg

styles *style.Styles

Expand All @@ -36,9 +40,10 @@ func New(s *algod.Server) Model {
return Model{
Server: s,
styles: styles,
Status: status.NewModel(s),
Status: status.New(s, styles),
BlockExplorer: explorer.NewModel(s, styles, initialWidth, 0, initialHeight, MaxTopBoxHeight /* Max(status.height, account.height) */),
Accounts: accounts.NewModel(s),
Help: help.New(),
Footer: footer.New(styles),
}
}
19 changes: 15 additions & 4 deletions daemon/algod/tui/internal/model/update.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package model

import (
"github.com/algorand/go-algorand/daemon/algod"
"strings"

"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"

"github.com/algorand/go-algorand/daemon/algod"
"github.com/algorand/go-algorand/daemon/algod/tui/internal/constants"
)

func networkFromID(genesisID string) string {
return strings.Split(genesisID, "-")[0]
}

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case algod.NetworkMsg:
m.network = msg
case tea.KeyMsg:
switch {
case key.Matches(msg, constants.Keys.Quit):
return m, tea.Quit
case key.Matches(msg, constants.Keys.Catchup):
return m, algod.StartFastCatchup(m.Server)
return m, algod.StartFastCatchup(m.Server, networkFromID(m.Status.Network.GenesisID))
case key.Matches(msg, constants.Keys.AbortCatchup):
return m, algod.StopFastCatchup(m.Server)
return m, algod.StopFastCatchup(m.Server, networkFromID(m.Status.Network.GenesisID))
}

case tea.WindowSizeMsg:
Expand All @@ -33,5 +41,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var explorerCommand tea.Cmd
m.BlockExplorer, explorerCommand = m.BlockExplorer.Update(msg)

return m, tea.Batch(statusCommand, accountsCommand, explorerCommand)
var footerCommand tea.Cmd
m.Footer, footerCommand = m.Footer.Update(msg)

return m, tea.Batch(statusCommand, accountsCommand, explorerCommand, footerCommand)
}
3 changes: 2 additions & 1 deletion daemon/algod/tui/internal/model/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ func (m Model) View() string {
m.Status.View(),
m.Accounts.View()),
m.BlockExplorer.View(),
m.Help.View(constants.Keys))
m.Help.View(constants.Keys),
m.Footer.View())
}
Loading

0 comments on commit 961e710

Please sign in to comment.