Skip to content

Commit

Permalink
Merge pull request #771 from bhandras/cost-migration-timeout
Browse files Browse the repository at this point in the history
loopd: make the LND RPC timeout configurable and fix cost migration for pending swaps
  • Loading branch information
bhandras authored Jun 4, 2024
2 parents 3d1d3eb + 9cacd8e commit 18b0de3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cost_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,21 @@ func MigrateLoopOutCosts(ctx context.Context, lnd lndclient.LndServices,
// costs in the database.
updatedCosts := make(map[lntypes.Hash]loopdb.SwapCost)
for _, loopOutSwap := range loopOutSwaps {
if loopOutSwap.State().State.IsPending() {
continue
}

cost, err := CalculateLoopOutCost(
lnd.ChainParams, loopOutSwap, paymentFees,
)
if err != nil {
return err
// We don't want to fail loopd because of any old swap
// that we're unable to calculate the cost for. We'll
// warn though so that we can investigate further.
log.Warnf("Unable to calculate cost for swap %v: %v",
loopOutSwap.Hash, err)

continue
}

_, ok := updatedCosts[loopOutSwap.Hash]
Expand Down
8 changes: 8 additions & 0 deletions loopd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ var (
defaultLndMacaroon,
)

// DefaultLndRPCTimeout is the default timeout to use when communicating
// with lnd.
DefaultLndRPCTimeout = time.Minute

// DefaultTLSCertPath is the default full path of the autogenerated TLS
// certificate.
DefaultTLSCertPath = filepath.Join(
Expand Down Expand Up @@ -118,6 +122,9 @@ type lndConfig struct {
MacaroonPath string `long:"macaroonpath" description:"The full path to the single macaroon to use, either the admin.macaroon or a custom baked one. Cannot be specified at the same time as macaroondir. A custom macaroon must contain ALL permissions required for all subservers to work, otherwise permission errors will occur."`

TLSPath string `long:"tlspath" description:"Path to lnd tls certificate"`

// RPCTimeout is the timeout to use when communicating with lnd.
RPCTimeout time.Duration `long:"rpctimeout" description:"The timeout to use when communicating with lnd"`
}

type loopServerConfig struct {
Expand Down Expand Up @@ -217,6 +224,7 @@ func DefaultConfig() Config {
Lnd: &lndConfig{
Host: "localhost:10009",
MacaroonPath: DefaultLndMacaroonPath,
RPCTimeout: DefaultLndRPCTimeout,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions loopd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func NewListenerConfig(config *Config, rpcCfg RPCConfig) *ListenerCfg {
BlockUntilChainSynced: true,
CallerCtx: callerCtx,
BlockUntilUnlocked: true,
RPCTimeout: cfg.RPCTimeout,
}

// If a custom lnd connection is specified we use that
Expand Down

0 comments on commit 18b0de3

Please sign in to comment.