Skip to content

Commit 2cbc2ff

Browse files
authored
Merge pull request #622 from hieblmi/trivial-cleanup
trivial: clean up typos and comments
2 parents 24987dd + 2031604 commit 2cbc2ff

File tree

5 files changed

+43
-43
lines changed

5 files changed

+43
-43
lines changed

client.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
272272
// restored from persistent storage and resumed. Subsequent updates will be
273273
// sent through the passed in statusChan. The function can be terminated by
274274
// cancelling the context.
275-
func (s *Client) Run(ctx context.Context,
276-
statusChan chan<- SwapInfo) error {
277-
275+
func (s *Client) Run(ctx context.Context, statusChan chan<- SwapInfo) error {
278276
if !atomic.CompareAndSwapUint32(&s.started, 0, 1) {
279277
return errors.New("swap client can only be started once")
280278
}
@@ -284,7 +282,7 @@ func (s *Client) Run(ctx context.Context,
284282
s.lndServices.NodeAlias, s.lndServices.NodePubkey,
285283
lndclient.VersionString(s.lndServices.Version))
286284

287-
// Setup main context used for cancelation.
285+
// Setup main context used for cancellation.
288286
mainCtx, mainCancel := context.WithCancel(ctx)
289287
defer mainCancel()
290288

@@ -307,7 +305,7 @@ func (s *Client) Run(ctx context.Context,
307305

308306
s.resumeSwaps(mainCtx, pendingLoopOutSwaps, pendingLoopInSwaps)
309307

310-
// Signal that new requests can be accepted. Otherwise the new
308+
// Signal that new requests can be accepted. Otherwise, the new
311309
// swap could already have been added to the store and read in
312310
// this goroutine as being a swap that needs to be resumed.
313311
// Resulting in two goroutines executing the same swap.

executor.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,35 @@ func (s *executor) run(mainCtx context.Context,
7171
for {
7272
blockEpochChan, blockErrorChan, err =
7373
s.lnd.ChainNotifier.RegisterBlockEpochNtfn(mainCtx)
74-
if err != nil {
75-
if strings.Contains(err.Error(),
76-
"in the process of starting") {
7774

78-
log.Warnf("LND chain notifier server not " +
79-
"ready yet, retrying with delay")
75+
if err == nil {
76+
break
77+
}
8078

81-
// Give chain notifier some time to start and
82-
// try to re-attempt block epoch subscription.
83-
select {
84-
case <-time.After(500 * time.Millisecond):
85-
continue
79+
if strings.Contains(err.Error(),
80+
"in the process of starting") {
8681

87-
case <-mainCtx.Done():
88-
return err
89-
}
90-
}
82+
log.Warnf("LND chain notifier server not ready yet, " +
83+
"retrying with delay")
84+
85+
// Give chain notifier some time to start and try to
86+
// re-attempt block epoch subscription.
87+
select {
88+
case <-time.After(500 * time.Millisecond):
89+
continue
9190

92-
return err
91+
case <-mainCtx.Done():
92+
return err
93+
}
9394
}
9495

95-
break
96+
return err
9697
}
9798

98-
// Before starting, make sure we have an up to date block height.
99-
// Otherwise we might reveal a preimage for a swap that is already
99+
// Before starting, make sure we have an up-to-date block height.
100+
// Otherwise, we might reveal a preimage for a swap that is already
100101
// expired.
101-
log.Infof("Wait for first block ntfn")
102+
log.Infof("Wait for first block notification")
102103

103104
var height int32
104105
setHeight := func(h int32) {
@@ -118,7 +119,7 @@ func (s *executor) run(mainCtx context.Context,
118119
// Start main event loop.
119120
log.Infof("Starting event loop at height %v", height)
120121

121-
// Signal that executor being ready with an up to date block height.
122+
// Signal that executor being ready with an up-to-date block height.
122123
close(s.ready)
123124

124125
// Use a map to administer the individual notification queues for the

loopd/daemon.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func New(config *Config, lisCfg *ListenerCfg) *Daemon {
9595
// We send exactly one error on this channel if something goes
9696
// wrong at runtime. Or a nil value if the shutdown was
9797
// successful. But in case nobody's listening, we don't want to
98-
// block on it so we buffer it.
98+
// block on it, so we buffer it.
9999
ErrChan: make(chan error, 1),
100100

101101
quit: make(chan struct{}),
@@ -135,9 +135,9 @@ func (d *Daemon) Start() error {
135135
if errors.Is(err, bbolt.ErrTimeout) {
136136
// We're trying to be started as a standalone Loop daemon, most
137137
// likely LiT is already running and blocking the DB
138-
return fmt.Errorf("%v: make sure no other loop daemon "+
139-
"process (standalone or embedded in "+
140-
"lightning-terminal) is running", err)
138+
return fmt.Errorf("%v: make sure no other loop daemon process "+
139+
"(standalone or embedded in lightning-terminal) is"+
140+
"running", err)
141141
}
142142
if err != nil {
143143
return err
@@ -166,9 +166,9 @@ func (d *Daemon) Start() error {
166166
func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices,
167167
withMacaroonService bool) error {
168168

169-
// There should be no reason to start the daemon twice. Therefore return
170-
// an error if that's tried. This is mostly to guard against Start and
171-
// StartAsSubserver both being called.
169+
// There should be no reason to start the daemon twice. Therefore,
170+
// return an error if that's tried. This is mostly to guard against
171+
// Start and StartAsSubserver both being called.
172172
if atomic.AddInt32(&d.started, 1) != 1 {
173173
return errOnlyStartOnce
174174
}
@@ -179,8 +179,8 @@ func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices,
179179

180180
// With lnd already pre-connected, initialize everything else, such as
181181
// the swap server client, the RPC server instance and our main swap
182-
// handlers. If this fails, then nothing has been started yet and we can
183-
// just return the error.
182+
// handlers. If this fails, then nothing has been started yet, and we
183+
// can just return the error.
184184
err := d.initialize(withMacaroonService)
185185
if errors.Is(err, bbolt.ErrTimeout) {
186186
// We're trying to be started inside LiT so there most likely is
@@ -370,8 +370,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
370370
}
371371
}
372372

373-
// Both the client RPC server and and the swap server client should
374-
// stop on main context cancel. So we create it early and pass it down.
373+
// Both the client RPC server and the swap server client should stop
374+
// on main context cancel. So we create it early and pass it down.
375375
d.mainCtx, d.mainCtxCancel = context.WithCancel(context.Background())
376376

377377
log.Infof("Swap server address: %v", d.cfg.Server.Host)

loopd/swapclient_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ func (s *swapClientServer) LoopOutQuote(ctx context.Context,
561561
}, nil
562562
}
563563

564-
// GetTerms returns the terms that the server enforces for swaps.
564+
// GetLoopInTerms returns the terms that the server enforces for swaps.
565565
func (s *swapClientServer) GetLoopInTerms(ctx context.Context,
566566
req *clientrpc.TermsRequest) (*clientrpc.InTermsResponse, error) {
567567

@@ -579,7 +579,7 @@ func (s *swapClientServer) GetLoopInTerms(ctx context.Context,
579579
}, nil
580580
}
581581

582-
// GetQuote returns a quote for a swap with the provided parameters.
582+
// GetLoopInQuote returns a quote for a swap with the provided parameters.
583583
func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
584584
req *clientrpc.QuoteRequest) (*clientrpc.InQuoteResponse, error) {
585585

loopin.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,9 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
817817
return fmt.Errorf("subscribe to swap invoice: %v", err)
818818
}
819819

820-
// checkTimeout publishes the timeout tx if the contract has expired.
821-
checkTimeout := func() (btcutil.Amount, error) {
820+
// publishTxOnTimeout publishes the timeout tx if the contract has
821+
// expired.
822+
publishTxOnTimeout := func() (btcutil.Amount, error) {
822823
if s.height >= s.LoopInContract.CltvExpiry {
823824
return s.publishTimeoutTx(ctx, htlcOutpoint, htlcValue)
824825
}
@@ -829,7 +830,7 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
829830
// Check timeout at current height. After a restart we may want to
830831
// publish the tx immediately.
831832
var sweepFee btcutil.Amount
832-
sweepFee, err = checkTimeout()
833+
sweepFee, err = publishTxOnTimeout()
833834
if err != nil {
834835
return err
835836
}
@@ -848,7 +849,7 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
848849
case notification := <-s.blockEpochChan:
849850
s.height = notification.(int32)
850851

851-
sweepFee, err = checkTimeout()
852+
sweepFee, err = publishTxOnTimeout()
852853
if err != nil {
853854
return err
854855
}
@@ -971,7 +972,7 @@ func (s *loopInSwap) processHtlcSpend(ctx context.Context,
971972
sweepFee btcutil.Amount) error {
972973

973974
// Determine the htlc input of the spending tx and inspect the witness
974-
// to findout whether a success or a timeout tx spend the htlc.
975+
// to find out whether a success or a timeout tx spent the htlc.
975976
htlcInput := spend.SpendingTx.TxIn[spend.SpenderInputIndex]
976977

977978
if s.htlc.IsSuccessWitness(htlcInput.Witness) {

0 commit comments

Comments
 (0)