Skip to content

Commit

Permalink
feat: add fast-catchup state to status
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Jan 2, 2025
1 parent 4c75760 commit e781e42
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
9 changes: 8 additions & 1 deletion internal/algod/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,18 @@ func (s *StateModel) Watch(cb func(model *StateModel, err error), ctx context.Co
}
// Abort on Fast-Catchup
if s.Status.State == FastCatchupState {
time.Sleep(time.Second * 10)
// Update current render
cb(s, nil)
// Wait for a while
time.Sleep(time.Second * 2)
// Check status
s.Status, _, err = s.Status.Get(ctx)
// Report errors
if err != nil {
cb(nil, err)
}
// Update render after status fetch
cb(s, nil)
continue
}

Expand Down
18 changes: 17 additions & 1 deletion internal/algod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ type Status struct {
LastRound uint64 `json:"lastRound"`

// Catchpoint is a pointer to a string that identifies the current catchpoint for node synchronization or fast catchup.
Catchpoint *string `json:"catchpoint"`
Catchpoint *string `json:"catchpoint"`
CatchpointAccountsTotal int `json:"catchpointAccountsTotal"`
CatchpointAccountsProcessed int `json:"catchpointAccountsProcessed"`
CatchpointAccountsVerified int `json:"catchpointAccountsVerified"`
CatchpointKeyValueTotal int `json:"catchpointKeyValueTotal"`
CatchpointKeyValueProcessed int `json:"catchpointKeyValueProcessed"`
CatchpointKeyValueVerified int `json:"catchpointKeyValueVerified"`

SyncTime int `json:"syncTime"`

// Client provides methods for interacting with the API, adhering to ClientWithResponsesInterface specifications.
Client api.ClientWithResponsesInterface `json:"-"`
Expand Down Expand Up @@ -100,7 +108,15 @@ func (s Status) Merge(res api.StatusLike) Status {
if catchpoint != nil && *catchpoint != "" {
s.State = FastCatchupState
s.Catchpoint = catchpoint
s.SyncTime = res.CatchupTime
s.CatchpointAccountsTotal = *res.CatchpointTotalAccounts
s.CatchpointAccountsProcessed = *res.CatchpointProcessedAccounts
s.CatchpointAccountsVerified = *res.CatchpointVerifiedAccounts
s.CatchpointKeyValueTotal = *res.CatchpointTotalKvs
s.CatchpointKeyValueProcessed = *res.CatchpointProcessedKvs
s.CatchpointKeyValueVerified = *res.CatchpointVerifiedKvs
} else if res.CatchupTime > 0 {
s.SyncTime = res.CatchupTime
s.State = SyncingState
} else {
s.State = StableState
Expand Down
23 changes: 21 additions & 2 deletions ui/modal/controller.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package modal

import (
"fmt"
"github.com/algorandfoundation/algorun-tui/internal/algod"
"github.com/algorandfoundation/algorun-tui/internal/algod/participation"
"github.com/algorandfoundation/algorun-tui/ui/app"
"github.com/algorandfoundation/algorun-tui/ui/modals/generate"
"github.com/algorandfoundation/algorun-tui/ui/style"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"time"
)

// Init initializes the current ViewModel by batching initialization commands for all associated modal ViewModels.
Expand Down Expand Up @@ -41,8 +43,25 @@ func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {
m.transactionModal.State = msg
m.infoModal.State = msg

// When the state changes, and we are displaying a valid QR Code/Transaction Modal
if m.Type == app.TransactionModal && m.transactionModal.Participation != nil {
if m.State.Status.State == algod.FastCatchupState {
m.Open = true
m.SetType(app.ExceptionModal)
m.exceptionModal.Message = style.LightBlue(lipgloss.JoinVertical(lipgloss.Top,
fmt.Sprintf("Last committed block: %d", m.State.Status.LastRound),
fmt.Sprintf("Sync Time: %ds", m.State.Status.SyncTime/int(time.Second)),
fmt.Sprintf("Catchpoint: %s", *m.State.Status.Catchpoint),
fmt.Sprintf("Total Accounts: %d", m.State.Status.CatchpointAccountsTotal),
fmt.Sprintf("Accounts Processed: %d", m.State.Status.CatchpointAccountsProcessed),
fmt.Sprintf("Accounts Verified: %d", m.State.Status.CatchpointAccountsVerified),
fmt.Sprintf("Total Key Values: %d", m.State.Status.CatchpointKeyValueTotal),
fmt.Sprintf("Key Values Processed: %d", m.State.Status.CatchpointKeyValueProcessed),
fmt.Sprintf("Key Values Verified: %d", m.State.Status.CatchpointKeyValueVerified),
))
m.borderColor = "7"
m.controls = ""
m.title = "Fast Catchup"

} else if m.Type == app.TransactionModal && m.transactionModal.Participation != nil {
acct, ok := msg.Accounts[m.Address]
// If the previous state is not active
if ok {
Expand Down

0 comments on commit e781e42

Please sign in to comment.