Skip to content
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 @@ -20,7 +20,7 @@ env:

# If you change this value, please change it in the following files as well:
# /Dockerfile
GO_VERSION: 1.21.10
GO_VERSION: 1.24.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉


jobs:
########################
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${BUILDPLATFORM} golang:1.22-alpine as builder
FROM --platform=${BUILDPLATFORM} golang:1.24-alpine as builder

# Copy in the local repository to build from.
COPY . /go/src/github.com/lightningnetwork/loop
Expand Down
4 changes: 2 additions & 2 deletions sweepbatcher/greedy_batch_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (b *Batcher) greedyAddSweep(ctx context.Context, sweep *sweep) error {
return nil
}

log.Debugf("Batch selection algorithm returned batch id %d for"+
" sweep %x, but acceptance failed.", batchId,
debugf("Batch selection algorithm returned batch id %d "+
"for sweep %x, but acceptance failed.", batchId,
sweep.swapHash[:6])
}

Expand Down
34 changes: 30 additions & 4 deletions sweepbatcher/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ package sweepbatcher

import (
"fmt"
"sync/atomic"

"github.com/btcsuite/btclog"
"github.com/lightningnetwork/lnd/build"
)

// log is a logger that is initialized with no output filters. This
// log_ is a logger that is initialized with no output filters. This
// means the package will not perform any logging by default until the
// caller requests it.
var log btclog.Logger
var log_ atomic.Pointer[btclog.Logger]

// log returns active logger.
func log() btclog.Logger {
return *log_.Load()
}

// The default amount of logging is none.
func init() {
Expand All @@ -20,12 +26,32 @@ func init() {
// batchPrefixLogger returns a logger that prefixes all log messages with
// the ID.
func batchPrefixLogger(batchID string) btclog.Logger {
return build.NewPrefixLog(fmt.Sprintf("[Batch %s]", batchID), log)
return build.NewPrefixLog(fmt.Sprintf("[Batch %s]", batchID), log())
}

// UseLogger uses a specified Logger to output package logging info.
// This should be used in preference to SetLogWriter if the caller is also
// using btclog.
func UseLogger(logger btclog.Logger) {
log = logger
log_.Store(&logger)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we only really call UseLogger once it should not race iiuc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call it in runTests function in each test. It increases logging to include debug messages. I caught a race between tests: in one test a sweepbatcher was shutting down and logging something, while another test was calling UseLogger.

}

// debugf logs a message with level DEBUG.
func debugf(format string, params ...interface{}) {
log().Debugf(format, params...)
}

// infof logs a message with level INFO.
func infof(format string, params ...interface{}) {
log().Infof(format, params...)
}

// warnf logs a message with level WARN.
func warnf(format string, params ...interface{}) {
log().Warnf(format, params...)
}

// errorf logs a message with level ERROR.
func errorf(format string, params ...interface{}) {
log().Errorf(format, params...)
}
33 changes: 33 additions & 0 deletions sweepbatcher/store_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"sort"
"sync"

"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/lntypes"
Expand All @@ -13,6 +14,7 @@ import (
type StoreMock struct {
batches map[int32]dbBatch
sweeps map[lntypes.Hash]dbSweep
mu sync.Mutex
}

// NewStoreMock instantiates a new mock store.
Expand All @@ -28,6 +30,9 @@ func NewStoreMock() *StoreMock {
func (s *StoreMock) FetchUnconfirmedSweepBatches(ctx context.Context) (
[]*dbBatch, error) {

s.mu.Lock()
defer s.mu.Unlock()

result := []*dbBatch{}
for _, batch := range s.batches {
batch := batch
Expand All @@ -44,6 +49,9 @@ func (s *StoreMock) FetchUnconfirmedSweepBatches(ctx context.Context) (
func (s *StoreMock) InsertSweepBatch(ctx context.Context,
batch *dbBatch) (int32, error) {

s.mu.Lock()
defer s.mu.Unlock()

var id int32

if len(s.batches) == 0 {
Expand All @@ -66,12 +74,18 @@ func (s *StoreMock) DropBatch(ctx context.Context, id int32) error {
func (s *StoreMock) UpdateSweepBatch(ctx context.Context,
batch *dbBatch) error {

s.mu.Lock()
defer s.mu.Unlock()

s.batches[batch.ID] = *batch
return nil
}

// ConfirmBatch confirms a batch.
func (s *StoreMock) ConfirmBatch(ctx context.Context, id int32) error {
s.mu.Lock()
defer s.mu.Unlock()

batch, ok := s.batches[id]
if !ok {
return errors.New("batch not found")
Expand All @@ -87,6 +101,9 @@ func (s *StoreMock) ConfirmBatch(ctx context.Context, id int32) error {
func (s *StoreMock) FetchBatchSweeps(ctx context.Context,
id int32) ([]*dbSweep, error) {

s.mu.Lock()
defer s.mu.Unlock()

result := []*dbSweep{}
for _, sweep := range s.sweeps {
sweep := sweep
Expand All @@ -104,14 +121,21 @@ func (s *StoreMock) FetchBatchSweeps(ctx context.Context,

// UpsertSweep inserts a sweep into the database, or updates an existing sweep.
func (s *StoreMock) UpsertSweep(ctx context.Context, sweep *dbSweep) error {
s.mu.Lock()
defer s.mu.Unlock()

s.sweeps[sweep.SwapHash] = *sweep

return nil
}

// GetSweepStatus returns the status of a sweep.
func (s *StoreMock) GetSweepStatus(ctx context.Context,
swapHash lntypes.Hash) (bool, error) {

s.mu.Lock()
defer s.mu.Unlock()

sweep, ok := s.sweeps[swapHash]
if !ok {
return false, nil
Expand All @@ -127,6 +151,9 @@ func (s *StoreMock) Close() error {

// AssertSweepStored asserts that a sweep is stored.
func (s *StoreMock) AssertSweepStored(id lntypes.Hash) bool {
s.mu.Lock()
defer s.mu.Unlock()

_, ok := s.sweeps[id]
return ok
}
Expand All @@ -135,6 +162,9 @@ func (s *StoreMock) AssertSweepStored(id lntypes.Hash) bool {
func (s *StoreMock) GetParentBatch(ctx context.Context, swapHash lntypes.Hash) (
*dbBatch, error) {

s.mu.Lock()
defer s.mu.Unlock()

for _, sweep := range s.sweeps {
if sweep.SwapHash == swapHash {
batch, ok := s.batches[sweep.BatchID]
Expand All @@ -153,6 +183,9 @@ func (s *StoreMock) GetParentBatch(ctx context.Context, swapHash lntypes.Hash) (
func (s *StoreMock) TotalSweptAmount(ctx context.Context, batchID int32) (
btcutil.Amount, error) {

s.mu.Lock()
defer s.mu.Unlock()

batch, ok := s.batches[batchID]
if !ok {
return 0, errors.New("batch not found")
Expand Down
Loading