Skip to content

Commit ac8f146

Browse files
authored
Merge pull request #739 from hieblmi/static-addr-staging
Rebase static-addr staging
2 parents 174e598 + ce6c2e7 commit ac8f146

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
152152
LndServices: cfg.Lnd,
153153
Server: swapServerClient,
154154
Conn: swapServerClient.conn,
155-
Store: loopDB,
156155
L402Store: l402Store,
156+
Store: loopDB,
157157
CreateExpiryTimer: func(d time.Duration) <-chan time.Time {
158158
return time.NewTimer(d).C
159159
},

loopd/daemon.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type ListenerCfg struct {
5353
// on the passed TLS configuration.
5454
restListener func(*tls.Config) (net.Listener, error)
5555

56-
// getLnd returns a grpc connection to an lnd instance.
56+
// getLnd returns a grpc connection to a lnd instance.
5757
getLnd func(lndclient.Network, *lndConfig) (*lndclient.GrpcLndServices,
5858
error)
5959
}
@@ -120,9 +120,9 @@ func New(config *Config, lisCfg *ListenerCfg) *Daemon {
120120
// Start starts loopd in daemon mode. It will listen for grpc connections,
121121
// execute commands and pass back swap status information.
122122
func (d *Daemon) Start() error {
123-
// There should be no reason to start the daemon twice. Therefore return
124-
// an error if that's tried. This is mostly to guard against Start and
125-
// StartAsSubserver both being called.
123+
// There should be no reason to start the daemon twice. Therefore,
124+
// return an error if that's tried. This is mostly to guard against
125+
// Start and StartAsSubserver both being called.
126126
if atomic.AddInt32(&d.started, 1) != 1 {
127127
return errOnlyStartOnce
128128
}
@@ -137,7 +137,7 @@ func (d *Daemon) Start() error {
137137

138138
// With lnd connected, initialize everything else, such as the swap
139139
// server client, the swap client RPC server instance and our main swap
140-
// and error handlers. If this fails, then nothing has been started yet
140+
// and error handlers. If this fails, then nothing has been started yet,
141141
// and we can just return the error.
142142
err = d.initialize(true)
143143
if errors.Is(err, bbolt.ErrTimeout) {
@@ -324,7 +324,7 @@ func (d *Daemon) startWebServers() error {
324324
err := d.restServer.Serve(d.restListener)
325325
// ErrServerClosed is always returned when the proxy is
326326
// shut down, so don't log it.
327-
if err != nil && err != http.ErrServerClosed {
327+
if err != nil && !errors.Is(err, http.ErrServerClosed) {
328328
// Notify the main error handler goroutine that
329329
// we exited unexpectedly here. We don't have to
330330
// worry about blocking as the internal error
@@ -343,7 +343,7 @@ func (d *Daemon) startWebServers() error {
343343

344344
log.Infof("RPC server listening on %s", d.grpcListener.Addr())
345345
err = d.grpcServer.Serve(d.grpcListener)
346-
if err != nil && err != grpc.ErrServerStopped {
346+
if err != nil && !errors.Is(err, grpc.ErrServerStopped) {
347347
// Notify the main error handler goroutine that
348348
// we exited unexpectedly here. We don't have to
349349
// worry about blocking as the internal error
@@ -719,9 +719,9 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
719719
var runtimeErr error
720720

721721
// There are only two ways this goroutine can exit. Either there
722-
// is an internal error or the caller requests shutdown. In both
723-
// cases we wait for the stop to complete before we signal the
724-
// caller that we're done.
722+
// is an internal error or the caller requests a shutdown.
723+
// In both cases we wait for the stop to complete before we
724+
// signal the caller that we're done.
725725
select {
726726
case runtimeErr = <-d.internalErrChan:
727727
log.Errorf("Runtime error in daemon, shutting down: "+
@@ -730,7 +730,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
730730
case <-d.quit:
731731
}
732732

733-
// We need to shutdown before sending the error on the channel,
733+
// We need to shut down before sending the error on the channel,
734734
// otherwise a caller might exit the process too early.
735735
d.stop()
736736
cleanupMacaroonStore()
@@ -761,7 +761,7 @@ func (d *Daemon) stop() {
761761
d.mainCtxCancel()
762762
}
763763

764-
// As there is no swap activity anymore, we can forcefully shutdown the
764+
// As there is no swap activity anymore, we can forcefully shut down the
765765
// gRPC and HTTP servers now.
766766
log.Infof("Stopping gRPC server")
767767
if d.grpcServer != nil {

sweepbatcher/sweep_batch.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sweepbatcher
33
import (
44
"bytes"
55
"context"
6+
"encoding/hex"
67
"fmt"
78
"math"
89
"sync"
@@ -700,9 +701,11 @@ func (b *batch) publishBatch(ctx context.Context) (btcutil.Amount, error) {
700701
batchTx.TxIn[i].Witness = witness
701702
}
702703

703-
b.log.Debugf("attempting to publish non-coop tx with feerate=%v, "+
704-
"totalfee=%v, sweeps=%v, destAddr=%s", b.rbfCache.FeeRate, fee,
705-
len(batchTx.TxIn), address.String())
704+
b.log.Infof("attempting to publish non-coop tx=%v with feerate=%v, "+
705+
"totalfee=%v, sweeps=%d, destAddr=%s", batchTx.TxHash(),
706+
b.rbfCache.FeeRate, fee, len(batchTx.TxIn), address)
707+
708+
b.debugLogTx("serialized non-coop sweep", batchTx)
706709

707710
err = b.wallet.PublishTransaction(
708711
ctx, batchTx, labels.LoopOutBatchSweepSuccess(b.id),
@@ -846,9 +849,11 @@ func (b *batch) publishBatchCoop(ctx context.Context) (btcutil.Amount,
846849
return fee, err, false
847850
}
848851

849-
b.log.Debugf("attempting to publish coop tx with feerate=%v, "+
850-
"totalfee=%v, sweeps=%v, destAddr=%s", b.rbfCache.FeeRate, fee,
851-
len(batchTx.TxIn), address.String())
852+
b.log.Infof("attempting to publish coop tx=%v with feerate=%v, "+
853+
"totalfee=%v, sweeps=%d, destAddr=%s", batchTx.TxHash(),
854+
b.rbfCache.FeeRate, fee, len(batchTx.TxIn), address)
855+
856+
b.debugLogTx("serialized coop sweep", batchTx)
852857

853858
err = b.wallet.PublishTransaction(
854859
ctx, batchTx, labels.LoopOutBatchSweepSuccess(b.id),
@@ -866,6 +871,17 @@ func (b *batch) publishBatchCoop(ctx context.Context) (btcutil.Amount,
866871
return fee, nil, true
867872
}
868873

874+
func (b *batch) debugLogTx(msg string, tx *wire.MsgTx) {
875+
// Serialize the transaction and convert to hex string.
876+
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
877+
if err := tx.Serialize(buf); err != nil {
878+
b.log.Errorf("failed to serialize tx for debug log: %v", err)
879+
return
880+
}
881+
882+
b.log.Debugf("%s: %s", msg, hex.EncodeToString(buf.Bytes()))
883+
}
884+
869885
// coopSignBatchTx collects the necessary signatures from the server in order
870886
// to cooperatively sweep the funds.
871887
func (b *batch) coopSignBatchTx(ctx context.Context, packet *psbt.Packet,

0 commit comments

Comments
 (0)