Skip to content

Commit 4fc175f

Browse files
authored
Merge pull request #602 from hieblmi/loopin-typos
loopin: fix typos
2 parents 32d48d3 + c8848a2 commit 4fc175f

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed

loopin.go

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,26 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
8686

8787
var err error
8888

89-
// Private and routehints are mutually exclusive as setting private
90-
// means we retrieve our own routehints from the connected node.
89+
// Private and route hints are mutually exclusive as setting private
90+
// means we retrieve our own route hints from the connected node.
9191
if len(request.RouteHints) != 0 && request.Private {
9292
return nil, fmt.Errorf("private and route_hints both set")
9393
}
9494

95-
// If Private is set, we generate route hints
95+
// If Private is set, we generate route hints.
9696
if request.Private {
97-
// If last_hop is set, we'll only add channels with peers
98-
// set to the last_hop parameter
97+
// If last_hop is set, we'll only add channels with peers set to
98+
// the last_hop parameter.
9999
includeNodes := make(map[route.Vertex]struct{})
100100
if request.LastHop != nil {
101101
includeNodes[*request.LastHop] = struct{}{}
102102
}
103103

104-
// Because the Private flag is set, we'll generate our own
105-
// set of hop hints
104+
// Because the Private flag is set, we'll generate our own set
105+
// of hop hints.
106106
request.RouteHints, err = SelectHopHints(
107-
globalCtx, cfg.lnd, request.Amount, DefaultMaxHopHints, includeNodes,
107+
globalCtx, cfg.lnd, request.Amount, DefaultMaxHopHints,
108+
includeNodes,
108109
)
109110
if err != nil {
110111
return nil, err
@@ -115,9 +116,9 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
115116
// swap fee that we should subtract from the swap amount in the payment
116117
// request that we send to the server. We pass nil as optional route
117118
// hints as hop hint selection when generating invoices with private
118-
// channels is an LND side black box feaure. Advanced users will quote
119-
// directly anyway and there they have the option to add specific
120-
// route hints.
119+
// channels is an LND side black box feature. Advanced users will quote
120+
// directly anyway and there they have the option to add specific route
121+
// hints.
121122
quote, err := cfg.server.GetLoopInQuote(
122123
globalCtx, request.Amount, cfg.lnd.NodePubkey, request.LastHop,
123124
request.RouteHints,
@@ -194,8 +195,8 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
194195
// Default the HTLC internal key to our sender key.
195196
senderInternalPubKey := senderKey
196197

197-
// If this is a MuSig2 swap then we'll generate a brand new key pair
198-
// and will use that as the internal key for the HTLC.
198+
// If this is a MuSig2 swap then we'll generate a brand new key pair and
199+
// will use that as the internal key for the HTLC.
199200
if loopdb.CurrentProtocolVersion() >= loopdb.ProtocolVersionMuSig2 {
200201
secret, err := sharedSecretFromHash(
201202
globalCtx, cfg.lnd.Signer, swapHash,
@@ -238,8 +239,8 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
238239
return nil, fmt.Errorf("probe error: %v", err)
239240
}
240241

241-
// Validate the response parameters the prevent us continuing with a
242-
// swap that is based on parameters outside our allowed range.
242+
// Validate if the response parameters are outside our allowed range
243+
// preventing us from continuing with a swap.
243244
err = validateLoopInContract(currentHeight, swapResp)
244245
if err != nil {
245246
return nil, err
@@ -415,10 +416,9 @@ func resumeLoopInSwap(_ context.Context, cfg *swapConfig,
415416
return swap, nil
416417
}
417418

418-
// validateLoopInContract validates the contract parameters against our
419-
// request.
419+
// validateLoopInContract validates the contract parameters against our request.
420420
func validateLoopInContract(height int32, response *newLoopInResponse) error {
421-
// Verify that we are not forced to publish an htlc that locks up our
421+
// Verify that we are not forced to publish a htlc that locks up our
422422
// funds for too long in case the server doesn't follow through.
423423
if response.expiry-height > MaxLoopInAcceptDelta {
424424
return ErrExpiryTooFar
@@ -427,8 +427,8 @@ func validateLoopInContract(height int32, response *newLoopInResponse) error {
427427
return nil
428428
}
429429

430-
// initHtlcs creates and updates the native and nested segwit htlcs
431-
// of the loopInSwap.
430+
// initHtlcs creates and updates the native and nested segwit htlcs of the
431+
// loopInSwap.
432432
func (s *loopInSwap) initHtlcs() error {
433433
htlc, err := GetHtlc(
434434
s.hash, &s.SwapContract, s.swapKit.lnd.ChainParams,
@@ -467,8 +467,8 @@ func (s *loopInSwap) sendUpdate(ctx context.Context) error {
467467

468468
info.ExternalHtlc = s.ExternalHtlc
469469

470-
// In order to avoid potentially dangerous ownership sharing
471-
// we copy the last hop vertex.
470+
// In order to avoid potentially dangerous ownership sharing we copy the
471+
// last hop vertex.
472472
if s.LastHop != nil {
473473
lastHop := &route.Vertex{}
474474
copy(lastHop[:], s.LastHop[:])
@@ -524,15 +524,15 @@ func (s *loopInSwap) execute(mainCtx context.Context,
524524
err = fmt.Errorf("swap in non-final state %v", s.state)
525525
}
526526

527-
// If an unexpected error happened, report a temporary failure
528-
// but don't persist the error. Otherwise for example a
529-
// connection error could lead to abandoning the swap
530-
// permanently and losing funds.
527+
// If an unexpected error happened, report a temporary failure but don't
528+
// persist the error. Otherwise, for example a connection error could
529+
// lead to abandoning the swap permanently and losing funds.
531530
if err != nil {
532531
s.log.Errorf("Swap error: %v", err)
533532
s.setState(loopdb.StateFailTemporary)
534533

535-
// If we cannot send out this update, there is nothing we can do.
534+
// If we cannot send out this update, there is nothing we can
535+
// do.
536536
_ = s.sendUpdate(mainCtx)
537537

538538
return err
@@ -554,7 +554,7 @@ func (s *loopInSwap) executeSwap(globalCtx context.Context) error {
554554
var err error
555555

556556
// For loop in, the client takes the first step by publishing the
557-
// on-chain htlc. Only do this is we haven't already done so in a
557+
// on-chain htlc. Only do this if we haven't already done so in a
558558
// previous run.
559559
if s.state == loopdb.StateInitiated {
560560
if s.ExternalHtlc {
@@ -577,7 +577,7 @@ func (s *loopInSwap) executeSwap(globalCtx context.Context) error {
577577
}
578578
}
579579

580-
// Wait for the htlc to confirm. After a restart this will pick up a
580+
// Wait for the htlc to confirm. After a restart, this will pick up a
581581
// previously published tx.
582582
conf, err := s.waitForHtlcConf(globalCtx)
583583
if err != nil {
@@ -593,17 +593,17 @@ func (s *loopInSwap) executeSwap(globalCtx context.Context) error {
593593
}
594594

595595
// Verify that the confirmed (external) htlc value matches the swap
596-
// amount. Otherwise fail the swap immediately.
596+
// amount. Otherwise, fail the swap immediately.
597597
if htlcValue != s.LoopInContract.AmountRequested {
598598
s.setState(loopdb.StateFailIncorrectHtlcAmt)
599599
return s.persistAndAnnounceState(globalCtx)
600600
}
601601

602-
// The server is expected to see the htlc on-chain and knowing that it
603-
// can sweep that htlc with the preimage, it should pay our swap
604-
// invoice, receive the preimage and sweep the htlc. We are waiting for
605-
// this to happen and simultaneously watch the htlc expiry height. When
606-
// the htlc expires, we will publish a timeout tx to reclaim the funds.
602+
// The server is expected to see the htlc on-chain and know that it can
603+
// sweep that htlc with the preimage, it should pay our swap invoice,
604+
// receive the preimage and sweep the htlc. We are waiting for this to
605+
// happen and simultaneously watch the htlc expiry height. When the htlc
606+
// expires, we will publish a timeout tx to reclaim the funds.
607607
err = s.waitForSwapComplete(globalCtx, htlcOutpoint, htlcValue)
608608
if err != nil {
609609
return err
@@ -623,8 +623,8 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) (
623623

624624
// Register for confirmation of the htlc. It is essential to specify not
625625
// just the pk script, because an attacker may publish the same htlc
626-
// with a lower value and we don't want to follow through with that tx.
627-
// In the unlikely event that our call to SendOutputs crashes and we
626+
// with a lower value, and we don't want to follow through with that tx.
627+
// In the unlikely event that our call to SendOutputs crashes, and we
628628
// restart, htlcTxHash will be nil at this point. Then only register
629629
// with PkScript and accept the risk that the call triggers on a
630630
// different htlc outpoint.
@@ -765,9 +765,6 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
765765
// Persist the htlc hash so that after a restart we are still waiting
766766
// for our own htlc. We don't need to announce to clients, because the
767767
// state remains unchanged.
768-
//
769-
// TODO(joostjager): Store tx hash before calling SendOutputs. This is
770-
// not yet possible with the current lnd api.
771768
s.htlcTxHash = &txHash
772769

773770
// We do not expect any on-chain fees to be recorded yet, and we only
@@ -940,9 +937,9 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
940937
}
941938

942939
// tryPushHtlcKey attempts to push the htlc key to the server. If the server
943-
// returns an error of any kind we'll log it as a warning but won't act as
944-
// the swap execution can just go on without the server gaining knowledge of
945-
// our internal key.
940+
// returns an error of any kind we'll log it as a warning but won't act as the
941+
// swap execution can just go on without the server gaining knowledge of our
942+
// internal key.
946943
func (s *loopInSwap) tryPushHtlcKey(ctx context.Context) bool {
947944
if s.ProtocolVersion < loopdb.ProtocolVersionMuSig2 {
948945
return false
@@ -1022,7 +1019,7 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
10221019
}
10231020
}
10241021

1025-
// Calculate sweep tx fee
1022+
// Calculate sweep tx fee.
10261023
fee, err := s.sweeper.GetSweepFee(
10271024
ctx, s.htlc.AddTimeoutToEstimator, s.timeoutAddr,
10281025
TimeoutTxConfTarget,

0 commit comments

Comments
 (0)