trivial: clean up typos and comments

pull/622/head
Slyghtning 9 months ago
parent 24987ddf10
commit 20316042d9
No known key found for this signature in database
GPG Key ID: F82D456EA023C9BF

@ -272,9 +272,7 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
// restored from persistent storage and resumed. Subsequent updates will be // restored from persistent storage and resumed. Subsequent updates will be
// sent through the passed in statusChan. The function can be terminated by // sent through the passed in statusChan. The function can be terminated by
// cancelling the context. // cancelling the context.
func (s *Client) Run(ctx context.Context, func (s *Client) Run(ctx context.Context, statusChan chan<- SwapInfo) error {
statusChan chan<- SwapInfo) error {
if !atomic.CompareAndSwapUint32(&s.started, 0, 1) { if !atomic.CompareAndSwapUint32(&s.started, 0, 1) {
return errors.New("swap client can only be started once") return errors.New("swap client can only be started once")
} }
@ -284,7 +282,7 @@ func (s *Client) Run(ctx context.Context,
s.lndServices.NodeAlias, s.lndServices.NodePubkey, s.lndServices.NodeAlias, s.lndServices.NodePubkey,
lndclient.VersionString(s.lndServices.Version)) lndclient.VersionString(s.lndServices.Version))
// Setup main context used for cancelation. // Setup main context used for cancellation.
mainCtx, mainCancel := context.WithCancel(ctx) mainCtx, mainCancel := context.WithCancel(ctx)
defer mainCancel() defer mainCancel()
@ -307,7 +305,7 @@ func (s *Client) Run(ctx context.Context,
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
// swap could already have been added to the store and read in // swap could already have been added to the store and read in
// 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.

@ -71,34 +71,35 @@ func (s *executor) run(mainCtx context.Context,
for { for {
blockEpochChan, blockErrorChan, err = blockEpochChan, blockErrorChan, err =
s.lnd.ChainNotifier.RegisterBlockEpochNtfn(mainCtx) s.lnd.ChainNotifier.RegisterBlockEpochNtfn(mainCtx)
if err != nil {
if strings.Contains(err.Error(),
"in the process of starting") {
log.Warnf("LND chain notifier server not " + if err == nil {
"ready yet, retrying with delay") break
}
// Give chain notifier some time to start and if strings.Contains(err.Error(),
// try to re-attempt block epoch subscription. "in the process of starting") {
select {
case <-time.After(500 * time.Millisecond):
continue
case <-mainCtx.Done(): log.Warnf("LND chain notifier server not ready yet, " +
return err "retrying with delay")
}
} // Give chain notifier some time to start and try to
// re-attempt block epoch subscription.
select {
case <-time.After(500 * time.Millisecond):
continue
return err case <-mainCtx.Done():
return err
}
} }
break return err
} }
// Before starting, make sure we have an up to date block height. // Before starting, make sure we have an up-to-date block height.
// Otherwise we might reveal a preimage for a swap that is already // Otherwise, we might reveal a preimage for a swap that is already
// expired. // expired.
log.Infof("Wait for first block ntfn") log.Infof("Wait for first block notification")
var height int32 var height int32
setHeight := func(h int32) { setHeight := func(h int32) {
@ -118,7 +119,7 @@ func (s *executor) run(mainCtx context.Context,
// 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)
// Signal that executor being ready with an up to date block height. // Signal that executor being ready with an up-to-date block height.
close(s.ready) close(s.ready)
// Use a map to administer the individual notification queues for the // Use a map to administer the individual notification queues for the

@ -95,7 +95,7 @@ func New(config *Config, lisCfg *ListenerCfg) *Daemon {
// We send exactly one error on this channel if something goes // We send exactly one error on this channel if something goes
// wrong at runtime. Or a nil value if the shutdown was // wrong at runtime. Or a nil value if the shutdown was
// successful. But in case nobody's listening, we don't want to // successful. But in case nobody's listening, we don't want to
// block on it so we buffer it. // block on it, so we buffer it.
ErrChan: make(chan error, 1), ErrChan: make(chan error, 1),
quit: make(chan struct{}), quit: make(chan struct{}),
@ -135,9 +135,9 @@ func (d *Daemon) Start() error {
if errors.Is(err, bbolt.ErrTimeout) { if errors.Is(err, bbolt.ErrTimeout) {
// We're trying to be started as a standalone Loop daemon, most // We're trying to be started as a standalone Loop daemon, most
// likely LiT is already running and blocking the DB // likely LiT is already running and blocking the DB
return fmt.Errorf("%v: make sure no other loop daemon "+ return fmt.Errorf("%v: make sure no other loop daemon process "+
"process (standalone or embedded in "+ "(standalone or embedded in lightning-terminal) is"+
"lightning-terminal) is running", err) "running", err)
} }
if err != nil { if err != nil {
return err return err
@ -166,9 +166,9 @@ func (d *Daemon) Start() error {
func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices, func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices,
withMacaroonService bool) error { withMacaroonService bool) error {
// There should be no reason to start the daemon twice. Therefore return // There should be no reason to start the daemon twice. Therefore,
// an error if that's tried. This is mostly to guard against Start and // return an error if that's tried. This is mostly to guard against
// StartAsSubserver both being called. // Start and StartAsSubserver both being called.
if atomic.AddInt32(&d.started, 1) != 1 { if atomic.AddInt32(&d.started, 1) != 1 {
return errOnlyStartOnce return errOnlyStartOnce
} }
@ -179,8 +179,8 @@ func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices,
// With lnd already pre-connected, initialize everything else, such as // With lnd already pre-connected, initialize everything else, such as
// the swap server client, the RPC server instance and our main swap // the swap server client, the RPC server instance and our main swap
// handlers. If this fails, then nothing has been started yet and we can // handlers. If this fails, then nothing has been started yet, and we
// just return the error. // can just return the error.
err := d.initialize(withMacaroonService) err := d.initialize(withMacaroonService)
if errors.Is(err, bbolt.ErrTimeout) { if errors.Is(err, bbolt.ErrTimeout) {
// We're trying to be started inside LiT so there most likely is // We're trying to be started inside LiT so there most likely is
@ -370,8 +370,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
} }
} }
// Both the client RPC server and and the swap server client should // Both the client RPC server and the swap server client should stop
// stop on main context cancel. So we create it early and pass it down. // on main context cancel. So we create it early and pass it down.
d.mainCtx, d.mainCtxCancel = context.WithCancel(context.Background()) d.mainCtx, d.mainCtxCancel = context.WithCancel(context.Background())
log.Infof("Swap server address: %v", d.cfg.Server.Host) log.Infof("Swap server address: %v", d.cfg.Server.Host)

@ -561,7 +561,7 @@ func (s *swapClientServer) LoopOutQuote(ctx context.Context,
}, nil }, nil
} }
// GetTerms returns the terms that the server enforces for swaps. // GetLoopInTerms returns the terms that the server enforces for swaps.
func (s *swapClientServer) GetLoopInTerms(ctx context.Context, func (s *swapClientServer) GetLoopInTerms(ctx context.Context,
req *clientrpc.TermsRequest) (*clientrpc.InTermsResponse, error) { req *clientrpc.TermsRequest) (*clientrpc.InTermsResponse, error) {
@ -579,7 +579,7 @@ func (s *swapClientServer) GetLoopInTerms(ctx context.Context,
}, nil }, nil
} }
// GetQuote returns a quote for a swap with the provided parameters. // GetLoopInQuote returns a quote for a swap with the provided parameters.
func (s *swapClientServer) GetLoopInQuote(ctx context.Context, func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
req *clientrpc.QuoteRequest) (*clientrpc.InQuoteResponse, error) { req *clientrpc.QuoteRequest) (*clientrpc.InQuoteResponse, error) {

@ -817,8 +817,9 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
return fmt.Errorf("subscribe to swap invoice: %v", err) return fmt.Errorf("subscribe to swap invoice: %v", err)
} }
// checkTimeout publishes the timeout tx if the contract has expired. // publishTxOnTimeout publishes the timeout tx if the contract has
checkTimeout := func() (btcutil.Amount, error) { // expired.
publishTxOnTimeout := func() (btcutil.Amount, error) {
if s.height >= s.LoopInContract.CltvExpiry { if s.height >= s.LoopInContract.CltvExpiry {
return s.publishTimeoutTx(ctx, htlcOutpoint, htlcValue) return s.publishTimeoutTx(ctx, htlcOutpoint, htlcValue)
} }
@ -829,7 +830,7 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
// Check timeout at current height. After a restart we may want to // Check timeout at current height. After a restart we may want to
// publish the tx immediately. // publish the tx immediately.
var sweepFee btcutil.Amount var sweepFee btcutil.Amount
sweepFee, err = checkTimeout() sweepFee, err = publishTxOnTimeout()
if err != nil { if err != nil {
return err return err
} }
@ -848,7 +849,7 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
case notification := <-s.blockEpochChan: case notification := <-s.blockEpochChan:
s.height = notification.(int32) s.height = notification.(int32)
sweepFee, err = checkTimeout() sweepFee, err = publishTxOnTimeout()
if err != nil { if err != nil {
return err return err
} }
@ -971,7 +972,7 @@ func (s *loopInSwap) processHtlcSpend(ctx context.Context,
sweepFee btcutil.Amount) error { sweepFee btcutil.Amount) error {
// Determine the htlc input of the spending tx and inspect the witness // Determine the htlc input of the spending tx and inspect the witness
// to findout whether a success or a timeout tx spend the htlc. // to find out whether a success or a timeout tx spent the htlc.
htlcInput := spend.SpendingTx.TxIn[spend.SpenderInputIndex] htlcInput := spend.SpendingTx.TxIn[spend.SpenderInputIndex]
if s.htlc.IsSuccessWitness(htlcInput.Witness) { if s.htlc.IsSuccessWitness(htlcInput.Witness) {

Loading…
Cancel
Save