Skip to content

Commit 12f6323

Browse files
authored
fix(dvb): remove dead code and fix -f flag showing no output (#90)
Remove dead looksLikeNodeIdentifier (references removed parseNodeIndex), remove freshness threshold in runtime/logs.go that suppressed initial tail lines when log file wasn't recently modified.
1 parent b1c9104 commit 12f6323

3 files changed

Lines changed: 4 additions & 56 deletions

File tree

cmd/dvb/logs.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -503,20 +503,6 @@ func tailLines(file *os.File, n int) ([]string, error) {
503503
return lines, nil
504504
}
505505

506-
// looksLikeNodeIdentifier returns true if the string looks like a node identifier.
507-
// Node identifiers are: pure numeric (0, 1, 2) or "validator-N" / "node-N" patterns.
508-
func looksLikeNodeIdentifier(s string) bool {
509-
// Pure numeric
510-
if _, err := parseNodeIndex(s); err == nil {
511-
return true
512-
}
513-
// Common node name patterns
514-
if strings.HasPrefix(s, "validator-") || strings.HasPrefix(s, "node-") || strings.HasPrefix(s, "full-") {
515-
return true
516-
}
517-
return false
518-
}
519-
520506
// nodeLogStreamer streams logs from the daemon for a specific node.
521507
type nodeLogStreamer interface {
522508
StreamNodeLogs(ctx context.Context, devnetName string, index int, follow bool, since string, tail int, callback func(*client.LogEntry) error) error

cmd/dvb/logs_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,6 @@ func TestIsPathWithinBase(t *testing.T) {
9393
}
9494
}
9595

96-
func TestLooksLikeNodeIdentifier(t *testing.T) {
97-
tests := []struct {
98-
input string
99-
want bool
100-
}{
101-
{"0", true},
102-
{"5", true},
103-
{"validator-0", true},
104-
{"node-1", true},
105-
{"full-3", true},
106-
{"my-devnet", false},
107-
{"cosmos", false},
108-
{"mainnet", false},
109-
}
110-
for _, tt := range tests {
111-
t.Run(tt.input, func(t *testing.T) {
112-
if got := looksLikeNodeIdentifier(tt.input); got != tt.want {
113-
t.Errorf("looksLikeNodeIdentifier(%q) = %v, want %v", tt.input, got, tt.want)
114-
}
115-
})
116-
}
117-
}
118-
11996
func TestGetNodeColor(t *testing.T) {
12097
// Same input should always return same color (deterministic)
12198
c1 := getNodeColor("validator-0")

internal/daemon/runtime/logs.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"sort"
1313
"strings"
1414
"sync"
15-
"time"
1615

1716
"github.com/nxadm/tail"
1817
)
@@ -101,24 +100,10 @@ func (lm *LogManager) followFile(ctx context.Context, logPath string, lines int)
101100
// The tail package doesn't support "last N lines" directly - Location is for byte offset.
102101
var initialContent io.ReadCloser
103102
if lines > 0 {
104-
// Check if file has been recently modified (within last 2 seconds).
105-
// If not, the content is likely stale (e.g., from before a node restart),
106-
// so we skip showing initial content and just follow for new logs.
107-
const freshnessThreshold = 2 * time.Second
108-
showInitialContent := true
109-
if info, err := os.Stat(logPath); err == nil {
110-
if time.Since(info.ModTime()) > freshnessThreshold {
111-
showInitialContent = false
112-
}
113-
}
114-
115-
if showInitialContent {
116-
// Read the last N lines first
117-
var err error
118-
initialContent, err = lm.tailFile(logPath, lines)
119-
if err != nil {
120-
return nil, fmt.Errorf("failed to read initial lines: %w", err)
121-
}
103+
var err error
104+
initialContent, err = lm.tailFile(logPath, lines)
105+
if err != nil {
106+
return nil, fmt.Errorf("failed to read initial lines: %w", err)
122107
}
123108
}
124109

0 commit comments

Comments
 (0)