Skip to content

Commit a94b19a

Browse files
build: update to testnet4 compatible lndclient dependency
1 parent ff127d2 commit a94b19a

File tree

10 files changed

+533
-841
lines changed

10 files changed

+533
-841
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
# go needs absolute directories, using the $HOME variable doesn't work here.
1717
GOCACHE: /home/runner/work/go/pkg/build
1818
GOPATH: /home/runner/work/go
19-
GO_VERSION: 1.21.6
19+
GO_VERSION: 1.23.6
2020

2121
jobs:
2222
########################

.golangci.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
run:
22
# timeout for analysis
3-
deadline: 10m
3+
timeout: 10m
4+
5+
go: "1.23"
46

57
linters-settings:
68
govet:
@@ -20,13 +22,11 @@ linters:
2022
- asciicheck
2123
- bidichk
2224
- bodyclose
23-
- deadcode
2425
- decorder
2526
- dupl
2627
- durationcheck
2728
- errcheck
2829
- errchkjson
29-
- execinquery
3030
- exportloopref
3131
- gocritic
3232
- godot
@@ -51,12 +51,10 @@ linters:
5151
- rowserrcheck
5252
- sqlclosecheck
5353
- staticcheck
54-
- structcheck
5554
- tagliatelle
5655
- tenv
5756
- typecheck
5857
- unconvert
5958
- unparam
6059
- unused
61-
- varcheck
6260
- wastedassign

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# /Dockerfile
33
# /tools/Dockerfile
44
# /.github/workflows/main.yml
5-
FROM golang:1.21.6-alpine as builder
5+
FROM golang:1.23.6-alpine as builder
66

77
# Install build dependencies such as git and glide.
88
RUN apk add --no-cache git gcc musl-dev

collectors/log.go

+30-23
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,60 @@ package collectors
22

33
import (
44
"fmt"
5-
"io"
65
"os"
76
"path/filepath"
87

9-
"github.com/btcsuite/btclog"
10-
"github.com/jrick/logrotate/rotator"
8+
"github.com/btcsuite/btclog/v2"
119
"github.com/lightningnetwork/lnd/build"
1210
)
1311

1412
var (
15-
logWriter = &build.LogWriter{}
16-
backendLog = btclog.NewBackend(logWriter)
17-
1813
// Logger for lndmon's main process.
19-
Logger = backendLog.Logger("LNDMON")
14+
Logger btclog.Logger
2015

2116
// htlcLogger is a logger for lndmon's htlc collector.
22-
htlcLogger = build.NewSubLogger("HTLC", backendLog.Logger)
17+
htlcLogger btclog.Logger
2318

2419
// paymentLogger is a logger for lndmon's payments monitor.
25-
paymentLogger = build.NewSubLogger("PMNT", backendLog.Logger)
20+
paymentLogger btclog.Logger
21+
22+
noOpShutdownFunc = func() {}
2623
)
2724

2825
// initLogRotator initializes the logging rotator to write logs to logFile and
2926
// create roll files in the same directory. It must be called before the
3027
// package-global log rotator variables are used.
31-
func initLogRotator(logFile string, maxLogFileSize int, maxLogFiles int) error {
28+
func initLogRotator(logFile string, maxLogFileSize, maxLogFiles int) error {
3229
logDir, _ := filepath.Split(logFile)
33-
err := os.MkdirAll(logDir, 0700)
34-
if err != nil {
30+
if err := os.MkdirAll(logDir, 0700); err != nil {
3531
return fmt.Errorf("failed to create log directory: %v", err)
3632
}
3733

38-
r, err := rotator.New(
39-
logFile, int64(maxLogFileSize*1024), false, maxLogFiles,
40-
)
41-
if err != nil {
42-
return fmt.Errorf("failed to create file rotator: %v", err)
34+
// Setup the rotating log writer.
35+
logRotator := build.NewRotatingLogWriter()
36+
logCfg := build.DefaultLogConfig()
37+
logCfg.File.MaxLogFileSize = maxLogFileSize
38+
logCfg.File.MaxLogFiles = maxLogFiles
39+
logCfg.File.Compressor = build.Gzip // Optional: or build.Zstd
40+
41+
if err := logRotator.InitLogRotator(logCfg.File, logFile); err != nil {
42+
return fmt.Errorf("failed to init log rotator: %w", err)
4343
}
4444

45-
pr, pw := io.Pipe()
46-
go func() {
47-
err := r.Run(pr)
48-
fmt.Println("unable to set up logs: ", err)
49-
}()
45+
// Create the log handlers (console + rotating file).
46+
logHandlers := build.NewDefaultLogHandlers(logCfg, logRotator)
47+
48+
// Create the subsystem logger manager.
49+
logManager := build.NewSubLoggerManager(logHandlers...)
50+
51+
// Create subsystem loggers.
52+
Logger = logManager.GenSubLogger("LNDMON", noOpShutdownFunc)
53+
htlcLogger = logManager.GenSubLogger("HTLC", noOpShutdownFunc)
54+
paymentLogger = logManager.GenSubLogger("PMNT", noOpShutdownFunc)
5055

51-
logWriter.RotatorPipe = pw
56+
// Set log level.
57+
// TODO: consider making this configurable.
58+
logManager.SetLogLevels("info")
5259

5360
return nil
5461
}

collectors/wallet_collector.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
121121
}
122122

123123
var (
124-
numConf, numUnconf uint32
125-
sum, max, min btcutil.Amount
124+
numConf, numUnconf uint32
125+
sum, maxAmt, minAmt btcutil.Amount
126126
)
127127

128128
// For each UTXO, we'll count the tally of confirmed vs unconfirmed,
@@ -137,11 +137,11 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
137137
numConf++
138138
}
139139

140-
if utxo.Value > max {
141-
max = utxo.Value
140+
if utxo.Value > maxAmt {
141+
maxAmt = utxo.Value
142142
}
143-
if utxo.Value < min || min == 0 {
144-
min = utxo.Value
143+
if utxo.Value < minAmt || minAmt == 0 {
144+
minAmt = utxo.Value
145145
}
146146
}
147147

@@ -156,11 +156,11 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
156156
)
157157

158158
ch <- prometheus.MustNewConstMetric(
159-
u.minUtxoSizeDesc, prometheus.GaugeValue, float64(min),
159+
u.minUtxoSizeDesc, prometheus.GaugeValue, float64(minAmt),
160160
)
161161

162162
ch <- prometheus.MustNewConstMetric(
163-
u.maxUtxoSizeDesc, prometheus.GaugeValue, float64(max),
163+
u.maxUtxoSizeDesc, prometheus.GaugeValue, float64(maxAmt),
164164
)
165165

166166
ch <- prometheus.MustNewConstMetric(

0 commit comments

Comments
 (0)