mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
lint: fix linter issues
This commit is contained in:
parent
bb9124a80a
commit
a10c741a26
54 changed files with 269 additions and 468 deletions
|
|
@ -442,10 +442,7 @@ func (s *Client) Run(ctx context.Context, statusChan chan<- SwapInfo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start goroutine to deliver all pending swaps to the main loop.
|
// Start goroutine to deliver all pending swaps to the main loop.
|
||||||
s.wg.Add(1)
|
s.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer s.wg.Done()
|
|
||||||
|
|
||||||
s.resumeSwaps(mainCtx, pendingLoopOutSwaps, pendingLoopInSwaps)
|
s.resumeSwaps(mainCtx, pendingLoopOutSwaps, pendingLoopInSwaps)
|
||||||
|
|
||||||
// Signal that new requests can be accepted. Otherwise, the new
|
// Signal that new requests can be accepted. Otherwise, the new
|
||||||
|
|
@ -453,7 +450,7 @@ func (s *Client) Run(ctx context.Context, statusChan chan<- SwapInfo) error {
|
||||||
// this goroutine as being a swap that needs to be resumed.
|
// this goroutine as being a swap that needs to be resumed.
|
||||||
// Resulting in two goroutines executing the same swap.
|
// Resulting in two goroutines executing the same swap.
|
||||||
close(s.resumeReady)
|
close(s.resumeReady)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Main event loop.
|
// Main event loop.
|
||||||
err = s.executor.run(mainCtx, statusChan, s.abandonChans)
|
err = s.executor.run(mainCtx, statusChan, s.abandonChans)
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,7 @@ func instantOut(ctx context.Context, cmd *cli.Command) error {
|
||||||
// element.
|
// element.
|
||||||
var outgoingChanSet []uint64
|
var outgoingChanSet []uint64
|
||||||
if cmd.IsSet("channel") {
|
if cmd.IsSet("channel") {
|
||||||
chanStrings := strings.Split(cmd.String("channel"), ",")
|
for chanString := range strings.SplitSeq(cmd.String("channel"), ",") {
|
||||||
for _, chanString := range chanStrings {
|
|
||||||
chanID, err := strconv.ParseUint(chanString, 10, 64)
|
chanID, err := strconv.ParseUint(chanString, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error parsing channel id "+
|
return fmt.Errorf("error parsing channel id "+
|
||||||
|
|
|
||||||
|
|
@ -159,8 +159,7 @@ func loopOut(ctx context.Context, cmd *cli.Command) error {
|
||||||
return fmt.Errorf("channel flag is not supported when " +
|
return fmt.Errorf("channel flag is not supported when " +
|
||||||
"looping out assets")
|
"looping out assets")
|
||||||
}
|
}
|
||||||
chanStrings := strings.Split(cmd.String("channel"), ",")
|
for chanString := range strings.SplitSeq(cmd.String("channel"), ",") {
|
||||||
for _, chanString := range chanStrings {
|
|
||||||
chanID, err := strconv.ParseUint(chanString, 10, 64)
|
chanID, err := strconv.ParseUint(chanString, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error parsing channel id "+
|
return fmt.Errorf("error parsing channel id "+
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ const (
|
||||||
envVarMacaroonPath = "LOOPCLI_MACAROONPATH"
|
envVarMacaroonPath = "LOOPCLI_MACAROONPATH"
|
||||||
)
|
)
|
||||||
|
|
||||||
func printJSON(resp interface{}) {
|
func printJSON(resp any) {
|
||||||
b, err := json.Marshal(resp)
|
b, err := json.Marshal(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,7 @@ func listSwaps(ctx context.Context, cmd *cli.Command) error {
|
||||||
// element.
|
// element.
|
||||||
var outgoingChanSet []uint64
|
var outgoingChanSet []uint64
|
||||||
if cmd.IsSet(channelFlag.Name) {
|
if cmd.IsSet(channelFlag.Name) {
|
||||||
chanStrings := strings.Split(cmd.String(channelFlag.Name), ",")
|
for chanString := range strings.SplitSeq(cmd.String(channelFlag.Name), ",") {
|
||||||
for _, chanString := range chanStrings {
|
|
||||||
chanID, err := strconv.ParseUint(chanString, 10, 64)
|
chanID, err := strconv.ParseUint(chanString, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error parsing channel id "+
|
return fmt.Errorf("error parsing channel id "+
|
||||||
|
|
|
||||||
14
executor.go
14
executor.go
|
|
@ -123,10 +123,7 @@ func (s *executor) run(mainCtx context.Context,
|
||||||
|
|
||||||
batcherErrChan = make(chan error, 1)
|
batcherErrChan = make(chan error, 1)
|
||||||
|
|
||||||
s.wg.Add(1)
|
s.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer s.wg.Done()
|
|
||||||
|
|
||||||
err := s.batcher.Run(mainCtx)
|
err := s.batcher.Run(mainCtx)
|
||||||
if err != nil && !errors.Is(err, context.Canceled) {
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
select {
|
select {
|
||||||
|
|
@ -134,7 +131,7 @@ func (s *executor) run(mainCtx context.Context,
|
||||||
case <-mainCtx.Done():
|
case <-mainCtx.Done():
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Start main event loop.
|
// Start main event loop.
|
||||||
log.Infof("Starting event loop at height %v", height)
|
log.Infof("Starting event loop at height %v", height)
|
||||||
|
|
@ -164,10 +161,7 @@ func (s *executor) run(mainCtx context.Context,
|
||||||
swapID := nextSwapID
|
swapID := nextSwapID
|
||||||
blockEpochQueues[swapID] = queue
|
blockEpochQueues[swapID] = queue
|
||||||
|
|
||||||
s.wg.Add(1)
|
s.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer s.wg.Done()
|
|
||||||
|
|
||||||
err := newSwap.execute(mainCtx, &executeConfig{
|
err := newSwap.execute(mainCtx, &executeConfig{
|
||||||
statusChan: statusChan,
|
statusChan: statusChan,
|
||||||
sweeper: s.sweeper,
|
sweeper: s.sweeper,
|
||||||
|
|
@ -200,7 +194,7 @@ func (s *executor) run(mainCtx context.Context,
|
||||||
case swapDoneChan <- swapID:
|
case swapDoneChan <- swapID:
|
||||||
case <-mainCtx.Done():
|
case <-mainCtx.Done():
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
nextSwapID++
|
nextSwapID++
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ type EventType string
|
||||||
|
|
||||||
// EventContext represents the context to be passed to the action
|
// EventContext represents the context to be passed to the action
|
||||||
// implementation.
|
// implementation.
|
||||||
type EventContext interface{}
|
type EventContext = any
|
||||||
|
|
||||||
// Action represents the action to be executed in a given state.
|
// Action represents the action to be executed in a given state.
|
||||||
type Action func(ctx context.Context, eventCtx EventContext) EventType
|
type Action func(ctx context.Context, eventCtx EventContext) EventType
|
||||||
|
|
|
||||||
|
|
@ -352,33 +352,33 @@ func (f *FSM) updateInstantOut(ctx context.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof logs an info message with the reservation hash as prefix.
|
// Infof logs an info message with the reservation hash as prefix.
|
||||||
func (f *FSM) Infof(format string, args ...interface{}) {
|
func (f *FSM) Infof(format string, args ...any) {
|
||||||
log.Infof(
|
log.Infof(
|
||||||
"InstantOut %v: "+format,
|
"InstantOut %v: "+format,
|
||||||
append(
|
append(
|
||||||
[]interface{}{f.InstantOut.swapPreimage.Hash()},
|
[]any{f.InstantOut.swapPreimage.Hash()},
|
||||||
args...,
|
args...,
|
||||||
)...,
|
)...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf logs a debug message with the reservation hash as prefix.
|
// Debugf logs a debug message with the reservation hash as prefix.
|
||||||
func (f *FSM) Debugf(format string, args ...interface{}) {
|
func (f *FSM) Debugf(format string, args ...any) {
|
||||||
log.Debugf(
|
log.Debugf(
|
||||||
"InstantOut %v: "+format,
|
"InstantOut %v: "+format,
|
||||||
append(
|
append(
|
||||||
[]interface{}{f.InstantOut.swapPreimage.Hash()},
|
[]any{f.InstantOut.swapPreimage.Hash()},
|
||||||
args...,
|
args...,
|
||||||
)...,
|
)...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf logs an error message with the reservation hash as prefix.
|
// Errorf logs an error message with the reservation hash as prefix.
|
||||||
func (f *FSM) Errorf(format string, args ...interface{}) {
|
func (f *FSM) Errorf(format string, args ...any) {
|
||||||
log.Errorf(
|
log.Errorf(
|
||||||
"InstantOut %v: "+format,
|
"InstantOut %v: "+format,
|
||||||
append(
|
append(
|
||||||
[]interface{}{f.InstantOut.swapPreimage.Hash()},
|
[]any{f.InstantOut.swapPreimage.Hash()},
|
||||||
args...,
|
args...,
|
||||||
)...,
|
)...,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -443,7 +443,7 @@ func (i *InstantOut) generateHtlcSweepTx(ctx context.Context,
|
||||||
// htlcWeight returns the weight for the htlc transaction.
|
// htlcWeight returns the weight for the htlc transaction.
|
||||||
func htlcWeight(numInputs int) lntypes.WeightUnit {
|
func htlcWeight(numInputs int) lntypes.WeightUnit {
|
||||||
var weightEstimator input.TxWeightEstimator
|
var weightEstimator input.TxWeightEstimator
|
||||||
for i := 0; i < numInputs; i++ {
|
for range numInputs {
|
||||||
weightEstimator.AddTaprootKeySpendInput(
|
weightEstimator.AddTaprootKeySpendInput(
|
||||||
txscript.SigHashDefault,
|
txscript.SigHashDefault,
|
||||||
)
|
)
|
||||||
|
|
@ -457,7 +457,7 @@ func htlcWeight(numInputs int) lntypes.WeightUnit {
|
||||||
// sweeplessSweepWeight returns the weight for the sweepless sweep transaction.
|
// sweeplessSweepWeight returns the weight for the sweepless sweep transaction.
|
||||||
func sweeplessSweepWeight(numInputs int) lntypes.WeightUnit {
|
func sweeplessSweepWeight(numInputs int) lntypes.WeightUnit {
|
||||||
var weightEstimator input.TxWeightEstimator
|
var weightEstimator input.TxWeightEstimator
|
||||||
for i := 0; i < numInputs; i++ {
|
for range numInputs {
|
||||||
weightEstimator.AddTaprootKeySpendInput(
|
weightEstimator.AddTaprootKeySpendInput(
|
||||||
txscript.SigHashDefault,
|
txscript.SigHashDefault,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -259,26 +259,26 @@ func (r *FSM) updateReservation(ctx context.Context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FSM) Infof(format string, args ...interface{}) {
|
func (r *FSM) Infof(format string, args ...any) {
|
||||||
log.Infof(
|
log.Infof(
|
||||||
"Reservation %v %x: "+format,
|
"Reservation %v %x: "+format,
|
||||||
append([]interface{}{r.reservation.ProtocolVersion, r.reservation.ID},
|
append([]any{r.reservation.ProtocolVersion, r.reservation.ID},
|
||||||
args...)...,
|
args...)...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FSM) Debugf(format string, args ...interface{}) {
|
func (r *FSM) Debugf(format string, args ...any) {
|
||||||
log.Debugf(
|
log.Debugf(
|
||||||
"Reservation %v %x: "+format,
|
"Reservation %v %x: "+format,
|
||||||
append([]interface{}{r.reservation.ProtocolVersion, r.reservation.ID},
|
append([]any{r.reservation.ProtocolVersion, r.reservation.ID},
|
||||||
args...)...,
|
args...)...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FSM) Errorf(format string, args ...interface{}) {
|
func (r *FSM) Errorf(format string, args ...any) {
|
||||||
log.Errorf(
|
log.Errorf(
|
||||||
"Reservation %v %x: "+format,
|
"Reservation %v %x: "+format,
|
||||||
append([]interface{}{r.reservation.ProtocolVersion, r.reservation.ID},
|
append([]any{r.reservation.ProtocolVersion, r.reservation.ID},
|
||||||
args...)...,
|
args...)...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestManager(t *testing.T) {
|
func TestManager(t *testing.T) {
|
||||||
ctxb, cancel := context.WithCancel(context.Background())
|
ctxb := t.Context()
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
testContext := newManagerTestContext(t)
|
testContext := newManagerTestContext(t)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -324,7 +324,7 @@ func (c *autoloopTestCtx) autoloop(step *autoloopStep) {
|
||||||
amt2expected[expected.request.Amount] = expected
|
amt2expected[expected.request.Amount] = expected
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(step.quotesIn); i++ {
|
for range len(step.quotesIn) {
|
||||||
request := <-c.quoteRequestIn
|
request := <-c.quoteRequestIn
|
||||||
|
|
||||||
// Get the expected item, using amount as a key.
|
// Get the expected item, using amount as a key.
|
||||||
|
|
@ -459,7 +459,7 @@ func (c *autoloopTestCtx) matchLoopOuts(swaps []loopOutRequestResp,
|
||||||
|
|
||||||
length := len(swapsCopy)
|
length := len(swapsCopy)
|
||||||
|
|
||||||
for i := 0; i < length; i++ {
|
for range length {
|
||||||
actual := <-c.outRequest
|
actual := <-c.outRequest
|
||||||
|
|
||||||
if !keepDestAddr {
|
if !keepDestAddr {
|
||||||
|
|
@ -494,7 +494,7 @@ func (c *autoloopTestCtx) matchLoopIns(
|
||||||
swapsCopy := make([]loopInRequestResp, len(swaps))
|
swapsCopy := make([]loopInRequestResp, len(swaps))
|
||||||
copy(swapsCopy, swaps)
|
copy(swapsCopy, swaps)
|
||||||
|
|
||||||
for i := 0; i < len(swapsCopy); i++ {
|
for range len(swapsCopy) {
|
||||||
actual := <-c.inRequest
|
actual := <-c.inRequest
|
||||||
|
|
||||||
inner:
|
inner:
|
||||||
|
|
|
||||||
|
|
@ -622,9 +622,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
|
||||||
// Calculate the amount that we want to loop out. If it exceeds the max
|
// Calculate the amount that we want to loop out. If it exceeds the max
|
||||||
// allowed clamp it to max.
|
// allowed clamp it to max.
|
||||||
amount := localTotal - m.params.EasyAutoloopTarget
|
amount := localTotal - m.params.EasyAutoloopTarget
|
||||||
if amount > restrictions.Maximum {
|
amount = min(amount, restrictions.Maximum)
|
||||||
amount = restrictions.Maximum
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the amount we want to loop out is less than the minimum we can't
|
// If the amount we want to loop out is less than the minimum we can't
|
||||||
// proceed with a swap, so we return early.
|
// proceed with a swap, so we return early.
|
||||||
|
|
@ -1516,7 +1514,7 @@ func (m *Manager) dispatchStickyLoopOut(ctx context.Context,
|
||||||
m.activeStickyLock.Unlock()
|
m.activeStickyLock.Unlock()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for i := 0; i < int(retryCount); i++ {
|
for range int(retryCount) {
|
||||||
// Dispatch the swap.
|
// Dispatch the swap.
|
||||||
swap, err := m.cfg.LoopOut(ctx, &out)
|
swap, err := m.cfg.LoopOut(ctx, &out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -335,10 +336,7 @@ func (d *Daemon) startWebServers() error {
|
||||||
ReadHeaderTimeout: 5 * time.Second,
|
ReadHeaderTimeout: 5 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
d.wg.Add(1)
|
d.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("REST proxy listening on %s",
|
infof("REST proxy listening on %s",
|
||||||
d.restListener.Addr())
|
d.restListener.Addr())
|
||||||
err := d.restServer.Serve(d.restListener)
|
err := d.restServer.Serve(d.restListener)
|
||||||
|
|
@ -351,16 +349,13 @@ func (d *Daemon) startWebServers() error {
|
||||||
// channel is sufficiently buffered.
|
// channel is sufficiently buffered.
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
} else {
|
} else {
|
||||||
infof("REST proxy disabled")
|
infof("REST proxy disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the grpc server.
|
// Start the grpc server.
|
||||||
d.wg.Add(1)
|
d.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("RPC server listening on %s", d.grpcListener.Addr())
|
infof("RPC server listening on %s", d.grpcListener.Addr())
|
||||||
err = d.grpcServer.Serve(d.grpcListener)
|
err = d.grpcServer.Serve(d.grpcListener)
|
||||||
if err != nil && !errors.Is(err, grpc.ErrServerStopped) {
|
if err != nil && !errors.Is(err, grpc.ErrServerStopped) {
|
||||||
|
|
@ -370,7 +365,7 @@ func (d *Daemon) startWebServers() error {
|
||||||
// channel is sufficiently buffered.
|
// channel is sufficiently buffered.
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -511,9 +506,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
|
|
||||||
// Add our debug permissions to our main set of required permissions
|
// Add our debug permissions to our main set of required permissions
|
||||||
// if compiled in.
|
// if compiled in.
|
||||||
for endpoint, perm := range debugRequiredPermissions {
|
maps.Copy(loop_looprpc.RequiredPermissions, debugRequiredPermissions)
|
||||||
loop_looprpc.RequiredPermissions[endpoint] = perm
|
|
||||||
}
|
|
||||||
|
|
||||||
rks, db, err := lndclient.NewBoltMacaroonStore(
|
rks, db, err := lndclient.NewBoltMacaroonStore(
|
||||||
d.cfg.DataDir, "macaroons.db", loopdb.DefaultLoopDBTimeout,
|
d.cfg.DataDir, "macaroons.db", loopdb.DefaultLoopDBTimeout,
|
||||||
|
|
@ -569,17 +562,14 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
}
|
}
|
||||||
notificationManager := notifications.NewManager(notificationCfg)
|
notificationManager := notifications.NewManager(notificationCfg)
|
||||||
|
|
||||||
d.wg.Add(1)
|
d.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Starting notification manager")
|
infof("Starting notification manager")
|
||||||
err := notificationManager.Run(d.mainCtx)
|
err := notificationManager.Run(d.mainCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
errorf("Notification manager stopped: %v", err)
|
errorf("Notification manager stopped: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
staticAddressManager *address.Manager
|
staticAddressManager *address.Manager
|
||||||
|
|
@ -752,7 +742,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
liquidityMgr: getLiquidityManager(swapClient),
|
liquidityMgr: getLiquidityManager(swapClient),
|
||||||
lnd: &d.lnd.LndServices,
|
lnd: &d.lnd.LndServices,
|
||||||
swaps: make(map[lntypes.Hash]loop.SwapInfo),
|
swaps: make(map[lntypes.Hash]loop.SwapInfo),
|
||||||
subscribers: make(map[int]chan<- interface{}),
|
subscribers: make(map[int]chan<- any),
|
||||||
statusChan: make(chan loop.SwapInfo),
|
statusChan: make(chan loop.SwapInfo),
|
||||||
mainCtx: d.mainCtx,
|
mainCtx: d.mainCtx,
|
||||||
reservationManager: reservationManager,
|
reservationManager: reservationManager,
|
||||||
|
|
@ -792,10 +782,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the swap client itself.
|
// Start the swap client itself.
|
||||||
d.wg.Add(1)
|
d.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Starting swap client")
|
infof("Starting swap client")
|
||||||
err := d.impl.Run(d.mainCtx, d.statusChan)
|
err := d.impl.Run(d.mainCtx, d.statusChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -806,21 +793,15 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
infof("Swap client stopped")
|
infof("Swap client stopped")
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Start a goroutine that broadcasts swap updates to clients.
|
// Start a goroutine that broadcasts swap updates to clients.
|
||||||
d.wg.Add(1)
|
d.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Waiting for updates")
|
infof("Waiting for updates")
|
||||||
d.processStatusUpdates(d.mainCtx)
|
d.processStatusUpdates(d.mainCtx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
d.wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
|
d.wg.Go(func() {
|
||||||
infof("Starting liquidity manager")
|
infof("Starting liquidity manager")
|
||||||
err := d.liquidityMgr.Run(d.mainCtx)
|
err := d.liquidityMgr.Run(d.mainCtx)
|
||||||
if err != nil && !errors.Is(err, context.Canceled) {
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
|
@ -828,17 +809,14 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
infof("Liquidity manager stopped")
|
infof("Liquidity manager stopped")
|
||||||
}()
|
})
|
||||||
|
|
||||||
initManagerTimeout := 10 * time.Second
|
initManagerTimeout := 10 * time.Second
|
||||||
|
|
||||||
// Start the reservation manager.
|
// Start the reservation manager.
|
||||||
if d.reservationManager != nil {
|
if d.reservationManager != nil {
|
||||||
d.wg.Add(1)
|
|
||||||
initChan := make(chan struct{})
|
initChan := make(chan struct{})
|
||||||
go func() {
|
d.wg.Go(func() {
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Starting reservation manager")
|
infof("Starting reservation manager")
|
||||||
defer infof("Reservation manager stopped")
|
defer infof("Reservation manager stopped")
|
||||||
|
|
||||||
|
|
@ -848,7 +826,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
if err != nil && !errors.Is(err, context.Canceled) {
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the reservation server to be ready before starting
|
// Wait for the reservation server to be ready before starting
|
||||||
// the grpc server.
|
// the grpc server.
|
||||||
|
|
@ -868,11 +846,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
|
|
||||||
// Start the instant out manager.
|
// Start the instant out manager.
|
||||||
if d.instantOutManager != nil {
|
if d.instantOutManager != nil {
|
||||||
d.wg.Add(1)
|
|
||||||
initChan := make(chan struct{})
|
initChan := make(chan struct{})
|
||||||
go func() {
|
d.wg.Go(func() {
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Starting instantout manager")
|
infof("Starting instantout manager")
|
||||||
defer infof("Instantout manager stopped")
|
defer infof("Instantout manager stopped")
|
||||||
|
|
||||||
|
|
@ -880,7 +855,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
if err != nil && !errors.Is(err, context.Canceled) {
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the instantout server to be ready before starting
|
// Wait for the instantout server to be ready before starting
|
||||||
// the grpc server.
|
// the grpc server.
|
||||||
|
|
@ -900,11 +875,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
|
|
||||||
// Start the static address manager.
|
// Start the static address manager.
|
||||||
if staticAddressManager != nil {
|
if staticAddressManager != nil {
|
||||||
d.wg.Add(1)
|
|
||||||
initChan := make(chan struct{})
|
initChan := make(chan struct{})
|
||||||
go func() {
|
d.wg.Go(func() {
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Starting static address manager...")
|
infof("Starting static address manager...")
|
||||||
defer infof("Static address manager stopped")
|
defer infof("Static address manager stopped")
|
||||||
|
|
||||||
|
|
@ -912,7 +884,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
if shouldReportManagerErr(err) {
|
if shouldReportManagerErr(err) {
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the static address manager to be ready before
|
// Wait for the static address manager to be ready before
|
||||||
// starting the grpc server.
|
// starting the grpc server.
|
||||||
|
|
@ -932,11 +904,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
|
|
||||||
// Start the static address deposit manager.
|
// Start the static address deposit manager.
|
||||||
if depositManager != nil {
|
if depositManager != nil {
|
||||||
d.wg.Add(1)
|
|
||||||
initChan := make(chan struct{})
|
initChan := make(chan struct{})
|
||||||
go func() {
|
d.wg.Go(func() {
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Starting static address deposit manager...")
|
infof("Starting static address deposit manager...")
|
||||||
defer infof("Static address deposit manager stopped")
|
defer infof("Static address deposit manager stopped")
|
||||||
|
|
||||||
|
|
@ -944,7 +913,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
if shouldReportManagerErr(err) {
|
if shouldReportManagerErr(err) {
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the static address manager to be ready before
|
// Wait for the static address manager to be ready before
|
||||||
// starting the grpc server.
|
// starting the grpc server.
|
||||||
|
|
@ -964,11 +933,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
|
|
||||||
// Start the static address deposit withdrawal manager.
|
// Start the static address deposit withdrawal manager.
|
||||||
if withdrawalManager != nil {
|
if withdrawalManager != nil {
|
||||||
d.wg.Add(1)
|
|
||||||
initChan := make(chan struct{})
|
initChan := make(chan struct{})
|
||||||
go func() {
|
d.wg.Go(func() {
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Starting static address withdrawal manager...")
|
infof("Starting static address withdrawal manager...")
|
||||||
defer infof("Static address withdrawal manager stopped")
|
defer infof("Static address withdrawal manager stopped")
|
||||||
|
|
||||||
|
|
@ -976,7 +942,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
if shouldReportManagerErr(err) {
|
if shouldReportManagerErr(err) {
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
// We need a higher timeout here, because withdrawalManager
|
// We need a higher timeout here, because withdrawalManager
|
||||||
// publishes transactions and each PublishTransaction call can
|
// publishes transactions and each PublishTransaction call can
|
||||||
|
|
@ -1000,33 +966,27 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
||||||
}
|
}
|
||||||
// Start the static address open channel manager.
|
// Start the static address open channel manager.
|
||||||
if openChannelManager != nil {
|
if openChannelManager != nil {
|
||||||
d.wg.Add(1)
|
d.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Starting static address open channel manager")
|
infof("Starting static address open channel manager")
|
||||||
err := openChannelManager.Run(d.mainCtx)
|
err := openChannelManager.Run(d.mainCtx)
|
||||||
if err != nil && !errors.Is(context.Canceled, err) {
|
if err != nil && !errors.Is(context.Canceled, err) {
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
infof("Static address open channel manager stopped")
|
infof("Static address open channel manager stopped")
|
||||||
}()
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the static address loop-in manager.
|
// Start the static address loop-in manager.
|
||||||
if staticLoopInManager != nil {
|
if staticLoopInManager != nil {
|
||||||
d.wg.Add(1)
|
|
||||||
initChan := make(chan struct{})
|
initChan := make(chan struct{})
|
||||||
go func() {
|
d.wg.Go(func() {
|
||||||
defer d.wg.Done()
|
|
||||||
|
|
||||||
infof("Starting static address loop-in manager...")
|
infof("Starting static address loop-in manager...")
|
||||||
defer infof("Static address loop-in manager stopped")
|
defer infof("Static address loop-in manager stopped")
|
||||||
err := staticLoopInManager.Run(d.mainCtx, initChan)
|
err := staticLoopInManager.Run(d.mainCtx, initChan)
|
||||||
if shouldReportManagerErr(err) {
|
if shouldReportManagerErr(err) {
|
||||||
d.internalErrChan <- err
|
d.internalErrChan <- err
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the static address loop-in manager to be ready before
|
// Wait for the static address loop-in manager to be ready before
|
||||||
// starting the grpc server.
|
// starting the grpc server.
|
||||||
|
|
|
||||||
|
|
@ -39,22 +39,22 @@ func setLogger(logger btclog.Logger) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tracef logs a message with level TRACE.
|
// tracef logs a message with level TRACE.
|
||||||
func tracef(format string, params ...interface{}) {
|
func tracef(format string, params ...any) {
|
||||||
log().Tracef(format, params...)
|
log().Tracef(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// infof logs a message with level INFO.
|
// infof logs a message with level INFO.
|
||||||
func infof(format string, params ...interface{}) {
|
func infof(format string, params ...any) {
|
||||||
log().Infof(format, params...)
|
log().Infof(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// warnf logs a message with level WARN.
|
// warnf logs a message with level WARN.
|
||||||
func warnf(format string, params ...interface{}) {
|
func warnf(format string, params ...any) {
|
||||||
log().Warnf(format, params...)
|
log().Warnf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorf logs a message with level ERROR.
|
// errorf logs a message with level ERROR.
|
||||||
func errorf(format string, params ...interface{}) {
|
func errorf(format string, params ...any) {
|
||||||
log().Errorf(format, params...)
|
log().Errorf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build !dev
|
//go:build !dev
|
||||||
// +build !dev
|
|
||||||
|
|
||||||
package loopd
|
package loopd
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ type swapClientServer struct {
|
||||||
openChannelManager *openchannel.Manager
|
openChannelManager *openchannel.Manager
|
||||||
assetClient *assets.TapdClient
|
assetClient *assets.TapdClient
|
||||||
swaps map[lntypes.Hash]loop.SwapInfo
|
swaps map[lntypes.Hash]loop.SwapInfo
|
||||||
subscribers map[int]chan<- interface{}
|
subscribers map[int]chan<- any
|
||||||
statusChan chan loop.SwapInfo
|
statusChan chan loop.SwapInfo
|
||||||
nextSubscriberID int
|
nextSubscriberID int
|
||||||
swapsLock sync.Mutex
|
swapsLock sync.Mutex
|
||||||
|
|
@ -678,14 +678,8 @@ func filterSwap(swapInfo *loop.SwapInfo, filter *looprpc.ListSwapsFilter) bool {
|
||||||
if swapInfo.SwapType == swap.TypeOut && filter.OutgoingChanSet != nil {
|
if swapInfo.SwapType == swap.TypeOut && filter.OutgoingChanSet != nil {
|
||||||
// First we sort both channel sets to make sure we can compare
|
// First we sort both channel sets to make sure we can compare
|
||||||
// them.
|
// them.
|
||||||
sort.Slice(swapInfo.OutgoingChanSet, func(i, j int) bool {
|
slices.Sort(swapInfo.OutgoingChanSet)
|
||||||
return swapInfo.OutgoingChanSet[i] <
|
slices.Sort(filter.OutgoingChanSet)
|
||||||
swapInfo.OutgoingChanSet[j]
|
|
||||||
})
|
|
||||||
sort.Slice(filter.OutgoingChanSet, func(i, j int) bool {
|
|
||||||
return filter.OutgoingChanSet[i] <
|
|
||||||
filter.OutgoingChanSet[j]
|
|
||||||
})
|
|
||||||
|
|
||||||
// Compare the outgoing channel set by using reflect.DeepEqual
|
// Compare the outgoing channel set by using reflect.DeepEqual
|
||||||
// which compares the underlying arrays.
|
// which compares the underlying arrays.
|
||||||
|
|
@ -1244,6 +1238,7 @@ func (s *swapClientServer) GetL402Tokens(ctx context.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLsatTokens returns all tokens that are contained in the L402 token store.
|
// GetLsatTokens returns all tokens that are contained in the L402 token store.
|
||||||
|
//
|
||||||
// Deprecated: use GetL402Tokens.
|
// Deprecated: use GetL402Tokens.
|
||||||
// This API is provided to maintain backward compatibility with gRPC clients
|
// This API is provided to maintain backward compatibility with gRPC clients
|
||||||
// (e.g. `loop listauth`, Terminal Web, RTL).
|
// (e.g. `loop listauth`, Terminal Web, RTL).
|
||||||
|
|
@ -1809,12 +1804,7 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
|
||||||
var filteredDeposits []*looprpc.Deposit
|
var filteredDeposits []*looprpc.Deposit
|
||||||
if len(outpoints) > 0 {
|
if len(outpoints) > 0 {
|
||||||
f := func(d *deposit.Deposit) bool {
|
f := func(d *deposit.Deposit) bool {
|
||||||
for _, outpoint := range outpoints {
|
return slices.Contains(outpoints, d.OutPoint.String())
|
||||||
if outpoint == d.OutPoint.String() {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
filteredDeposits = filter(allDeposits, f)
|
filteredDeposits = filter(allDeposits, f)
|
||||||
|
|
||||||
|
|
@ -2179,7 +2169,7 @@ func (s *swapClientServer) populateBlocksUntilExpiry(ctx context.Context,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := 0; i < len(deposits); i++ {
|
for i := range len(deposits) {
|
||||||
deposits[i].BlocksUntilExpiry =
|
deposits[i].BlocksUntilExpiry =
|
||||||
deposits[i].ConfirmationHeight +
|
deposits[i].ConfirmationHeight +
|
||||||
int64(params.Expiry) - bestBlockHeight
|
int64(params.Expiry) - bestBlockHeight
|
||||||
|
|
@ -2646,7 +2636,7 @@ func hasBandwidth(channels []lndclient.ChannelInfo, amt btcutil.Amount,
|
||||||
tracef("Trying to split %v sats into %v parts", amt, shard)
|
tracef("Trying to split %v sats into %v parts", amt, shard)
|
||||||
|
|
||||||
paid := false
|
paid := false
|
||||||
for i := 0; i < len(localBalances); i++ {
|
for i := range len(localBalances) {
|
||||||
// TODO(hieblmi): Consider channel reserves because the
|
// TODO(hieblmi): Consider channel reserves because the
|
||||||
// channel can't send its full local balance.
|
// channel can't send its full local balance.
|
||||||
if localBalances[i] >= split {
|
if localBalances[i] >= split {
|
||||||
|
|
|
||||||
|
|
@ -545,37 +545,37 @@ func (f *formatLogger) record(format string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tracef logs a trace and records its format.
|
// Tracef logs a trace and records its format.
|
||||||
func (f *formatLogger) Tracef(format string, params ...interface{}) {
|
func (f *formatLogger) Tracef(format string, params ...any) {
|
||||||
f.record(format)
|
f.record(format)
|
||||||
f.Logger.Tracef(format, params...)
|
f.Logger.Tracef(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf logs a debug message and records its format.
|
// Debugf logs a debug message and records its format.
|
||||||
func (f *formatLogger) Debugf(format string, params ...interface{}) {
|
func (f *formatLogger) Debugf(format string, params ...any) {
|
||||||
f.record(format)
|
f.record(format)
|
||||||
f.Logger.Debugf(format, params...)
|
f.Logger.Debugf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof logs an info message and records its format.
|
// Infof logs an info message and records its format.
|
||||||
func (f *formatLogger) Infof(format string, params ...interface{}) {
|
func (f *formatLogger) Infof(format string, params ...any) {
|
||||||
f.record(format)
|
f.record(format)
|
||||||
f.Logger.Infof(format, params...)
|
f.Logger.Infof(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warnf logs a warning and records its format.
|
// Warnf logs a warning and records its format.
|
||||||
func (f *formatLogger) Warnf(format string, params ...interface{}) {
|
func (f *formatLogger) Warnf(format string, params ...any) {
|
||||||
f.record(format)
|
f.record(format)
|
||||||
f.Logger.Warnf(format, params...)
|
f.Logger.Warnf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf logs an error and records its format.
|
// Errorf logs an error and records its format.
|
||||||
func (f *formatLogger) Errorf(format string, params ...interface{}) {
|
func (f *formatLogger) Errorf(format string, params ...any) {
|
||||||
f.record(format)
|
f.record(format)
|
||||||
f.Logger.Errorf(format, params...)
|
f.Logger.Errorf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Criticalf logs a critical message and records its format.
|
// Criticalf logs a critical message and records its format.
|
||||||
func (f *formatLogger) Criticalf(format string, params ...interface{}) {
|
func (f *formatLogger) Criticalf(format string, params ...any) {
|
||||||
f.record(format)
|
f.record(format)
|
||||||
f.Logger.Criticalf(format, params...)
|
f.Logger.Criticalf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ func TestProtocolVersionMarshalUnMarshal(t *testing.T) {
|
||||||
bogusVersion := []byte{0xFF, 0xFF, 0xFF, 0xFF}
|
bogusVersion := []byte{0xFF, 0xFF, 0xFF, 0xFF}
|
||||||
invalidSlice := []byte{0xFF, 0xFF, 0xFF}
|
invalidSlice := []byte{0xFF, 0xFF, 0xFF}
|
||||||
|
|
||||||
for i := 0; i < len(testVersions); i++ {
|
for i := range len(testVersions) {
|
||||||
testVersion := testVersions[i]
|
testVersion := testVersions[i]
|
||||||
|
|
||||||
// Test that unmarshal(marshal(v)) == v.
|
// Test that unmarshal(marshal(v)) == v.
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,7 @@ func NewMigrationError(err error) *migrationError {
|
||||||
return &migrationError{Err: err}
|
return &migrationError{Err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
func equalValues(src interface{}, dst interface{}) error {
|
func equalValues(src any, dst any) error {
|
||||||
mt := &mockTesting{}
|
mt := &mockTesting{}
|
||||||
|
|
||||||
require.EqualValues(mt, src, dst)
|
require.EqualValues(mt, src, dst)
|
||||||
|
|
@ -405,14 +405,14 @@ type mockTesting struct {
|
||||||
failNow bool
|
failNow bool
|
||||||
fail bool
|
fail bool
|
||||||
format string
|
format string
|
||||||
args []interface{}
|
args []any
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockTesting) FailNow() {
|
func (m *mockTesting) FailNow() {
|
||||||
m.failNow = true
|
m.failNow = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockTesting) Errorf(format string, args ...interface{}) {
|
func (m *mockTesting) Errorf(format string, args ...any) {
|
||||||
m.format = format
|
m.format = format
|
||||||
m.args = args
|
m.args = args
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,25 +19,25 @@ func TestMigrationUpdates(t *testing.T) {
|
||||||
legacyDbVersion = Hex("00000003")
|
legacyDbVersion = Hex("00000003")
|
||||||
)
|
)
|
||||||
|
|
||||||
legacyDb := map[string]interface{}{
|
legacyDb := map[string]any{
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]any{
|
||||||
"dbp": legacyDbVersion,
|
"dbp": legacyDbVersion,
|
||||||
},
|
},
|
||||||
"loop-in": map[string]interface{}{
|
"loop-in": map[string]any{
|
||||||
Hex("acae09fec9020b7996042613eede68a9eaf29eb28c21ea9943b19e344365a4bb"): map[string]interface{}{
|
Hex("acae09fec9020b7996042613eede68a9eaf29eb28c21ea9943b19e344365a4bb"): map[string]any{
|
||||||
"contract": Hex("161b25277262bdb5c7c2827b975b2cbc7eb13e222b30cf88ea6daef4bcf22bdac4116c23071472cb000000000000ea6003f2f513a8fd7958b6a229dfb8835f6ab2c9c63cc3e138784d3e8c0e0ebbdd4e61033f26c40666977ed497eea4694d6dd3f07dbcf037089234ff665cd0a07fea329400007b8a00000000000059a600000000000009ca000077a20000000600000000000000000000000000000000000000000000000000000000000000000000"),
|
"contract": Hex("161b25277262bdb5c7c2827b975b2cbc7eb13e222b30cf88ea6daef4bcf22bdac4116c23071472cb000000000000ea6003f2f513a8fd7958b6a229dfb8835f6ab2c9c63cc3e138784d3e8c0e0ebbdd4e61033f26c40666977ed497eea4694d6dd3f07dbcf037089234ff665cd0a07fea329400007b8a00000000000059a600000000000009ca000077a20000000600000000000000000000000000000000000000000000000000000000000000000000"),
|
||||||
"updates": map[string]interface{}{
|
"updates": map[string]any{
|
||||||
Hex("0000000000000001"): Hex("161b252772cb524508000000000000000000000000000000000000000000000000"),
|
Hex("0000000000000001"): Hex("161b252772cb524508000000000000000000000000000000000000000000000000"),
|
||||||
Hex("0000000000000002"): Hex("161b252837115e9b09ffffffffffff1f6a00000000000000000000000000000000"),
|
Hex("0000000000000002"): Hex("161b252837115e9b09ffffffffffff1f6a00000000000000000000000000000000"),
|
||||||
Hex("0000000000000003"): Hex("161b252ab670360d0200000000000009ca00000000000000000000000000000000"),
|
Hex("0000000000000003"): Hex("161b252ab670360d0200000000000009ca00000000000000000000000000000000"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"uncharge-swaps": map[string]interface{}{
|
"uncharge-swaps": map[string]any{
|
||||||
Hex("c3b3d7a145dbd2bab5aa1f505305f31ee432fe23b0801f065fac453dd9b1f923"): map[string]interface{}{
|
Hex("c3b3d7a145dbd2bab5aa1f505305f31ee432fe23b0801f065fac453dd9b1f923"): map[string]any{
|
||||||
"contract": Hex("161b2526643767387ca76e58c964a8f2b6c0a13392b2dea93bde260226a263fb836954054ed1756b000000000000c350fd11016c6e6263727431333337306e3170303072343775707035366c7671663836753565766135647868686c706c78303733756a70676e3979767977376130766a37746d307678793276683576716471327770657832757270307963717a7279787139377a76757173703570373232733970686a6e6e6e706c3778716e796a78353373706863346c396735306b396e347836703761793577707539306b6673397179397173717a353766676a7a67676838343439377375716b383436787a3333336a713036736c6b38637a323872657466363672796b7876396a746e6a3072683979666a6170777065617265713071396679797a666664676d6874687973617370757565746e6b72306b32376370326173366a750269d66fd2cea620dc06f1f7de7838f0c8b145b82c7033080c398862f3421a23230382cb637badbb07f9926a06ecd88b6150513ea0060dc8d6dc1c1fb623926b0a0f000077d400000000000b458c00000000000005f10000000000000024000077a22c6263727431713271756332666777737971376463617a73666e3332636a7874667671647671366a6c70706574fd0f016c6e626372743530313834306e317030307234377570703563776561306732396d30667434646432726167397870306e726d6a72396c33726b7a717037706a6c34337a6e6d6b64336c79337364713877646d6b7a757163717a7279787139377a767571737035616478717538766168643730743776747165777578366d6d64337977636639767835736476717567753833327230676e373466733971793971737168746773636638386e377664767136716e71307a657775366d7471616e326c7a306e7534737a72376c6b36646d343673336c78726572656e333972616b7a6c777378346c613538733966773630356d6767766b766879716e743339713976737367777879367571707236713273780000000600000000000003f20000000000000000161b25262710ce00"),
|
"contract": Hex("161b2526643767387ca76e58c964a8f2b6c0a13392b2dea93bde260226a263fb836954054ed1756b000000000000c350fd11016c6e6263727431333337306e3170303072343775707035366c7671663836753565766135647868686c706c78303733756a70676e3979767977376130766a37746d307678793276683576716471327770657832757270307963717a7279787139377a76757173703570373232733970686a6e6e6e706c3778716e796a78353373706863346c396735306b396e347836703761793577707539306b6673397179397173717a353766676a7a67676838343439377375716b383436787a3333336a713036736c6b38637a323872657466363672796b7876396a746e6a3072683979666a6170777065617265713071396679797a666664676d6874687973617370757565746e6b72306b32376370326173366a750269d66fd2cea620dc06f1f7de7838f0c8b145b82c7033080c398862f3421a23230382cb637badbb07f9926a06ecd88b6150513ea0060dc8d6dc1c1fb623926b0a0f000077d400000000000b458c00000000000005f10000000000000024000077a22c6263727431713271756332666777737971376463617a73666e3332636a7874667671647671366a6c70706574fd0f016c6e626372743530313834306e317030307234377570703563776561306732396d30667434646432726167397870306e726d6a72396c33726b7a717037706a6c34337a6e6d6b64336c79337364713877646d6b7a757163717a7279787139377a767571737035616478717538766168643730743776747165777578366d6d64337977636639767835736476717567753833327230676e373466733971793971737168746773636638386e377664767136716e71307a657775366d7471616e326c7a306e7534737a72376c6b36646d343673336c78726572656e333972616b7a6c777378346c613538733966773630356d6767766b766879716e743339713976737367777879367571707236713273780000000600000000000003f20000000000000000161b25262710ce00"),
|
||||||
"outgoing-chan-set": nil,
|
"outgoing-chan-set": nil,
|
||||||
"updates": map[string]interface{}{
|
"updates": map[string]any{
|
||||||
Hex("0000000000000001"): Hex("161b252a770e649b01000000000000053900000000000000000000000000000001"),
|
Hex("0000000000000001"): Hex("161b252a770e649b01000000000000053900000000000000000000000000000001"),
|
||||||
Hex("0000000000000002"): Hex("161b252ab671bdd90200000000000005f10000000000001a9c0000000000000003"),
|
Hex("0000000000000002"): Hex("161b252ab671bdd90200000000000005f10000000000001a9c0000000000000003"),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ type PostgresConfig struct {
|
||||||
Host string `long:"host" description:"Database server hostname."`
|
Host string `long:"host" description:"Database server hostname."`
|
||||||
Port int `long:"port" description:"Database server port."`
|
Port int `long:"port" description:"Database server port."`
|
||||||
User string `long:"user" description:"Database user."`
|
User string `long:"user" description:"Database user."`
|
||||||
Password string `long:"password" description:"Database user's password."`
|
Password string `long:"password" description:"Database user's password."` //nolint:gosec
|
||||||
DBName string `long:"dbname" description:"Database name to use."`
|
DBName string `long:"dbname" description:"Database name to use."`
|
||||||
MaxOpenConnections int32 `long:"maxconnections" description:"Max open connections to keep alive to the database server."`
|
MaxOpenConnections int32 `long:"maxconnections" description:"Max open connections to keep alive to the database server."`
|
||||||
RequireSSL bool `long:"requiressl" description:"Whether to require using SSL (mode: require) when connecting to the server."`
|
RequireSSL bool `long:"requiressl" description:"Whether to require using SSL (mode: require) when connecting to the server."`
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,9 @@ const (
|
||||||
// the server to perform a probe to test inbound liquidty.
|
// the server to perform a probe to test inbound liquidty.
|
||||||
ProtocolVersionProbe ProtocolVersion = 8
|
ProtocolVersionProbe ProtocolVersion = 8
|
||||||
|
|
||||||
// The client may ask the server to use a custom routing helper plugin
|
// ProtocolVersionRoutingPlugin indicates that the client may ask the
|
||||||
// in order to enhance off-chain payments corresponding to a swap.
|
// server to use a custom routing helper plugin in order to enhance
|
||||||
|
// off-chain payments corresponding to a swap.
|
||||||
ProtocolVersionRoutingPlugin = 9
|
ProtocolVersionRoutingPlugin = 9
|
||||||
|
|
||||||
// ProtocolVersionHtlcV3 indicates that the client will now use the new
|
// ProtocolVersionHtlcV3 indicates that the client will now use the new
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ import (
|
||||||
//
|
//
|
||||||
// Example output:
|
// Example output:
|
||||||
//
|
//
|
||||||
// map[string]interface{}{
|
// map[string]any{
|
||||||
// Hex("1234"): map[string]interface{}{
|
// Hex("1234"): map[string]any{
|
||||||
// "human-readable": Hex("102030"),
|
// "human-readable": Hex("102030"),
|
||||||
// Hex("1111"): Hex("5783492373"),
|
// Hex("1111"): Hex("5783492373"),
|
||||||
// },
|
// },
|
||||||
|
|
@ -36,7 +36,7 @@ func DumpDB(tx *bbolt.Tx) error { // nolint: unused
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpBucket(bucket *bbolt.Bucket) error { // nolint: unused
|
func dumpBucket(bucket *bbolt.Bucket) error { // nolint: unused
|
||||||
fmt.Printf("map[string]interface{} {\n")
|
fmt.Printf("map[string]any {\n")
|
||||||
err := bucket.ForEach(func(k, v []byte) error {
|
err := bucket.ForEach(func(k, v []byte) error {
|
||||||
key := toString(k)
|
key := toString(k)
|
||||||
fmt.Printf("%v: ", key)
|
fmt.Printf("%v: ", key)
|
||||||
|
|
@ -63,11 +63,11 @@ func dumpBucket(bucket *bbolt.Bucket) error { // nolint: unused
|
||||||
}
|
}
|
||||||
|
|
||||||
// RestoreDB primes the database with the given data set.
|
// RestoreDB primes the database with the given data set.
|
||||||
func RestoreDB(tx *bbolt.Tx, data map[string]interface{}) error {
|
func RestoreDB(tx *bbolt.Tx, data map[string]any) error {
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
key := []byte(k)
|
key := []byte(k)
|
||||||
|
|
||||||
value := v.(map[string]interface{})
|
value := v.(map[string]any)
|
||||||
|
|
||||||
subBucket, err := tx.CreateBucket(key)
|
subBucket, err := tx.CreateBucket(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -83,7 +83,7 @@ func RestoreDB(tx *bbolt.Tx, data map[string]interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func restoreDB(bucket *bbolt.Bucket, data map[string]interface{}) error {
|
func restoreDB(bucket *bbolt.Bucket, data map[string]any) error {
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
key := []byte(k)
|
key := []byte(k)
|
||||||
|
|
||||||
|
|
@ -104,7 +104,7 @@ func restoreDB(bucket *bbolt.Bucket, data map[string]interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key contains a sub-bucket.
|
// Key contains a sub-bucket.
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
subBucket, err := bucket.CreateBucket(key)
|
subBucket, err := bucket.CreateBucket(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -740,7 +740,7 @@ func (db *BaseDB) convertLoopInRow(row sqlc.GetLoopInSwapsRow,
|
||||||
func getSwapEvents(updates []sqlc.SwapUpdate) ([]*LoopEvent, error) {
|
func getSwapEvents(updates []sqlc.SwapUpdate) ([]*LoopEvent, error) {
|
||||||
events := make([]*LoopEvent, len(updates))
|
events := make([]*LoopEvent, len(updates))
|
||||||
|
|
||||||
for i := 0; i < len(events); i++ {
|
for i := range len(events) {
|
||||||
events[i] = &LoopEvent{
|
events[i] = &LoopEvent{
|
||||||
SwapStateData: SwapStateData{
|
SwapStateData: SwapStateData{
|
||||||
State: SwapState(updates[i].UpdateState),
|
State: SwapState(updates[i].UpdateState),
|
||||||
|
|
|
||||||
|
|
@ -569,14 +569,14 @@ func randomBytes(length int) []byte {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func randomStruct(v interface{}) error {
|
func randomStruct(v any) error {
|
||||||
val := reflect.ValueOf(v)
|
val := reflect.ValueOf(v)
|
||||||
if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
|
if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
|
||||||
return errors.New("Input should be a pointer to a struct type")
|
return errors.New("Input should be a pointer to a struct type")
|
||||||
}
|
}
|
||||||
|
|
||||||
val = val.Elem()
|
val = val.Elem()
|
||||||
for i := 0; i < val.NumField(); i++ {
|
for i := range val.NumField() {
|
||||||
field := val.Field(i)
|
field := val.Field(i)
|
||||||
|
|
||||||
switch field.Kind() {
|
switch field.Kind() {
|
||||||
|
|
@ -598,12 +598,12 @@ func randomStruct(v interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
if field.Type() == reflect.TypeOf(time.Time{}) {
|
if field.Type() == reflect.TypeFor[time.Time]() {
|
||||||
if field.CanSet() {
|
if field.CanSet() {
|
||||||
field.Set(reflect.ValueOf(time.Now()))
|
field.Set(reflect.ValueOf(time.Now()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if field.Type() == reflect.TypeOf(route.Vertex{}) {
|
if field.Type() == reflect.TypeFor[route.Vertex]() {
|
||||||
if field.CanSet() {
|
if field.CanSet() {
|
||||||
vertex, err := route.NewVertexFromBytes(
|
vertex, err := route.NewVertexFromBytes(
|
||||||
randomBytes(route.VertexSize),
|
randomBytes(route.VertexSize),
|
||||||
|
|
|
||||||
|
|
@ -442,15 +442,15 @@ func TestLegacyOutgoingChannel(t *testing.T) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
legacyDb := map[string]interface{}{
|
legacyDb := map[string]any{
|
||||||
"loop-in": map[string]interface{}{},
|
"loop-in": map[string]any{},
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]any{
|
||||||
"dbp": legacyDbVersion,
|
"dbp": legacyDbVersion,
|
||||||
},
|
},
|
||||||
"uncharge-swaps": map[string]interface{}{
|
"uncharge-swaps": map[string]any{
|
||||||
Hex("2a595d79a55168970532805ae20c9b5fac98f04db79ba4c6ae9b9ac0f206359e"): map[string]interface{}{
|
Hex("2a595d79a55168970532805ae20c9b5fac98f04db79ba4c6ae9b9ac0f206359e"): map[string]any{
|
||||||
"contract": Hex("1562d6fbec140000010101010202020203030303040404040101010102020202030303030404040400000000000000640d707265706179696e766f69636501010101010101010101010101010101010101010101010101010101010101010201010101010101010101010101010101010101010101010101010101010101010300000090000000000000000a0000000000000014000000000000002800000063223347454e556d6e4552745766516374344e65676f6d557171745a757a5947507742530b73776170696e766f69636500000002000000000000001e") + legacyOutgoingChannel + Hex("1562d6fbec140000"),
|
"contract": Hex("1562d6fbec140000010101010202020203030303040404040101010102020202030303030404040400000000000000640d707265706179696e766f69636501010101010101010101010101010101010101010101010101010101010101010201010101010101010101010101010101010101010101010101010101010101010300000090000000000000000a0000000000000014000000000000002800000063223347454e556d6e4552745766516374344e65676f6d557171745a757a5947507742530b73776170696e766f69636500000002000000000000001e") + legacyOutgoingChannel + Hex("1562d6fbec140000"),
|
||||||
"updates": map[string]interface{}{
|
"updates": map[string]any{
|
||||||
Hex("0000000000000001"): Hex("1508290a92d4c00001000000000000000000000000000000000000000000000000"),
|
Hex("0000000000000001"): Hex("1508290a92d4c00001000000000000000000000000000000000000000000000000"),
|
||||||
Hex("0000000000000002"): Hex("1508290a92d4c00006000000000000000000000000000000000000000000000000"),
|
Hex("0000000000000002"): Hex("1508290a92d4c00006000000000000000000000000000000000000000000000000"),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build !test_db_postgres
|
//go:build !test_db_postgres
|
||||||
// +build !test_db_postgres
|
|
||||||
|
|
||||||
package loopdb
|
package loopdb
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -530,13 +530,11 @@ func (s *loopInSwap) execute(mainCtx context.Context,
|
||||||
subCtx, cancel := context.WithCancel(mainCtx)
|
subCtx, cancel := context.WithCancel(mainCtx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
s.wg.Add(1)
|
s.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer s.wg.Done()
|
|
||||||
subscribeAndLogUpdates(
|
subscribeAndLogUpdates(
|
||||||
subCtx, s.hash, s.log, s.server.SubscribeLoopInUpdates,
|
subCtx, s.hash, s.log, s.server.SubscribeLoopInUpdates,
|
||||||
)
|
)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Announce swap by sending out an initial update.
|
// Announce swap by sending out an initial update.
|
||||||
err := s.sendUpdate(mainCtx)
|
err := s.sendUpdate(mainCtx)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ type loopInTestContext struct {
|
||||||
cfg *executeConfig
|
cfg *executeConfig
|
||||||
statusChan chan SwapInfo
|
statusChan chan SwapInfo
|
||||||
errChan chan error
|
errChan chan error
|
||||||
blockEpochChan chan interface{}
|
blockEpochChan chan any
|
||||||
|
|
||||||
swapInvoiceSubscription *test.SingleInvoiceSubscription
|
swapInvoiceSubscription *test.SingleInvoiceSubscription
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ func newLoopInTestContext(t *testing.T) *loopInTestContext {
|
||||||
store := loopdb.NewStoreMock(t)
|
store := loopdb.NewStoreMock(t)
|
||||||
sweeper := sweep.Sweeper{Lnd: &lnd.LndServices}
|
sweeper := sweep.Sweeper{Lnd: &lnd.LndServices}
|
||||||
|
|
||||||
blockEpochChan := make(chan interface{})
|
blockEpochChan := make(chan any)
|
||||||
statusChan := make(chan SwapInfo)
|
statusChan := make(chan SwapInfo)
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ type executeConfig struct {
|
||||||
sweeper *sweep.Sweeper
|
sweeper *sweep.Sweeper
|
||||||
batcher *sweepbatcher.Batcher
|
batcher *sweepbatcher.Batcher
|
||||||
statusChan chan<- SwapInfo
|
statusChan chan<- SwapInfo
|
||||||
blockEpochChan <-chan interface{}
|
blockEpochChan <-chan any
|
||||||
timerFactory func(time.Duration) <-chan time.Time
|
timerFactory func(time.Duration) <-chan time.Time
|
||||||
loopOutMaxParts uint32
|
loopOutMaxParts uint32
|
||||||
totalPaymentTimeout time.Duration
|
totalPaymentTimeout time.Duration
|
||||||
|
|
@ -386,13 +386,11 @@ func (s *loopOutSwap) execute(mainCtx context.Context,
|
||||||
subCtx, cancel := context.WithCancel(mainCtx)
|
subCtx, cancel := context.WithCancel(mainCtx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
s.wg.Add(1)
|
s.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer s.wg.Done()
|
|
||||||
subscribeAndLogUpdates(
|
subscribeAndLogUpdates(
|
||||||
subCtx, s.hash, s.log, s.server.SubscribeLoopOutUpdates,
|
subCtx, s.hash, s.log, s.server.SubscribeLoopOutUpdates,
|
||||||
)
|
)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Execute swap.
|
// Execute swap.
|
||||||
err := s.executeAndFinalize(mainCtx)
|
err := s.executeAndFinalize(mainCtx)
|
||||||
|
|
|
||||||
|
|
@ -155,10 +155,7 @@ func (p *loopOutSweepFeerateProvider) GetConfTargetAndFeeRate(
|
||||||
if confTarget <= DefaultSweepConfTargetDelta {
|
if confTarget <= DefaultSweepConfTargetDelta {
|
||||||
// If confTarget is already <= urgentSweepConfTarget, don't
|
// If confTarget is already <= urgentSweepConfTarget, don't
|
||||||
// increase it.
|
// increase it.
|
||||||
newConfTarget := int32(urgentSweepConfTarget)
|
newConfTarget := min(confTarget, int32(urgentSweepConfTarget))
|
||||||
if confTarget < newConfTarget {
|
|
||||||
newConfTarget = confTarget
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Swap %x is about to expire (blocksUntilExpiry=%d), "+
|
log.Infof("Swap %x is about to expire (blocksUntilExpiry=%d), "+
|
||||||
"reducing its confTarget from %d to %d and multiplying"+
|
"reducing its confTarget from %d to %d and multiplying"+
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ func testLoopOutPaymentParameters(t *testing.T) {
|
||||||
|
|
||||||
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
||||||
|
|
||||||
blockEpochChan := make(chan interface{})
|
blockEpochChan := make(chan any)
|
||||||
statusChan := make(chan SwapInfo)
|
statusChan := make(chan SwapInfo)
|
||||||
|
|
||||||
const maxParts = uint32(5)
|
const maxParts = uint32(5)
|
||||||
|
|
@ -205,7 +205,7 @@ func testLateHtlcPublish(t *testing.T) {
|
||||||
|
|
||||||
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
||||||
|
|
||||||
blockEpochChan := make(chan interface{})
|
blockEpochChan := make(chan any)
|
||||||
statusChan := make(chan SwapInfo)
|
statusChan := make(chan SwapInfo)
|
||||||
|
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
|
|
@ -308,7 +308,7 @@ func testCustomSweepConfTarget(t *testing.T) {
|
||||||
//
|
//
|
||||||
// TODO: create test context similar to loopInTestContext.
|
// TODO: create test context similar to loopInTestContext.
|
||||||
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
||||||
blockEpochChan := make(chan interface{})
|
blockEpochChan := make(chan any)
|
||||||
statusChan := make(chan SwapInfo)
|
statusChan := make(chan SwapInfo)
|
||||||
expiryChan := make(chan time.Time)
|
expiryChan := make(chan time.Time)
|
||||||
timerFactory := func(expiry time.Duration) <-chan time.Time {
|
timerFactory := func(expiry time.Duration) <-chan time.Time {
|
||||||
|
|
@ -330,8 +330,7 @@ func testCustomSweepConfTarget(t *testing.T) {
|
||||||
lnd.ChainParams, batcherStore, sweepStore,
|
lnd.ChainParams, batcherStore, sweepStore,
|
||||||
)
|
)
|
||||||
|
|
||||||
tctx, cancel := context.WithCancel(context.Background())
|
tctx := t.Context()
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := batcher.Run(tctx)
|
err := batcher.Run(tctx)
|
||||||
|
|
@ -415,7 +414,7 @@ func testCustomSweepConfTarget(t *testing.T) {
|
||||||
|
|
||||||
// Try MuSig2 signing first and fail it so that we go for a
|
// Try MuSig2 signing first and fail it so that we go for a
|
||||||
// normal sweep.
|
// normal sweep.
|
||||||
for i := 0; i < maxMusigSweepRetries; i++ {
|
for range maxMusigSweepRetries {
|
||||||
expiryChan <- time.Now()
|
expiryChan <- time.Now()
|
||||||
preimage := <-server.preimagePush
|
preimage := <-server.preimagePush
|
||||||
require.Equal(t, swap.Preimage, preimage)
|
require.Equal(t, swap.Preimage, preimage)
|
||||||
|
|
@ -546,7 +545,7 @@ func testPreimagePush(t *testing.T) {
|
||||||
|
|
||||||
// Set up the required dependencies to execute the swap.
|
// Set up the required dependencies to execute the swap.
|
||||||
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
||||||
blockEpochChan := make(chan interface{})
|
blockEpochChan := make(chan any)
|
||||||
statusChan := make(chan SwapInfo)
|
statusChan := make(chan SwapInfo)
|
||||||
expiryChan := make(chan time.Time)
|
expiryChan := make(chan time.Time)
|
||||||
timerFactory := func(_ time.Duration) <-chan time.Time {
|
timerFactory := func(_ time.Duration) <-chan time.Time {
|
||||||
|
|
@ -568,8 +567,7 @@ func testPreimagePush(t *testing.T) {
|
||||||
lnd.ChainParams, batcherStore, sweepStore,
|
lnd.ChainParams, batcherStore, sweepStore,
|
||||||
)
|
)
|
||||||
|
|
||||||
tctx, cancel := context.WithCancel(context.Background())
|
tctx := t.Context()
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := batcher.Run(tctx)
|
err := batcher.Run(tctx)
|
||||||
|
|
@ -804,7 +802,7 @@ func testFailedOffChainCancelation(t *testing.T) {
|
||||||
|
|
||||||
// Set up the required dependencies to execute the swap.
|
// Set up the required dependencies to execute the swap.
|
||||||
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
||||||
blockEpochChan := make(chan interface{})
|
blockEpochChan := make(chan any)
|
||||||
statusChan := make(chan SwapInfo)
|
statusChan := make(chan SwapInfo)
|
||||||
expiryChan := make(chan time.Time)
|
expiryChan := make(chan time.Time)
|
||||||
timerFactory := func(_ time.Duration) <-chan time.Time {
|
timerFactory := func(_ time.Duration) <-chan time.Time {
|
||||||
|
|
@ -958,7 +956,7 @@ func TestLoopOutMuSig2Sweep(t *testing.T) {
|
||||||
|
|
||||||
// Set up the required dependencies to execute the swap.
|
// Set up the required dependencies to execute the swap.
|
||||||
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
||||||
blockEpochChan := make(chan interface{})
|
blockEpochChan := make(chan any)
|
||||||
statusChan := make(chan SwapInfo)
|
statusChan := make(chan SwapInfo)
|
||||||
expiryChan := make(chan time.Time)
|
expiryChan := make(chan time.Time)
|
||||||
timerFactory := func(_ time.Duration) <-chan time.Time {
|
timerFactory := func(_ time.Duration) <-chan time.Time {
|
||||||
|
|
@ -988,8 +986,7 @@ func TestLoopOutMuSig2Sweep(t *testing.T) {
|
||||||
lnd.ChainParams, batcherStore, sweepStore,
|
lnd.ChainParams, batcherStore, sweepStore,
|
||||||
)
|
)
|
||||||
|
|
||||||
tctx, cancel := context.WithCancel(context.Background())
|
tctx := t.Context()
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := batcher.Run(tctx)
|
err := batcher.Run(tctx)
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ func NewManager(cfg *Config) *Manager {
|
||||||
|
|
||||||
type subscriber struct {
|
type subscriber struct {
|
||||||
subCtx context.Context
|
subCtx context.Context
|
||||||
recvChan interface{}
|
recvChan any
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubscribeReservations subscribes to the reservation notifications.
|
// SubscribeReservations subscribes to the reservation notifications.
|
||||||
|
|
|
||||||
|
|
@ -85,11 +85,11 @@ func (m *mockSubscribeNotificationsClient) Context() context.Context {
|
||||||
return context.TODO()
|
return context.TODO()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSubscribeNotificationsClient) SendMsg(interface{}) error {
|
func (m *mockSubscribeNotificationsClient) SendMsg(any) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSubscribeNotificationsClient) RecvMsg(interface{}) error {
|
func (m *mockSubscribeNotificationsClient) RecvMsg(any) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,8 +125,7 @@ func TestManager_ReservationNotification(t *testing.T) {
|
||||||
subChan := mgr.SubscribeReservations(subCtx)
|
subChan := mgr.SubscribeReservations(subCtx)
|
||||||
|
|
||||||
// Run the manager.
|
// Run the manager.
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx := t.Context()
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := mgr.Run(ctx)
|
err := mgr.Run(ctx)
|
||||||
|
|
@ -229,13 +228,11 @@ func TestManager_Backoff(t *testing.T) {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
// We ignore the returned error because the Manager returns
|
// We ignore the returned error because the Manager returns
|
||||||
// nil on context cancel.
|
// nil on context cancel.
|
||||||
_ = mgr.Run(ctx)
|
_ = mgr.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait long enough to see at least 3 subscription attempts using
|
// Wait long enough to see at least 3 subscription attempts using
|
||||||
// the Manager's default pattern.
|
// the Manager's default pattern.
|
||||||
|
|
@ -318,11 +315,9 @@ func TestManager_MinAliveConnTime(t *testing.T) {
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
_ = mgr.Run(ctx)
|
_ = mgr.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Let the subscription stay alive for 2s, which is >1s (minAlive).
|
// Let the subscription stay alive for 2s, which is >1s (minAlive).
|
||||||
// Then force an error to end the subscription. The manager sees
|
// Then force an error to end the subscription. The manager sees
|
||||||
|
|
@ -407,13 +402,11 @@ func TestManager_Backoff_Pending_Token(t *testing.T) {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
// We ignore the returned error because the Manager returns
|
// We ignore the returned error because the Manager returns
|
||||||
// nil on context cancel.
|
// nil on context cancel.
|
||||||
_ = mgr.Run(ctx)
|
_ = mgr.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait long enough to see at least 3 token calls, so we can see that
|
// Wait long enough to see at least 3 token calls, so we can see that
|
||||||
// we'll indeed backoff when the token is pending.
|
// we'll indeed backoff when the token is pending.
|
||||||
|
|
|
||||||
|
|
@ -100,8 +100,7 @@ func (m *mockStaticAddressClient) ServerNewAddress(ctx context.Context,
|
||||||
// TestManager tests the static address manager generates the corerct static
|
// TestManager tests the static address manager generates the corerct static
|
||||||
// taproot address from the given test parameters.
|
// taproot address from the given test parameters.
|
||||||
func TestManager(t *testing.T) {
|
func TestManager(t *testing.T) {
|
||||||
ctxb, cancel := context.WithCancel(context.Background())
|
ctxb := t.Context()
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
testContext := NewAddressManagerTestContext(t)
|
testContext := NewAddressManagerTestContext(t)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -475,33 +475,33 @@ func isUpdateSkipped(notification fsm.Notification,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof logs an info message with the deposit outpoint.
|
// Infof logs an info message with the deposit outpoint.
|
||||||
func (f *FSM) Infof(format string, args ...interface{}) {
|
func (f *FSM) Infof(format string, args ...any) {
|
||||||
log.Infof(
|
log.Infof(
|
||||||
"Deposit %v: "+format,
|
"Deposit %v: "+format,
|
||||||
append(
|
append(
|
||||||
[]interface{}{f.deposit.OutPoint},
|
[]any{f.deposit.OutPoint},
|
||||||
args...,
|
args...,
|
||||||
)...,
|
)...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf logs a debug message with the deposit outpoint.
|
// Debugf logs a debug message with the deposit outpoint.
|
||||||
func (f *FSM) Debugf(format string, args ...interface{}) {
|
func (f *FSM) Debugf(format string, args ...any) {
|
||||||
log.Debugf(
|
log.Debugf(
|
||||||
"Deposit %v: "+format,
|
"Deposit %v: "+format,
|
||||||
append(
|
append(
|
||||||
[]interface{}{f.deposit.OutPoint},
|
[]any{f.deposit.OutPoint},
|
||||||
args...,
|
args...,
|
||||||
)...,
|
)...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf logs an error message with the deposit outpoint.
|
// Errorf logs an error message with the deposit outpoint.
|
||||||
func (f *FSM) Errorf(format string, args ...interface{}) {
|
func (f *FSM) Errorf(format string, args ...any) {
|
||||||
log.Errorf(
|
log.Errorf(
|
||||||
"Deposit %v: "+format,
|
"Deposit %v: "+format,
|
||||||
append(
|
append(
|
||||||
[]interface{}{f.deposit.OutPoint},
|
[]any{f.deposit.OutPoint},
|
||||||
args...,
|
args...,
|
||||||
)...,
|
)...,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -303,7 +303,7 @@ func isUpdateSkipped(notification fsm.Notification,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof logs an info message with the loop-in swap hash.
|
// Infof logs an info message with the loop-in swap hash.
|
||||||
func (f *FSM) Infof(format string, args ...interface{}) {
|
func (f *FSM) Infof(format string, args ...any) {
|
||||||
if f.loopIn == nil {
|
if f.loopIn == nil {
|
||||||
log.Infof(format, args...)
|
log.Infof(format, args...)
|
||||||
return
|
return
|
||||||
|
|
@ -315,7 +315,7 @@ func (f *FSM) Infof(format string, args ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf logs a debug message with the loop-in swap hash.
|
// Debugf logs a debug message with the loop-in swap hash.
|
||||||
func (f *FSM) Debugf(format string, args ...interface{}) {
|
func (f *FSM) Debugf(format string, args ...any) {
|
||||||
if f.loopIn == nil {
|
if f.loopIn == nil {
|
||||||
log.Debugf(format, args...)
|
log.Debugf(format, args...)
|
||||||
return
|
return
|
||||||
|
|
@ -327,7 +327,7 @@ func (f *FSM) Debugf(format string, args ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warnf logs a warning message with the loop-in swap hash.
|
// Warnf logs a warning message with the loop-in swap hash.
|
||||||
func (f *FSM) Warnf(format string, args ...interface{}) {
|
func (f *FSM) Warnf(format string, args ...any) {
|
||||||
if f.loopIn == nil {
|
if f.loopIn == nil {
|
||||||
log.Warnf(format, args...)
|
log.Warnf(format, args...)
|
||||||
return
|
return
|
||||||
|
|
@ -339,7 +339,7 @@ func (f *FSM) Warnf(format string, args ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf logs an error message with the loop-in swap hash.
|
// Errorf logs an error message with the loop-in swap hash.
|
||||||
func (f *FSM) Errorf(format string, args ...interface{}) {
|
func (f *FSM) Errorf(format string, args ...any) {
|
||||||
if f.loopIn == nil {
|
if f.loopIn == nil {
|
||||||
log.Errorf(format, args...)
|
log.Errorf(format, args...)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,7 @@ func (l *StaticAddressLoopIn) isHtlcTimedOut(height int32) bool {
|
||||||
// htlcWeight returns the weight for the htlc transaction.
|
// htlcWeight returns the weight for the htlc transaction.
|
||||||
func (l *StaticAddressLoopIn) htlcWeight(hasChange bool) lntypes.WeightUnit {
|
func (l *StaticAddressLoopIn) htlcWeight(hasChange bool) lntypes.WeightUnit {
|
||||||
var weightEstimator input.TxWeightEstimator
|
var weightEstimator input.TxWeightEstimator
|
||||||
for i := 0; i < len(l.Deposits); i++ {
|
for range len(l.Deposits) {
|
||||||
weightEstimator.AddTaprootKeySpendInput(
|
weightEstimator.AddTaprootKeySpendInput(
|
||||||
txscript.SigHashDefault,
|
txscript.SigHashDefault,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -986,14 +987,7 @@ func mapDepositsToIndices(
|
||||||
|
|
||||||
depositToIdxMap := make(map[string]int)
|
depositToIdxMap := make(map[string]int)
|
||||||
for reqOutpoint := range req.DepositToNonces {
|
for reqOutpoint := range req.DepositToNonces {
|
||||||
hasDeposit := false
|
if !slices.Contains(loopIn.DepositOutpoints, reqOutpoint) {
|
||||||
for _, depositOutpoint := range loopIn.DepositOutpoints {
|
|
||||||
if depositOutpoint == reqOutpoint {
|
|
||||||
hasDeposit = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !hasDeposit {
|
|
||||||
return nil, fmt.Errorf("deposit outpoint not part of " +
|
return nil, fmt.Errorf("deposit outpoint not part of " +
|
||||||
"loop-in")
|
"loop-in")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -660,8 +660,8 @@ func (m *mockClientStream) CloseSend() error { return nil }
|
||||||
func (m *mockClientStream) Context() context.Context {
|
func (m *mockClientStream) Context() context.Context {
|
||||||
return context.Background()
|
return context.Background()
|
||||||
}
|
}
|
||||||
func (m *mockClientStream) SendMsg(_ interface{}) error { return nil }
|
func (m *mockClientStream) SendMsg(_ any) error { return nil }
|
||||||
func (m *mockClientStream) RecvMsg(_ interface{}) error { return nil }
|
func (m *mockClientStream) RecvMsg(_ any) error { return nil }
|
||||||
|
|
||||||
// mockOpenChanStream implements lnrpc.Lightning_OpenChannelClient. It returns
|
// mockOpenChanStream implements lnrpc.Lightning_OpenChannelClient. It returns
|
||||||
// queued messages from Recv(), then returns finalErr once the queue is
|
// queued messages from Recv(), then returns finalErr once the queue is
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func CreateMusig2Sessions(ctx context.Context,
|
||||||
clientNonces := make([][]byte, len(deposits))
|
clientNonces := make([][]byte, len(deposits))
|
||||||
|
|
||||||
// Create the sessions and nonces from the deposits.
|
// Create the sessions and nonces from the deposits.
|
||||||
for i := 0; i < len(deposits); i++ {
|
for i := range len(deposits) {
|
||||||
session, err := CreateMusig2Session(
|
session, err := CreateMusig2Session(
|
||||||
ctx, signer, addrParams, staticAddress,
|
ctx, signer, addrParams, staticAddress,
|
||||||
)
|
)
|
||||||
|
|
@ -161,7 +161,7 @@ func bip69inputLess(input1, input2 *swapserverrpc.PrevoutInfo) bool {
|
||||||
// At this point, the hashes are not equal, so reverse them to
|
// At this point, the hashes are not equal, so reverse them to
|
||||||
// big-endian and return the result of the comparison.
|
// big-endian and return the result of the comparison.
|
||||||
const hashSize = chainhash.HashSize
|
const hashSize = chainhash.HashSize
|
||||||
for b := 0; b < hashSize/2; b++ {
|
for b := range hashSize / 2 {
|
||||||
ihash[b], ihash[hashSize-1-b] = ihash[hashSize-1-b], ihash[b]
|
ihash[b], ihash[hashSize-1-b] = ihash[hashSize-1-b], ihash[b]
|
||||||
jhash[b], jhash[hashSize-1-b] = jhash[hashSize-1-b], jhash[b]
|
jhash[b], jhash[hashSize-1-b] = jhash[hashSize-1-b], jhash[b]
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +227,7 @@ func estimateFee(numInputs int, feeRate chainfee.SatPerKWeight,
|
||||||
commitmentType lnrpc.CommitmentType) btcutil.Amount {
|
commitmentType lnrpc.CommitmentType) btcutil.Amount {
|
||||||
|
|
||||||
var we input.TxWeightEstimator
|
var we input.TxWeightEstimator
|
||||||
for i := 0; i < numInputs; i++ {
|
for range numInputs {
|
||||||
we.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
we.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1081,7 +1081,7 @@ func WithdrawalTxWeight(numInputs int, sweepAddress btcutil.Address,
|
||||||
hasChange bool) (lntypes.WeightUnit, error) {
|
hasChange bool) (lntypes.WeightUnit, error) {
|
||||||
|
|
||||||
var weightEstimator input.TxWeightEstimator
|
var weightEstimator input.TxWeightEstimator
|
||||||
for i := 0; i < numInputs; i++ {
|
for range numInputs {
|
||||||
weightEstimator.AddTaprootKeySpendInput(
|
weightEstimator.AddTaprootKeySpendInput(
|
||||||
txscript.SigHashDefault,
|
txscript.SigHashDefault,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ type PrefixLog struct {
|
||||||
|
|
||||||
// Infof formats message according to format specifier and writes to
|
// Infof formats message according to format specifier and writes to
|
||||||
// log with LevelInfo.
|
// log with LevelInfo.
|
||||||
func (s *PrefixLog) Infof(format string, params ...interface{}) {
|
func (s *PrefixLog) Infof(format string, params ...any) {
|
||||||
s.Logger.Infof(
|
s.Logger.Infof(
|
||||||
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
||||||
params...,
|
params...,
|
||||||
|
|
@ -27,7 +27,7 @@ func (s *PrefixLog) Infof(format string, params ...interface{}) {
|
||||||
|
|
||||||
// Warnf formats message according to format specifier and writes to log with
|
// Warnf formats message according to format specifier and writes to log with
|
||||||
// LevelError.
|
// LevelError.
|
||||||
func (s *PrefixLog) Warnf(format string, params ...interface{}) {
|
func (s *PrefixLog) Warnf(format string, params ...any) {
|
||||||
s.Logger.Warnf(
|
s.Logger.Warnf(
|
||||||
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
||||||
params...,
|
params...,
|
||||||
|
|
@ -36,7 +36,7 @@ func (s *PrefixLog) Warnf(format string, params ...interface{}) {
|
||||||
|
|
||||||
// Errorf formats message according to format specifier and writes to log with
|
// Errorf formats message according to format specifier and writes to log with
|
||||||
// LevelError.
|
// LevelError.
|
||||||
func (s *PrefixLog) Errorf(format string, params ...interface{}) {
|
func (s *PrefixLog) Errorf(format string, params ...any) {
|
||||||
s.Logger.Errorf(
|
s.Logger.Errorf(
|
||||||
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
||||||
params...,
|
params...,
|
||||||
|
|
|
||||||
|
|
@ -574,10 +574,7 @@ func (s *grpcSwapServerClient) makeServerUpdate(ctx context.Context,
|
||||||
updateChan := make(chan *ServerUpdate)
|
updateChan := make(chan *ServerUpdate)
|
||||||
|
|
||||||
// Create a goroutine that will pipe updates in to our updates channel.
|
// Create a goroutine that will pipe updates in to our updates channel.
|
||||||
s.wg.Add(1)
|
s.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer s.wg.Done()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Try to receive from our stream. If there are no items
|
// Try to receive from our stream. If there are no items
|
||||||
// to consume, this call will block. If our stream is
|
// to consume, this call will block. If our stream is
|
||||||
|
|
@ -623,7 +620,7 @@ func (s *grpcSwapServerClient) makeServerUpdate(ctx context.Context,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
return updateChan, errChan
|
return updateChan, errChan
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -273,10 +273,7 @@ func (e feeDetails) fee() btcutil.Amount {
|
||||||
// combine returns new feeDetails, combining properties.
|
// combine returns new feeDetails, combining properties.
|
||||||
func (e1 feeDetails) combine(e2 feeDetails) feeDetails {
|
func (e1 feeDetails) combine(e2 feeDetails) feeDetails {
|
||||||
// The fee rate is max of two fee rates.
|
// The fee rate is max of two fee rates.
|
||||||
feeRate := e1.FeeRate
|
feeRate := max(e1.FeeRate, e2.FeeRate)
|
||||||
if feeRate < e2.FeeRate {
|
|
||||||
feeRate = e2.FeeRate
|
|
||||||
}
|
|
||||||
|
|
||||||
return feeDetails{
|
return feeDetails{
|
||||||
FeeRate: feeRate,
|
FeeRate: feeRate,
|
||||||
|
|
|
||||||
|
|
@ -37,16 +37,16 @@ func UseLogger(logger btclog.Logger) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// debugf logs a message with level DEBUG.
|
// debugf logs a message with level DEBUG.
|
||||||
func debugf(format string, params ...interface{}) {
|
func debugf(format string, params ...any) {
|
||||||
log().Debugf(format, params...)
|
log().Debugf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// infof logs a message with level INFO.
|
// infof logs a message with level INFO.
|
||||||
func infof(format string, params ...interface{}) {
|
func infof(format string, params ...any) {
|
||||||
log().Infof(format, params...)
|
log().Infof(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// warnf logs a message with level WARN.
|
// warnf logs a message with level WARN.
|
||||||
func warnf(format string, params ...interface{}) {
|
func warnf(format string, params ...any) {
|
||||||
log().Warnf(format, params...)
|
log().Warnf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -465,22 +465,22 @@ func (b *batch) setLog(logger btclog.Logger) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf logs a message with level DEBUG.
|
// Debugf logs a message with level DEBUG.
|
||||||
func (b *batch) Debugf(format string, params ...interface{}) {
|
func (b *batch) Debugf(format string, params ...any) {
|
||||||
b.log().Debugf(format, params...)
|
b.log().Debugf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof logs a message with level INFO.
|
// Infof logs a message with level INFO.
|
||||||
func (b *batch) Infof(format string, params ...interface{}) {
|
func (b *batch) Infof(format string, params ...any) {
|
||||||
b.log().Infof(format, params...)
|
b.log().Infof(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warnf logs a message with level WARN.
|
// Warnf logs a message with level WARN.
|
||||||
func (b *batch) Warnf(format string, params ...interface{}) {
|
func (b *batch) Warnf(format string, params ...any) {
|
||||||
b.log().Warnf(format, params...)
|
b.log().Warnf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf logs a message with level ERROR.
|
// Errorf logs a message with level ERROR.
|
||||||
func (b *batch) Errorf(format string, params ...interface{}) {
|
func (b *batch) Errorf(format string, params ...any) {
|
||||||
b.log().Errorf(format, params...)
|
b.log().Errorf(format, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2034,10 +2034,8 @@ func (b *batch) monitorConfirmations(ctx context.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.wg.Add(1)
|
b.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer cancel()
|
defer cancel()
|
||||||
defer b.wg.Done()
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case conf := <-confChan:
|
case conf := <-confChan:
|
||||||
|
|
@ -2055,7 +2053,7 @@ func (b *batch) monitorConfirmations(ctx context.Context) error {
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1093,17 +1093,14 @@ func (b *Batcher) spinUpBatch(ctx context.Context, fast bool) (*batch, error) {
|
||||||
// We add the batch to our map of batches and start it.
|
// We add the batch to our map of batches and start it.
|
||||||
b.batches[id] = batch
|
b.batches[id] = batch
|
||||||
|
|
||||||
b.wg.Add(1)
|
b.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer b.wg.Done()
|
|
||||||
|
|
||||||
err := batch.Run(ctx)
|
err := batch.Run(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.writeToErrChan(
|
b.writeToErrChan(
|
||||||
ctx, fmt.Errorf("new batch failed: %w", err),
|
ctx, fmt.Errorf("new batch failed: %w", err),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
return batch, nil
|
return batch, nil
|
||||||
}
|
}
|
||||||
|
|
@ -1201,17 +1198,14 @@ func (b *Batcher) spinUpBatchFromDB(ctx context.Context, batch *batch) error {
|
||||||
// We add the batch to our map of batches and start it.
|
// We add the batch to our map of batches and start it.
|
||||||
b.batches[batch.id] = newBatch
|
b.batches[batch.id] = newBatch
|
||||||
|
|
||||||
b.wg.Add(1)
|
b.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer b.wg.Done()
|
|
||||||
|
|
||||||
err := newBatch.Run(ctx)
|
err := newBatch.Run(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.writeToErrChan(
|
b.writeToErrChan(
|
||||||
ctx, fmt.Errorf("db batch failed: %w", err),
|
ctx, fmt.Errorf("db batch failed: %w", err),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -1306,10 +1300,8 @@ func (b *Batcher) monitorSpendAndNotify(ctx context.Context, sweeps []*sweep,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.wg.Add(1)
|
b.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer cancel()
|
defer cancel()
|
||||||
defer b.wg.Done()
|
|
||||||
infof("Batcher monitoring spend for swap %x",
|
infof("Batcher monitoring spend for swap %x",
|
||||||
sweep.swapHash[:6])
|
sweep.swapHash[:6])
|
||||||
|
|
||||||
|
|
@ -1395,7 +1387,7 @@ func (b *Batcher) monitorSpendAndNotify(ctx context.Context, sweeps []*sweep,
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -1433,10 +1425,8 @@ func (b *Batcher) monitorConfAndNotify(ctx context.Context, sweep *sweep,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.wg.Add(1)
|
b.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer cancel()
|
defer cancel()
|
||||||
defer b.wg.Done()
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case conf := <-confChan:
|
case conf := <-confChan:
|
||||||
|
|
@ -1472,7 +1462,7 @@ func (b *Batcher) monitorConfAndNotify(ctx context.Context, sweep *sweep,
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -166,10 +167,7 @@ func (b *batch) snapshot(ctx context.Context) *batch {
|
||||||
var snapshot *batch
|
var snapshot *batch
|
||||||
b.testRunInEventLoop(ctx, func() {
|
b.testRunInEventLoop(ctx, func() {
|
||||||
// Deep copy sweeps.
|
// Deep copy sweeps.
|
||||||
sweeps := make(map[wire.OutPoint]sweep, len(b.sweeps))
|
sweeps := maps.Clone(b.sweeps)
|
||||||
for o, s := range b.sweeps {
|
|
||||||
sweeps[o] = s
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deep copy cfg.
|
// Deep copy cfg.
|
||||||
cfg := *b.cfg
|
cfg := *b.cfg
|
||||||
|
|
@ -527,11 +525,9 @@ func testTxLabeler(t *testing.T, store testStore,
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
)
|
)
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Create a sweep request.
|
// Create a sweep request.
|
||||||
op1 := wire.OutPoint{
|
op1 := wire.OutPoint{
|
||||||
|
|
@ -609,11 +605,9 @@ func testTxLabeler(t *testing.T, store testStore,
|
||||||
batcherStore, sweepStore, WithTxLabeler(txLabeler))
|
batcherStore, sweepStore, WithTxLabeler(txLabeler))
|
||||||
|
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Expect batch to register for spending.
|
// Expect batch to register for spending.
|
||||||
<-lnd.RegisterSpendChannel
|
<-lnd.RegisterSpendChannel
|
||||||
|
|
@ -684,11 +678,9 @@ func testPublishErrorHandler(t *testing.T, store testStore,
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
)
|
)
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Create a sweep request.
|
// Create a sweep request.
|
||||||
sweepReq1 := SweepRequest{
|
sweepReq1 := SweepRequest{
|
||||||
|
|
@ -1195,12 +1187,10 @@ func testSweepBatcherSkippedTxns(t *testing.T, store testStore,
|
||||||
batcherStore, sweepStore,
|
batcherStore, sweepStore,
|
||||||
)
|
)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
||||||
|
|
@ -1278,11 +1268,9 @@ func testSweepBatcherSkippedTxns(t *testing.T, store testStore,
|
||||||
op1.Hash: {},
|
op1.Hash: {},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
||||||
|
|
@ -1341,7 +1329,7 @@ type wrappedLogger struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf logs debug message.
|
// Debugf logs debug message.
|
||||||
func (l *wrappedLogger) Debugf(format string, params ...interface{}) {
|
func (l *wrappedLogger) Debugf(format string, params ...any) {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
|
|
||||||
|
|
@ -1350,7 +1338,7 @@ func (l *wrappedLogger) Debugf(format string, params ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof logs info message.
|
// Infof logs info message.
|
||||||
func (l *wrappedLogger) Infof(format string, params ...interface{}) {
|
func (l *wrappedLogger) Infof(format string, params ...any) {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
|
|
||||||
|
|
@ -1359,7 +1347,7 @@ func (l *wrappedLogger) Infof(format string, params ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warnf logs a warning message.
|
// Warnf logs a warning message.
|
||||||
func (l *wrappedLogger) Warnf(format string, params ...interface{}) {
|
func (l *wrappedLogger) Warnf(format string, params ...any) {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
|
|
||||||
|
|
@ -1402,13 +1390,11 @@ func testDelays(t *testing.T, store testStore, batcherStore testBatcherStore) {
|
||||||
)
|
)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -1452,24 +1438,18 @@ func testDelays(t *testing.T, store testStore, batcherStore testBatcherStore) {
|
||||||
// so catch these actions from two separate goroutines.
|
// so catch these actions from two separate goroutines.
|
||||||
var wg2 sync.WaitGroup
|
var wg2 sync.WaitGroup
|
||||||
|
|
||||||
wg2.Add(1)
|
wg2.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg2.Done()
|
|
||||||
|
|
||||||
// Since a batch was created we check that it registered for its
|
// Since a batch was created we check that it registered for its
|
||||||
// primary sweep's spend.
|
// primary sweep's spend.
|
||||||
<-lnd.RegisterSpendChannel
|
<-lnd.RegisterSpendChannel
|
||||||
}()
|
})
|
||||||
|
|
||||||
wg2.Add(1)
|
|
||||||
var delays []time.Duration
|
var delays []time.Duration
|
||||||
go func() {
|
wg2.Go(func() {
|
||||||
defer wg2.Done()
|
|
||||||
|
|
||||||
// Expect two timers: initialDelay and publishDelay.
|
// Expect two timers: initialDelay and publishDelay.
|
||||||
delays = append(delays, <-tickSignal)
|
delays = append(delays, <-tickSignal)
|
||||||
delays = append(delays, <-tickSignal)
|
delays = append(delays, <-tickSignal)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for RegisterSpend and for timer registrations.
|
// Wait for RegisterSpend and for timer registrations.
|
||||||
wg2.Wait()
|
wg2.Wait()
|
||||||
|
|
@ -1560,11 +1540,9 @@ func testDelays(t *testing.T, store testStore, batcherStore testBatcherStore) {
|
||||||
WithPublishDelay(publishDelay), WithClock(testClock),
|
WithPublishDelay(publishDelay), WithClock(testClock),
|
||||||
)
|
)
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -1574,26 +1552,20 @@ func testDelays(t *testing.T, store testStore, batcherStore testBatcherStore) {
|
||||||
// these actions from two separate goroutines.
|
// these actions from two separate goroutines.
|
||||||
var wg3 sync.WaitGroup
|
var wg3 sync.WaitGroup
|
||||||
|
|
||||||
wg3.Add(1)
|
wg3.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg3.Done()
|
|
||||||
|
|
||||||
// Since a batch was created we check that it registered for its
|
// Since a batch was created we check that it registered for its
|
||||||
// primary sweep's spend.
|
// primary sweep's spend.
|
||||||
<-lnd.RegisterSpendChannel
|
<-lnd.RegisterSpendChannel
|
||||||
|
|
||||||
// Wait for tx to be published.
|
// Wait for tx to be published.
|
||||||
<-lnd.TxPublishChannel
|
<-lnd.TxPublishChannel
|
||||||
}()
|
})
|
||||||
|
|
||||||
wg3.Add(1)
|
|
||||||
delays = nil
|
delays = nil
|
||||||
go func() {
|
wg3.Go(func() {
|
||||||
defer wg3.Done()
|
|
||||||
|
|
||||||
// Expect one timer: publishDelay (0).
|
// Expect one timer: publishDelay (0).
|
||||||
delays = append(delays, <-tickSignal)
|
delays = append(delays, <-tickSignal)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for RegisterSpend and for timer registration.
|
// Wait for RegisterSpend and for timer registration.
|
||||||
wg3.Wait()
|
wg3.Wait()
|
||||||
|
|
@ -1667,11 +1639,9 @@ func testDelays(t *testing.T, store testStore, batcherStore testBatcherStore) {
|
||||||
WithPublishDelay(publishDelay), WithClock(testClock),
|
WithPublishDelay(publishDelay), WithClock(testClock),
|
||||||
)
|
)
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -1682,23 +1652,17 @@ func testDelays(t *testing.T, store testStore, batcherStore testBatcherStore) {
|
||||||
// these actions from two separate goroutines.
|
// these actions from two separate goroutines.
|
||||||
var wg4 sync.WaitGroup
|
var wg4 sync.WaitGroup
|
||||||
|
|
||||||
wg4.Add(1)
|
wg4.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg4.Done()
|
|
||||||
|
|
||||||
// Since a batch was created we check that it registered for its
|
// Since a batch was created we check that it registered for its
|
||||||
// primary sweep's spend.
|
// primary sweep's spend.
|
||||||
<-lnd.RegisterSpendChannel
|
<-lnd.RegisterSpendChannel
|
||||||
}()
|
})
|
||||||
|
|
||||||
wg4.Add(1)
|
|
||||||
delays = nil
|
delays = nil
|
||||||
go func() {
|
wg4.Go(func() {
|
||||||
defer wg4.Done()
|
|
||||||
|
|
||||||
// Expect one timer: publishDelay (0).
|
// Expect one timer: publishDelay (0).
|
||||||
delays = append(delays, <-tickSignal)
|
delays = append(delays, <-tickSignal)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for RegisterSpend and for timer registration.
|
// Wait for RegisterSpend and for timer registration.
|
||||||
wg4.Wait()
|
wg4.Wait()
|
||||||
|
|
@ -1754,24 +1718,18 @@ func testDelays(t *testing.T, store testStore, batcherStore testBatcherStore) {
|
||||||
// parallel, so catch these actions from two separate goroutines.
|
// parallel, so catch these actions from two separate goroutines.
|
||||||
var wg5 sync.WaitGroup
|
var wg5 sync.WaitGroup
|
||||||
|
|
||||||
wg5.Add(1)
|
wg5.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg5.Done()
|
|
||||||
|
|
||||||
// Since a batch was created we check that it registered for its
|
// Since a batch was created we check that it registered for its
|
||||||
// primary sweep's spend.
|
// primary sweep's spend.
|
||||||
<-lnd.RegisterSpendChannel
|
<-lnd.RegisterSpendChannel
|
||||||
}()
|
})
|
||||||
|
|
||||||
wg5.Add(1)
|
|
||||||
delays = nil
|
delays = nil
|
||||||
go func() {
|
wg5.Go(func() {
|
||||||
defer wg5.Done()
|
|
||||||
|
|
||||||
// Expect two timer: largeInitialDelay, publishDelay.
|
// Expect two timer: largeInitialDelay, publishDelay.
|
||||||
delays = append(delays, <-tickSignal)
|
delays = append(delays, <-tickSignal)
|
||||||
delays = append(delays, <-tickSignal)
|
delays = append(delays, <-tickSignal)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for RegisterSpend and for timers' registrations.
|
// Wait for RegisterSpend and for timers' registrations.
|
||||||
wg5.Wait()
|
wg5.Wait()
|
||||||
|
|
@ -1920,13 +1878,11 @@ func testCustomDelays(t *testing.T, store testStore,
|
||||||
)
|
)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -1968,24 +1924,18 @@ func testCustomDelays(t *testing.T, store testStore,
|
||||||
// so catch these actions from two separate goroutines.
|
// so catch these actions from two separate goroutines.
|
||||||
var wg2 sync.WaitGroup
|
var wg2 sync.WaitGroup
|
||||||
|
|
||||||
wg2.Add(1)
|
wg2.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg2.Done()
|
|
||||||
|
|
||||||
// Since a batch was created we check that it registered for its
|
// Since a batch was created we check that it registered for its
|
||||||
// primary sweep's spend.
|
// primary sweep's spend.
|
||||||
<-lnd.RegisterSpendChannel
|
<-lnd.RegisterSpendChannel
|
||||||
}()
|
})
|
||||||
|
|
||||||
wg2.Add(1)
|
|
||||||
var delays []time.Duration
|
var delays []time.Duration
|
||||||
go func() {
|
wg2.Go(func() {
|
||||||
defer wg2.Done()
|
|
||||||
|
|
||||||
// Expect two timers: initialDelay and publishDelay.
|
// Expect two timers: initialDelay and publishDelay.
|
||||||
delays = append(delays, <-tickSignal)
|
delays = append(delays, <-tickSignal)
|
||||||
delays = append(delays, <-tickSignal)
|
delays = append(delays, <-tickSignal)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for RegisterSpend and for timer registrations.
|
// Wait for RegisterSpend and for timer registrations.
|
||||||
wg2.Wait()
|
wg2.Wait()
|
||||||
|
|
@ -2124,13 +2074,11 @@ func testMaxSweepsPerBatch(t *testing.T, store testStore,
|
||||||
)
|
)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -2141,7 +2089,7 @@ func testMaxSweepsPerBatch(t *testing.T, store testStore,
|
||||||
expectedBatches := (swapsNum + MaxSweepsPerBatch - 1) /
|
expectedBatches := (swapsNum + MaxSweepsPerBatch - 1) /
|
||||||
MaxSweepsPerBatch
|
MaxSweepsPerBatch
|
||||||
|
|
||||||
for i := 0; i < swapsNum; i++ {
|
for i := range swapsNum {
|
||||||
preimage := lntypes.Preimage{2, byte(i % 256), byte(i / 256)}
|
preimage := lntypes.Preimage{2, byte(i % 256), byte(i / 256)}
|
||||||
swapHash := preimage.Hash()
|
swapHash := preimage.Hash()
|
||||||
|
|
||||||
|
|
@ -2212,14 +2160,14 @@ func testMaxSweepsPerBatch(t *testing.T, store testStore,
|
||||||
|
|
||||||
// Expect mockSigner.SignOutputRaw calls to sign non-cooperative
|
// Expect mockSigner.SignOutputRaw calls to sign non-cooperative
|
||||||
// sweeps.
|
// sweeps.
|
||||||
for i := 0; i < expectedBatches; i++ {
|
for range expectedBatches {
|
||||||
<-lnd.SignOutputRawChannel
|
<-lnd.SignOutputRawChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for txs to be published.
|
// Wait for txs to be published.
|
||||||
inputsNum := 0
|
inputsNum := 0
|
||||||
const maxWeight = lntypes.WeightUnit(400_000)
|
const maxWeight = lntypes.WeightUnit(400_000)
|
||||||
for i := 0; i < expectedBatches; i++ {
|
for range expectedBatches {
|
||||||
tx := <-lnd.TxPublishChannel
|
tx := <-lnd.TxPublishChannel
|
||||||
inputsNum += len(tx.TxIn)
|
inputsNum += len(tx.TxIn)
|
||||||
|
|
||||||
|
|
@ -3226,13 +3174,11 @@ func testRestoringEmptyBatch(t *testing.T, store testStore,
|
||||||
batcherStore, sweepStore)
|
batcherStore, sweepStore)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -3407,13 +3353,11 @@ func testHandleSweepTwice(t *testing.T, backend testStore,
|
||||||
batcherStore, sweepStore)
|
batcherStore, sweepStore)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -3613,13 +3557,11 @@ func testRestoringPreservesConfTarget(t *testing.T, store testStore,
|
||||||
batcherStore, sweepStore)
|
batcherStore, sweepStore)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -3707,11 +3649,9 @@ func testRestoringPreservesConfTarget(t *testing.T, store testStore,
|
||||||
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
||||||
batcherStore, sweepStore)
|
batcherStore, sweepStore)
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -3862,13 +3802,11 @@ func testSweepFetcher(t *testing.T, store testStore,
|
||||||
WithCustomSignMuSig2(testSignMuSig2func))
|
WithCustomSignMuSig2(testSignMuSig2func))
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -3976,9 +3914,7 @@ func testSweepBatcherCloseDuringAdding(t *testing.T, store testStore,
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
// Add many sweeps.
|
// Add many sweeps.
|
||||||
for i := byte(1); i < 255; i++ {
|
for i := byte(1); i < 255; i++ {
|
||||||
// Create a sweep request.
|
// Create a sweep request.
|
||||||
|
|
@ -4007,15 +3943,13 @@ func testSweepBatcherCloseDuringAdding(t *testing.T, store testStore,
|
||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
// Close sweepbatcher during addings.
|
// Close sweepbatcher during addings.
|
||||||
time.Sleep(1 * time.Millisecond)
|
time.Sleep(1 * time.Millisecond)
|
||||||
cancel()
|
cancel()
|
||||||
}()
|
})
|
||||||
|
|
||||||
// We don't know how many spend notification registrations will be
|
// We don't know how many spend notification registrations will be
|
||||||
// issued, so accept them while waiting for two goroutines to stop.
|
// issued, so accept them while waiting for two goroutines to stop.
|
||||||
|
|
@ -4063,11 +3997,9 @@ func testSweepBatcherHandleSweepRace(t *testing.T, store testStore,
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var runErr error
|
var runErr error
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
||||||
|
|
@ -4147,10 +4079,7 @@ func testSweepBatcherHandleSweepRace(t *testing.T, store testStore,
|
||||||
confCtx, confCancel := context.WithCancel(ctx)
|
confCtx, confCancel := context.WithCancel(ctx)
|
||||||
defer confCancel()
|
defer confCancel()
|
||||||
|
|
||||||
addWG.Add(1)
|
addWG.Go(func() {
|
||||||
go func() {
|
|
||||||
defer addWG.Done()
|
|
||||||
|
|
||||||
// After this goroutine completes, stop the goroutine that
|
// After this goroutine completes, stop the goroutine that
|
||||||
// handles registrations as well. Give it one second to finish
|
// handles registrations as well. Give it one second to finish
|
||||||
// the last AddSweep to prevent goroutine leaks.
|
// the last AddSweep to prevent goroutine leaks.
|
||||||
|
|
@ -4170,7 +4099,7 @@ func testSweepBatcherHandleSweepRace(t *testing.T, store testStore,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait a bit so the AddSweep loop runs and keeps handleSweep busy.
|
// Wait a bit so the AddSweep loop runs and keeps handleSweep busy.
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
@ -4178,9 +4107,7 @@ func testSweepBatcherHandleSweepRace(t *testing.T, store testStore,
|
||||||
// This goroutine handles spending and confirmation registrations.
|
// This goroutine handles spending and confirmation registrations.
|
||||||
// One spending registration has been created above, so the loop starts
|
// One spending registration has been created above, so the loop starts
|
||||||
// with the next step - notifying about spending.
|
// with the next step - notifying about spending.
|
||||||
addWG.Add(1)
|
addWG.Go(func() {
|
||||||
go func() {
|
|
||||||
defer addWG.Done()
|
|
||||||
for {
|
for {
|
||||||
spendingTx := publishedTx
|
spendingTx := publishedTx
|
||||||
spendingHash := spendingTx.TxHash()
|
spendingHash := spendingTx.TxHash()
|
||||||
|
|
@ -4230,7 +4157,7 @@ func testSweepBatcherHandleSweepRace(t *testing.T, store testStore,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
addWG.Wait()
|
addWG.Wait()
|
||||||
|
|
||||||
|
|
@ -4596,12 +4523,10 @@ func TestSweepBatcherConfirmedBatchIncompleteSweeps(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx1)
|
runErr = batcher.Run(ctx1)
|
||||||
}()
|
})
|
||||||
|
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
||||||
|
|
@ -4661,13 +4586,11 @@ func testCustomSignMuSig2(t *testing.T, store testStore,
|
||||||
sweepStore, WithCustomSignMuSig2(testSignMuSig2func))
|
sweepStore, WithCustomSignMuSig2(testSignMuSig2func))
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -4786,13 +4709,11 @@ func testWithMixedBatch(t *testing.T, store testStore,
|
||||||
)
|
)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
@ -4969,13 +4890,11 @@ func testWithMixedBatchCustom(t *testing.T, store testStore,
|
||||||
)
|
)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
var runErr error
|
var runErr error
|
||||||
go func() {
|
wg.Go(func() {
|
||||||
defer wg.Done()
|
|
||||||
runErr = batcher.Run(ctx)
|
runErr = batcher.Run(ctx)
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Wait for the batcher to be initialized.
|
// Wait for the batcher to be initialized.
|
||||||
<-batcher.initDone
|
<-batcher.initDone
|
||||||
|
|
|
||||||
|
|
@ -71,10 +71,7 @@ func (c *mockChainNotifier) RegisterSpendNtfn(ctx context.Context,
|
||||||
spendChan := make(chan *chainntnfs.SpendDetail, 1)
|
spendChan := make(chan *chainntnfs.SpendDetail, 1)
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
|
|
||||||
c.wg.Add(1)
|
c.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer c.wg.Done()
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case m := <-c.lnd.SpendChannel:
|
case m := <-c.lnd.SpendChannel:
|
||||||
select {
|
select {
|
||||||
|
|
@ -96,7 +93,7 @@ func (c *mockChainNotifier) RegisterSpendNtfn(ctx context.Context,
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
return spendChan, errChan, nil
|
return spendChan, errChan, nil
|
||||||
}
|
}
|
||||||
|
|
@ -117,13 +114,11 @@ func (c *mockChainNotifier) RegisterBlockEpochNtfn(ctx context.Context) (
|
||||||
)
|
)
|
||||||
c.lnd.lock.Unlock()
|
c.lnd.lock.Unlock()
|
||||||
|
|
||||||
c.wg.Add(1)
|
c.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer c.wg.Done()
|
|
||||||
defer func() {
|
defer func() {
|
||||||
c.lnd.lock.Lock()
|
c.lnd.lock.Lock()
|
||||||
defer c.lnd.lock.Unlock()
|
defer c.lnd.lock.Unlock()
|
||||||
for i := 0; i < len(c.lnd.blockHeightListeners); i++ {
|
for i := range len(c.lnd.blockHeightListeners) {
|
||||||
if c.lnd.blockHeightListeners[i] == blockEpochChan {
|
if c.lnd.blockHeightListeners[i] == blockEpochChan {
|
||||||
c.lnd.blockHeightListeners = append(
|
c.lnd.blockHeightListeners = append(
|
||||||
c.lnd.blockHeightListeners[:i],
|
c.lnd.blockHeightListeners[:i],
|
||||||
|
|
@ -143,7 +138,7 @@ func (c *mockChainNotifier) RegisterBlockEpochNtfn(ctx context.Context) (
|
||||||
c.lnd.lock.Unlock()
|
c.lnd.lock.Unlock()
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
}()
|
})
|
||||||
|
|
||||||
return blockEpochChan, blockErrorChan, nil
|
return blockEpochChan, blockErrorChan, nil
|
||||||
}
|
}
|
||||||
|
|
@ -170,10 +165,7 @@ func (c *mockChainNotifier) RegisterConfirmationsNtfn(ctx context.Context,
|
||||||
|
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
|
|
||||||
c.wg.Add(1)
|
c.wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer c.wg.Done()
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case m := <-c.lnd.ConfChannel:
|
case m := <-c.lnd.ConfChannel:
|
||||||
c.Lock()
|
c.Lock()
|
||||||
|
|
@ -205,7 +197,7 @@ func (c *mockChainNotifier) RegisterConfirmationsNtfn(ctx context.Context,
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case c.lnd.RegisterConfChannel <- reg:
|
case c.lnd.RegisterConfChannel <- reg:
|
||||||
|
|
|
||||||
|
|
@ -280,9 +280,7 @@ func (h *mockLightningClient) ListPayments(_ context.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
lastIndexOffset := req.Offset + req.MaxPayments
|
lastIndexOffset := req.Offset + req.MaxPayments
|
||||||
if lastIndexOffset > uint64(len(h.lnd.Payments)) {
|
lastIndexOffset = min(lastIndexOffset, uint64(len(h.lnd.Payments)))
|
||||||
lastIndexOffset = uint64(len(h.lnd.Payments))
|
|
||||||
}
|
|
||||||
|
|
||||||
result := h.lnd.Payments[req.Offset:lastIndexOffset]
|
result := h.lnd.Payments[req.Offset:lastIndexOffset]
|
||||||
|
|
||||||
|
|
|
||||||
2
utils.go
2
utils.go
|
|
@ -438,7 +438,7 @@ func invoicesrpcSelectHopHints(amtMSat lnwire.MilliSatoshi, cfg *SelectHopHintsC
|
||||||
// or if the sum of available bandwidth in the routing hints exceeds 2x
|
// or if the sum of available bandwidth in the routing hints exceeds 2x
|
||||||
// the payment amount. We do 2x here to account for a margin of error
|
// the payment amount. We do 2x here to account for a margin of error
|
||||||
// if some of the selected channels no longer become operable.
|
// if some of the selected channels no longer become operable.
|
||||||
for i := 0; i < len(openChannels); i++ {
|
for i := range len(openChannels) {
|
||||||
enoughHopHints := sufficientHints(
|
enoughHopHints := sufficientHints(
|
||||||
len(hopHints), numMaxHophints, hopHintFactor, amtMSat,
|
len(hopHints), numMaxHophints, hopHintFactor, amtMSat,
|
||||||
totalHintBandwidth,
|
totalHintBandwidth,
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ func MuSig2Sign(version input.MuSig2Version, privKeys []*btcec.PrivateKey,
|
||||||
|
|
||||||
// Next we'll pass around all public nonces to all MuSig2 sessions so
|
// Next we'll pass around all public nonces to all MuSig2 sessions so
|
||||||
// that they become usable for creating the partial signatures.
|
// that they become usable for creating the partial signatures.
|
||||||
for i := 0; i < len(privKeys); i++ {
|
for i := range len(privKeys) {
|
||||||
nonce := sessions[i].PublicNonce()
|
nonce := sessions[i].PublicNonce()
|
||||||
|
|
||||||
for j := 0; j < len(privKeys); j++ {
|
for j := range len(privKeys) {
|
||||||
if i == j {
|
if i == j {
|
||||||
// Step over if it's the same session.
|
// Step over if it's the same session.
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue