Skip to content

Commit 18b0de3

Browse files
authored
Merge pull request #771 from bhandras/cost-migration-timeout
loopd: make the LND RPC timeout configurable and fix cost migration for pending swaps
2 parents 3d1d3eb + 9cacd8e commit 18b0de3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

cost_migration.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,21 @@ func MigrateLoopOutCosts(ctx context.Context, lnd lndclient.LndServices,
150150
// costs in the database.
151151
updatedCosts := make(map[lntypes.Hash]loopdb.SwapCost)
152152
for _, loopOutSwap := range loopOutSwaps {
153+
if loopOutSwap.State().State.IsPending() {
154+
continue
155+
}
156+
153157
cost, err := CalculateLoopOutCost(
154158
lnd.ChainParams, loopOutSwap, paymentFees,
155159
)
156160
if err != nil {
157-
return err
161+
// We don't want to fail loopd because of any old swap
162+
// that we're unable to calculate the cost for. We'll
163+
// warn though so that we can investigate further.
164+
log.Warnf("Unable to calculate cost for swap %v: %v",
165+
loopOutSwap.Hash, err)
166+
167+
continue
158168
}
159169

160170
_, ok := updatedCosts[loopOutSwap.Hash]

loopd/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ var (
7676
defaultLndMacaroon,
7777
)
7878

79+
// DefaultLndRPCTimeout is the default timeout to use when communicating
80+
// with lnd.
81+
DefaultLndRPCTimeout = time.Minute
82+
7983
// DefaultTLSCertPath is the default full path of the autogenerated TLS
8084
// certificate.
8185
DefaultTLSCertPath = filepath.Join(
@@ -118,6 +122,9 @@ type lndConfig struct {
118122
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."`
119123

120124
TLSPath string `long:"tlspath" description:"Path to lnd tls certificate"`
125+
126+
// RPCTimeout is the timeout to use when communicating with lnd.
127+
RPCTimeout time.Duration `long:"rpctimeout" description:"The timeout to use when communicating with lnd"`
121128
}
122129

123130
type loopServerConfig struct {
@@ -217,6 +224,7 @@ func DefaultConfig() Config {
217224
Lnd: &lndConfig{
218225
Host: "localhost:10009",
219226
MacaroonPath: DefaultLndMacaroonPath,
227+
RPCTimeout: DefaultLndRPCTimeout,
220228
},
221229
}
222230
}

loopd/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func NewListenerConfig(config *Config, rpcCfg RPCConfig) *ListenerCfg {
9696
BlockUntilChainSynced: true,
9797
CallerCtx: callerCtx,
9898
BlockUntilUnlocked: true,
99+
RPCTimeout: cfg.RPCTimeout,
99100
}
100101

101102
// If a custom lnd connection is specified we use that

0 commit comments

Comments
 (0)