loopin: fix typos

pull/602/head
Slyghtning 11 months ago
parent 32d48d3854
commit c8848a2e46
No known key found for this signature in database
GPG Key ID: F82D456EA023C9BF

@ -86,25 +86,26 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
var err error var err error
// Private and routehints are mutually exclusive as setting private // Private and route hints are mutually exclusive as setting private
// means we retrieve our own routehints from the connected node. // means we retrieve our own route hints from the connected node.
if len(request.RouteHints) != 0 && request.Private { if len(request.RouteHints) != 0 && request.Private {
return nil, fmt.Errorf("private and route_hints both set") return nil, fmt.Errorf("private and route_hints both set")
} }
// If Private is set, we generate route hints // If Private is set, we generate route hints.
if request.Private { if request.Private {
// If last_hop is set, we'll only add channels with peers // If last_hop is set, we'll only add channels with peers set to
// set to the last_hop parameter // the last_hop parameter.
includeNodes := make(map[route.Vertex]struct{}) includeNodes := make(map[route.Vertex]struct{})
if request.LastHop != nil { if request.LastHop != nil {
includeNodes[*request.LastHop] = struct{}{} includeNodes[*request.LastHop] = struct{}{}
} }
// Because the Private flag is set, we'll generate our own // Because the Private flag is set, we'll generate our own set
// set of hop hints // of hop hints.
request.RouteHints, err = SelectHopHints( request.RouteHints, err = SelectHopHints(
globalCtx, cfg.lnd, request.Amount, DefaultMaxHopHints, includeNodes, globalCtx, cfg.lnd, request.Amount, DefaultMaxHopHints,
includeNodes,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -115,9 +116,9 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
// swap fee that we should subtract from the swap amount in the payment // swap fee that we should subtract from the swap amount in the payment
// request that we send to the server. We pass nil as optional route // request that we send to the server. We pass nil as optional route
// hints as hop hint selection when generating invoices with private // hints as hop hint selection when generating invoices with private
// channels is an LND side black box feaure. Advanced users will quote // channels is an LND side black box feature. Advanced users will quote
// directly anyway and there they have the option to add specific // directly anyway and there they have the option to add specific route
// route hints. // hints.
quote, err := cfg.server.GetLoopInQuote( quote, err := cfg.server.GetLoopInQuote(
globalCtx, request.Amount, cfg.lnd.NodePubkey, request.LastHop, globalCtx, request.Amount, cfg.lnd.NodePubkey, request.LastHop,
request.RouteHints, request.RouteHints,
@ -194,8 +195,8 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
// Default the HTLC internal key to our sender key. // Default the HTLC internal key to our sender key.
senderInternalPubKey := senderKey senderInternalPubKey := senderKey
// If this is a MuSig2 swap then we'll generate a brand new key pair // If this is a MuSig2 swap then we'll generate a brand new key pair and
// and will use that as the internal key for the HTLC. // will use that as the internal key for the HTLC.
if loopdb.CurrentProtocolVersion() >= loopdb.ProtocolVersionMuSig2 { if loopdb.CurrentProtocolVersion() >= loopdb.ProtocolVersionMuSig2 {
secret, err := sharedSecretFromHash( secret, err := sharedSecretFromHash(
globalCtx, cfg.lnd.Signer, swapHash, globalCtx, cfg.lnd.Signer, swapHash,
@ -238,8 +239,8 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
return nil, fmt.Errorf("probe error: %v", err) return nil, fmt.Errorf("probe error: %v", err)
} }
// Validate the response parameters the prevent us continuing with a // Validate if the response parameters are outside our allowed range
// swap that is based on parameters outside our allowed range. // preventing us from continuing with a swap.
err = validateLoopInContract(currentHeight, swapResp) err = validateLoopInContract(currentHeight, swapResp)
if err != nil { if err != nil {
return nil, err return nil, err
@ -415,10 +416,9 @@ func resumeLoopInSwap(_ context.Context, cfg *swapConfig,
return swap, nil return swap, nil
} }
// validateLoopInContract validates the contract parameters against our // validateLoopInContract validates the contract parameters against our request.
// request.
func validateLoopInContract(height int32, response *newLoopInResponse) error { func validateLoopInContract(height int32, response *newLoopInResponse) error {
// Verify that we are not forced to publish an htlc that locks up our // Verify that we are not forced to publish a htlc that locks up our
// funds for too long in case the server doesn't follow through. // funds for too long in case the server doesn't follow through.
if response.expiry-height > MaxLoopInAcceptDelta { if response.expiry-height > MaxLoopInAcceptDelta {
return ErrExpiryTooFar return ErrExpiryTooFar
@ -427,8 +427,8 @@ func validateLoopInContract(height int32, response *newLoopInResponse) error {
return nil return nil
} }
// initHtlcs creates and updates the native and nested segwit htlcs // initHtlcs creates and updates the native and nested segwit htlcs of the
// of the loopInSwap. // loopInSwap.
func (s *loopInSwap) initHtlcs() error { func (s *loopInSwap) initHtlcs() error {
htlc, err := GetHtlc( htlc, err := GetHtlc(
s.hash, &s.SwapContract, s.swapKit.lnd.ChainParams, s.hash, &s.SwapContract, s.swapKit.lnd.ChainParams,
@ -467,8 +467,8 @@ func (s *loopInSwap) sendUpdate(ctx context.Context) error {
info.ExternalHtlc = s.ExternalHtlc info.ExternalHtlc = s.ExternalHtlc
// In order to avoid potentially dangerous ownership sharing // In order to avoid potentially dangerous ownership sharing we copy the
// we copy the last hop vertex. // last hop vertex.
if s.LastHop != nil { if s.LastHop != nil {
lastHop := &route.Vertex{} lastHop := &route.Vertex{}
copy(lastHop[:], s.LastHop[:]) copy(lastHop[:], s.LastHop[:])
@ -524,15 +524,15 @@ func (s *loopInSwap) execute(mainCtx context.Context,
err = fmt.Errorf("swap in non-final state %v", s.state) err = fmt.Errorf("swap in non-final state %v", s.state)
} }
// If an unexpected error happened, report a temporary failure // If an unexpected error happened, report a temporary failure but don't
// but don't persist the error. Otherwise for example a // persist the error. Otherwise, for example a connection error could
// connection error could lead to abandoning the swap // lead to abandoning the swap permanently and losing funds.
// permanently and losing funds.
if err != nil { if err != nil {
s.log.Errorf("Swap error: %v", err) s.log.Errorf("Swap error: %v", err)
s.setState(loopdb.StateFailTemporary) s.setState(loopdb.StateFailTemporary)
// If we cannot send out this update, there is nothing we can do. // If we cannot send out this update, there is nothing we can
// do.
_ = s.sendUpdate(mainCtx) _ = s.sendUpdate(mainCtx)
return err return err
@ -554,7 +554,7 @@ func (s *loopInSwap) executeSwap(globalCtx context.Context) error {
var err error var err error
// For loop in, the client takes the first step by publishing the // For loop in, the client takes the first step by publishing the
// on-chain htlc. Only do this is we haven't already done so in a // on-chain htlc. Only do this if we haven't already done so in a
// previous run. // previous run.
if s.state == loopdb.StateInitiated { if s.state == loopdb.StateInitiated {
if s.ExternalHtlc { if s.ExternalHtlc {
@ -577,7 +577,7 @@ func (s *loopInSwap) executeSwap(globalCtx context.Context) error {
} }
} }
// Wait for the htlc to confirm. After a restart this will pick up a // Wait for the htlc to confirm. After a restart, this will pick up a
// previously published tx. // previously published tx.
conf, err := s.waitForHtlcConf(globalCtx) conf, err := s.waitForHtlcConf(globalCtx)
if err != nil { if err != nil {
@ -593,17 +593,17 @@ func (s *loopInSwap) executeSwap(globalCtx context.Context) error {
} }
// Verify that the confirmed (external) htlc value matches the swap // Verify that the confirmed (external) htlc value matches the swap
// amount. Otherwise fail the swap immediately. // amount. Otherwise, fail the swap immediately.
if htlcValue != s.LoopInContract.AmountRequested { if htlcValue != s.LoopInContract.AmountRequested {
s.setState(loopdb.StateFailIncorrectHtlcAmt) s.setState(loopdb.StateFailIncorrectHtlcAmt)
return s.persistAndAnnounceState(globalCtx) return s.persistAndAnnounceState(globalCtx)
} }
// The server is expected to see the htlc on-chain and knowing that it // The server is expected to see the htlc on-chain and know that it can
// can sweep that htlc with the preimage, it should pay our swap // sweep that htlc with the preimage, it should pay our swap invoice,
// invoice, receive the preimage and sweep the htlc. We are waiting for // receive the preimage and sweep the htlc. We are waiting for this to
// this to happen and simultaneously watch the htlc expiry height. When // happen and simultaneously watch the htlc expiry height. When the htlc
// the htlc expires, we will publish a timeout tx to reclaim the funds. // expires, we will publish a timeout tx to reclaim the funds.
err = s.waitForSwapComplete(globalCtx, htlcOutpoint, htlcValue) err = s.waitForSwapComplete(globalCtx, htlcOutpoint, htlcValue)
if err != nil { if err != nil {
return err return err
@ -623,8 +623,8 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) (
// Register for confirmation of the htlc. It is essential to specify not // Register for confirmation of the htlc. It is essential to specify not
// just the pk script, because an attacker may publish the same htlc // just the pk script, because an attacker may publish the same htlc
// with a lower value and we don't want to follow through with that tx. // with a lower value, and we don't want to follow through with that tx.
// In the unlikely event that our call to SendOutputs crashes and we // In the unlikely event that our call to SendOutputs crashes, and we
// restart, htlcTxHash will be nil at this point. Then only register // restart, htlcTxHash will be nil at this point. Then only register
// with PkScript and accept the risk that the call triggers on a // with PkScript and accept the risk that the call triggers on a
// different htlc outpoint. // different htlc outpoint.
@ -765,9 +765,6 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
// Persist the htlc hash so that after a restart we are still waiting // Persist the htlc hash so that after a restart we are still waiting
// for our own htlc. We don't need to announce to clients, because the // for our own htlc. We don't need to announce to clients, because the
// state remains unchanged. // state remains unchanged.
//
// TODO(joostjager): Store tx hash before calling SendOutputs. This is
// not yet possible with the current lnd api.
s.htlcTxHash = &txHash s.htlcTxHash = &txHash
// We do not expect any on-chain fees to be recorded yet, and we only // 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,
} }
// tryPushHtlcKey attempts to push the htlc key to the server. If the server // tryPushHtlcKey attempts to push the htlc key to the server. If the server
// returns an error of any kind we'll log it as a warning but won't act as // returns an error of any kind we'll log it as a warning but won't act as the
// the swap execution can just go on without the server gaining knowledge of // swap execution can just go on without the server gaining knowledge of our
// our internal key. // internal key.
func (s *loopInSwap) tryPushHtlcKey(ctx context.Context) bool { func (s *loopInSwap) tryPushHtlcKey(ctx context.Context) bool {
if s.ProtocolVersion < loopdb.ProtocolVersionMuSig2 { if s.ProtocolVersion < loopdb.ProtocolVersionMuSig2 {
return false return false
@ -1022,7 +1019,7 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
} }
} }
// Calculate sweep tx fee // Calculate sweep tx fee.
fee, err := s.sweeper.GetSweepFee( fee, err := s.sweeper.GetSweepFee(
ctx, s.htlc.AddTimeoutToEstimator, s.timeoutAddr, ctx, s.htlc.AddTimeoutToEstimator, s.timeoutAddr,
TimeoutTxConfTarget, TimeoutTxConfTarget,

Loading…
Cancel
Save