Skip to content

config: add support for testnet4 #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
# go needs absolute directories, using the $HOME variable doesn't work here.
GOCACHE: /home/runner/work/go/pkg/build
GOPATH: /home/runner/work/go
GO_VERSION: 1.21.6
GO_VERSION: 1.23.6

jobs:
########################
Expand Down
8 changes: 3 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
run:
# timeout for analysis
deadline: 10m
timeout: 10m

go: "1.23"

linters-settings:
govet:
Expand All @@ -20,13 +22,11 @@ linters:
- asciicheck
- bidichk
- bodyclose
- deadcode
- decorder
- dupl
- durationcheck
- errcheck
- errchkjson
- execinquery
- exportloopref
- gocritic
- godot
Expand All @@ -51,12 +51,10 @@ linters:
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
- tagliatelle
- tenv
- typecheck
- unconvert
- unparam
- unused
- varcheck
- wastedassign
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# /Dockerfile
# /tools/Dockerfile
# /.github/workflows/main.yml
FROM golang:1.21.6-alpine as builder
FROM golang:1.23.6-alpine as builder

# Install build dependencies such as git and glide.
RUN apk add --no-cache git gcc musl-dev
Expand Down
53 changes: 30 additions & 23 deletions collectors/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,60 @@ package collectors

import (
"fmt"
"io"
"os"
"path/filepath"

"github.com/btcsuite/btclog"
"github.com/jrick/logrotate/rotator"
"github.com/btcsuite/btclog/v2"
"github.com/lightningnetwork/lnd/build"
)

var (
logWriter = &build.LogWriter{}
backendLog = btclog.NewBackend(logWriter)

// Logger for lndmon's main process.
Logger = backendLog.Logger("LNDMON")
Logger btclog.Logger

// htlcLogger is a logger for lndmon's htlc collector.
htlcLogger = build.NewSubLogger("HTLC", backendLog.Logger)
htlcLogger btclog.Logger

// paymentLogger is a logger for lndmon's payments monitor.
paymentLogger = build.NewSubLogger("PMNT", backendLog.Logger)
paymentLogger btclog.Logger

noOpShutdownFunc = func() {}
)

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

r, err := rotator.New(
logFile, int64(maxLogFileSize*1024), false, maxLogFiles,
)
if err != nil {
return fmt.Errorf("failed to create file rotator: %v", err)
// Setup the rotating log writer.
logRotator := build.NewRotatingLogWriter()
logCfg := build.DefaultLogConfig()
logCfg.File.MaxLogFileSize = maxLogFileSize
logCfg.File.MaxLogFiles = maxLogFiles
logCfg.File.Compressor = build.Gzip // Optional: or build.Zstd

if err := logRotator.InitLogRotator(logCfg.File, logFile); err != nil {
return fmt.Errorf("failed to init log rotator: %w", err)
}

pr, pw := io.Pipe()
go func() {
err := r.Run(pr)
fmt.Println("unable to set up logs: ", err)
}()
// Create the log handlers (console + rotating file).
logHandlers := build.NewDefaultLogHandlers(logCfg, logRotator)

// Create the subsystem logger manager.
logManager := build.NewSubLoggerManager(logHandlers...)

// Create subsystem loggers.
Logger = logManager.GenSubLogger("LNDMON", noOpShutdownFunc)
htlcLogger = logManager.GenSubLogger("HTLC", noOpShutdownFunc)
paymentLogger = logManager.GenSubLogger("PMNT", noOpShutdownFunc)

logWriter.RotatorPipe = pw
// Set log level.
// TODO: consider making this configurable.
logManager.SetLogLevels("info")

return nil
}
16 changes: 8 additions & 8 deletions collectors/wallet_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
}

var (
numConf, numUnconf uint32
sum, max, min btcutil.Amount
numConf, numUnconf uint32
sum, maxAmt, minAmt btcutil.Amount
)

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

if utxo.Value > max {
max = utxo.Value
if utxo.Value > maxAmt {
maxAmt = utxo.Value
}
if utxo.Value < min || min == 0 {
min = utxo.Value
if utxo.Value < minAmt || minAmt == 0 {
minAmt = utxo.Value
}
}

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

ch <- prometheus.MustNewConstMetric(
u.minUtxoSizeDesc, prometheus.GaugeValue, float64(min),
u.minUtxoSizeDesc, prometheus.GaugeValue, float64(minAmt),
)

ch <- prometheus.MustNewConstMetric(
u.maxUtxoSizeDesc, prometheus.GaugeValue, float64(max),
u.maxUtxoSizeDesc, prometheus.GaugeValue, float64(maxAmt),
)

ch <- prometheus.MustNewConstMetric(
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type lndConfig struct {
Host string `long:"host" description:"lnd instance rpc address"`

// Network is the network that lnd is running on, i.e. mainnet.
Network string `long:"network" description:"network to run on" choice:"regtest" choice:"testnet" choice:"mainnet" choice:"simnet" choice:"signet"`
Network string `long:"network" description:"network to run on" choice:"regtest" choice:"testnet" choice:"testnet4" choice:"mainnet" choice:"simnet" choice:"signet"`

// MacaroonDir is the path to lnd macaroons.
MacaroonDir string `long:"macaroondir" description:"Path to lnd macaroons"`
Expand Down
Loading