Skip to content

Commit 7c1cd9a

Browse files
authored
Merge pull request #1177 from lightninglabs/lnd-rpc-timeout
tapcfg: allow to configure lnd RPC timeout, increase default val
2 parents 8e070bd + a8e6336 commit 7c1cd9a

File tree

4 files changed

+58
-33
lines changed

4 files changed

+58
-33
lines changed

proof/courier.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@ func (e *BackoffExecError) Error() string {
545545
}
546546

547547
// BackoffCfg configures the behaviour of the proof delivery backoff procedure.
548+
//
549+
// nolint:lll
548550
type BackoffCfg struct {
549551
// SkipInitDelay is a flag that indicates whether we should skip the
550552
// initial delay before attempting to deliver the proof to the receiver
@@ -553,19 +555,19 @@ type BackoffCfg struct {
553555

554556
// BackoffResetWait is the amount of time we'll wait before
555557
// resetting the backoff counter to its initial state.
556-
BackoffResetWait time.Duration `long:"backoffresetwait" description:"The amount of time to wait before resetting the backoff counter."`
558+
BackoffResetWait time.Duration `long:"backoffresetwait" description:"The amount of time to wait before resetting the backoff counter. Valid time units are {s, m, h}."`
557559

558560
// NumTries is the number of times we'll try to deliver the proof to the
559561
// receiver before the BackoffResetWait delay is enforced.
560562
NumTries int `long:"numtries" description:"The number of proof delivery attempts before the backoff counter is reset."`
561563

562564
// InitialBackoff is the initial backoff time we'll use to wait before
563565
// retrying to deliver the proof to the receiver.
564-
InitialBackoff time.Duration `long:"initialbackoff" description:"The initial backoff time to wait before retrying to deliver the proof to the receiver."`
566+
InitialBackoff time.Duration `long:"initialbackoff" description:"The initial backoff time to wait before retrying to deliver the proof to the receiver. Valid time units are {s, m, h}."`
565567

566568
// MaxBackoff is the maximum backoff time we'll use to wait before
567569
// retrying to deliver the proof to the receiver.
568-
MaxBackoff time.Duration `long:"maxbackoff" description:"The maximum backoff time to wait before retrying to deliver the proof to the receiver."`
570+
MaxBackoff time.Duration `long:"maxbackoff" description:"The maximum backoff time to wait before retrying to deliver the proof to the receiver. Valid time units are {s, m, h}."`
569571
}
570572

571573
// BackoffHandler is a handler for the backoff procedure.
@@ -755,10 +757,12 @@ func NewBackoffHandler(cfg *BackoffCfg,
755757
}
756758

757759
// HashMailCourierCfg is the config for the hashmail proof courier.
760+
//
761+
// nolint:lll
758762
type HashMailCourierCfg struct {
759763
// ReceiverAckTimeout is the maximum time we'll wait for the receiver to
760764
// acknowledge the proof.
761-
ReceiverAckTimeout time.Duration `long:"receiveracktimeout" description:"The maximum time to wait for the receiver to acknowledge the proof."`
765+
ReceiverAckTimeout time.Duration `long:"receiveracktimeout" description:"The maximum time to wait for the receiver to acknowledge the proof. Valid time units are {s, m, h}."`
762766

763767
// BackoffCfg configures the behaviour of the proof delivery
764768
// functionality.

sample-tapd.conf

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
; proofcourieraddr=universerpc://testnet.universe.lightning.finance:10029
6060

6161
; The number of seconds the custodian waits after identifying an asset transfer
62-
; on-chain and before retrieving the corresponding proof
62+
; on-chain and before retrieving the corresponding proof. Valid time units are
63+
; {s, m, h}.
6364
; custodianproofretrievaldelay=5s
6465

6566
; Network to run on (mainnet, regtest, testnet, simnet, signet)
@@ -94,7 +95,8 @@
9495
; Use first --tlsextradomain as Common Name instead, if set
9596
; tlsdisableautofill=false
9697

97-
; The duration for which the auto-generated TLS certificate will be valid for
98+
; The duration for which the auto-generated TLS certificate will be valid for.
99+
; Valid time units are {s, m, h}.
98100
; tlscertduration=10080h
99101

100102
; Disable REST API
@@ -103,12 +105,13 @@
103105
; Disable TLS for REST connections
104106
; no-rest-tls=false
105107

106-
; The ping interval for REST based WebSocket connections
107-
; Set to 0 to disable sending ping messages from the server side
108+
; The ping interval for REST based WebSocket connections. Set to 0 to disable
109+
; sending ping messages from the server side. Valid time units are {s, m, h}.
108110
; ws-ping-interval=30s
109111

110112
; The time we wait for a pong response message on REST based WebSocket
111-
; connections before the connection is closed as inactive
113+
; connections before the connection is closed as inactive. Valid time units are
114+
; {s, m, h}.
112115
; ws-pong-wait=5s
113116

114117
; Path to write the admin macaroon for tapd's RPC and REST services if it
@@ -154,25 +157,27 @@
154157

155158
[hashmailcourier]
156159

157-
; The maximum time to wait for the receiver to acknowledge the proof
160+
; The maximum time to wait for the receiver to acknowledge the proof. Valid time
161+
; units are {s, m, h}.
158162
; hashmailcourier.receiveracktimeout=6h
159163

160164
; Skip the initial delay before attempting to deliver the proof to the receiver
161165
; or receiving from the sender
162166
; hashmailcourier.skipinitdelay=false
163167

164-
; The amount of time to wait before resetting the backoff counter
168+
; The amount of time to wait before resetting the backoff counter. Valid time
169+
; units are {s, m, h}.
165170
; hashmailcourier.backoffresetwait=10m
166171

167172
; The number of proof delivery attempts before the backoff counter is reset
168173
; hashmailcourier.numtries=2000
169174

170175
; The initial backoff time to wait before retrying to deliver the proof to the
171-
; receiver
176+
; receiver. Valid time units are {s, m, h}.
172177
; hashmailcourier.initialbackoff=30s
173178

174179
; The maximum backoff time to wait before retrying to deliver the proof to the
175-
; receiver
180+
; receiver. Valid time units are {s, m, h}.
176181
; hashmailcourier.maxbackoff=5m
177182

178183
[universerpccourier]
@@ -181,18 +186,19 @@
181186
; or receiving from the sender
182187
; universerpccourier.skipinitdelay=false
183188

184-
; The amount of time to wait before resetting the backoff counter
189+
; The amount of time to wait before resetting the backoff counter. Valid time
190+
; units are {s, m, h}.
185191
; universerpccourier.backoffresetwait=10m
186192

187193
; The number of proof delivery attempts before the backoff counter is reset
188194
; universerpccourier.numtries=2000
189195

190196
; The initial backoff time to wait before retrying to deliver the proof to the
191-
; receiver
197+
; receiver. Valid time units are {s, m, h}.
192198
; universerpccourier.initialbackoff=30s
193199

194200
; The maximum backoff time to wait before retrying to deliver the proof to the
195-
; receiver
201+
; receiver. Valid time units are {s, m, h}.
196202
; universerpccourier.maxbackoff=5m
197203

198204
[lnd]
@@ -213,6 +219,11 @@
213219
; Path to lnd tls certificate
214220
; lnd.tlspath=
215221

222+
; The timeout to use for RPC requests to lnd; a sufficiently long duration
223+
; should be chosen to avoid issues with slow responses. Valid time units are
224+
; {s, m, h}.
225+
; lnd.rpctimeout=1m
226+
216227
[sqlite]
217228

218229
; Skip applying migrations on startup
@@ -250,18 +261,20 @@
250261
; Max number of idle connections to keep in the connection pool
251262
; postgres.maxidleconnections=
252263

253-
; Max amount of time a connection can be reused for before it is closed
264+
; Max amount of time a connection can be reused for before it is closed. Valid
265+
; time units are {s, m, h}.
254266
; postgres.connmaxlifetime=
255267

256-
; Max amount of time a connection can be idle for before it is closed
268+
; Max amount of time a connection can be idle for before it is closed. Valid
269+
; time units are {s, m, h}.
257270
; postgres.connmaxidletime=
258271

259272
; Whether to require using SSL (mode: require) when connecting to the server
260273
; postgres.requiressl=false
261274

262275
[universe]
263276

264-
; Amount of time to wait between universe syncs
277+
; Amount of time to wait between universe syncs. Valid time units are {s, m, h}.
265278
; universe.syncinterval=10m
266279

267280
; The host:port of a Universe server peer with
@@ -281,7 +294,8 @@
281294
; If 'w' is included, public access is allowed for write endpoints
282295
; universe.public-access=
283296

284-
; The amount of time to cache stats for before refreshing them
297+
; The amount of time to cache stats for before refreshing them. Valid time units
298+
; are {s, m, h}.
285299
; universe.stats-cache-duration=
286300

287301
; The maximum number of queries per second across the set of active universe

tapcfg/config.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// nolint:lll
12
package tapcfg
23

34
import (
@@ -130,6 +131,10 @@ const (
130131
// waits having identified an asset transfer on-chain and before
131132
// retrieving the corresponding proof via the proof courier service.
132133
defaultProofRetrievalDelay = 5 * time.Second
134+
135+
// defaultLndRPCTimeout is the default timeout we'll use for RPC
136+
// requests to lnd.
137+
defaultLndRPCTimeout = 1 * time.Minute
133138
)
134139

135140
var (
@@ -220,12 +225,12 @@ type RpcConfig struct {
220225
TLSExtraDomains []string `long:"tlsextradomain" description:"Adds an extra domain to the generated certificate"`
221226
TLSAutoRefresh bool `long:"tlsautorefresh" description:"Re-generate TLS certificate and key if the IPs or domains are changed"`
222227
TLSDisableAutofill bool `long:"tlsdisableautofill" description:"Do not include the interface IPs or the system hostname in TLS certificate, use first --tlsextradomain as Common Name instead, if set"`
223-
TLSCertDuration time.Duration `long:"tlscertduration" description:"The duration for which the auto-generated TLS certificate will be valid for"`
228+
TLSCertDuration time.Duration `long:"tlscertduration" description:"The duration for which the auto-generated TLS certificate will be valid for. Valid time units are {s, m, h}."`
224229

225230
DisableRest bool `long:"norest" description:"Disable REST API"`
226231
DisableRestTLS bool `long:"no-rest-tls" description:"Disable TLS for REST connections"`
227-
WSPingInterval time.Duration `long:"ws-ping-interval" description:"The ping interval for REST based WebSocket connections, set to 0 to disable sending ping messages from the server side"`
228-
WSPongWait time.Duration `long:"ws-pong-wait" description:"The time we wait for a pong response message on REST based WebSocket connections before the connection is closed as inactive"`
232+
WSPingInterval time.Duration `long:"ws-ping-interval" description:"The ping interval for REST based WebSocket connections, set to 0 to disable sending ping messages from the server side. Valid time units are {s, m, h}."`
233+
WSPongWait time.Duration `long:"ws-pong-wait" description:"The time we wait for a pong response message on REST based WebSocket connections before the connection is closed as inactive. Valid time units are {s, m, h}."`
229234

230235
MacaroonPath string `long:"macaroonpath" description:"Path to write the admin macaroon for tapd's RPC and REST services if it doesn't exist"`
231236
NoMacaroons bool `long:"no-macaroons" description:"Disable macaroon authentication, can only be used if server is not listening on a public interface."`
@@ -258,22 +263,23 @@ type LndConfig struct {
258263
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."`
259264

260265
TLSPath string `long:"tlspath" description:"Path to lnd tls certificate"`
266+
267+
// RPCTimeout is the timeout we'll use for RPC requests to lnd.
268+
RPCTimeout time.Duration `long:"rpctimeout" description:"The timeout to use for RPC requests to lnd; a sufficiently long duration should be chosen to avoid issues with slow responses. Valid time units are {s, m, h}."`
261269
}
262270

263271
// UniverseConfig is the config that houses any Universe related config
264272
// values.
265-
//
266-
// nolint: lll
267273
type UniverseConfig struct {
268-
SyncInterval time.Duration `long:"syncinterval" description:"Amount of time to wait between universe syncs"`
274+
SyncInterval time.Duration `long:"syncinterval" description:"Amount of time to wait between universe syncs. Valid time units are {s, m, h}."`
269275

270276
FederationServers []string `long:"federationserver" description:"The host:port of a Universe server peer with. These servers will be added as the default set of federation servers. Can be specified multiple times."`
271277

272278
SyncAllAssets bool `long:"sync-all-assets" description:"If set, the federation syncer will default to syncing all assets."`
273279

274280
PublicAccess string `long:"public-access" description:"The public access mode for the universe server, controlling whether remote parties can read from and/or write to this universe server over RPC if exposed to a public network interface. This can be unset, 'r', 'w', or 'rw'. If unset, public access is not enabled for the universe server. If 'r' is included, public access is allowed for read-only endpoints. If 'w' is included, public access is allowed for write endpoints."`
275281

276-
StatsCacheDuration time.Duration `long:"stats-cache-duration" description:"The amount of time to cache stats for before refreshing them."`
282+
StatsCacheDuration time.Duration `long:"stats-cache-duration" description:"The amount of time to cache stats for before refreshing them. Valid time units are {s, m, h}."`
277283

278284
UniverseQueriesPerSecond rate.Limit `long:"max-qps" description:"The maximum number of queries per second across the set of active universe queries that is permitted. Anything above this starts to get rate limited."`
279285

@@ -297,8 +303,6 @@ func (c *ExperimentalConfig) Validate() error {
297303
}
298304

299305
// Config is the main config for the tapd cli command.
300-
//
301-
// nolint: lll
302306
type Config struct {
303307
ShowVersion bool `long:"version" description:"Display version information and exit"`
304308

@@ -322,7 +326,7 @@ type Config struct {
322326
HashMailCourier *proof.HashMailCourierCfg `group:"hashmailcourier" namespace:"hashmailcourier"`
323327
UniverseRpcCourier *proof.UniverseRpcCourierCfg `group:"universerpccourier" namespace:"universerpccourier"`
324328

325-
CustodianProofRetrievalDelay time.Duration `long:"custodianproofretrievaldelay" description:"The number of seconds the custodian waits after identifying an asset transfer on-chain and before retrieving the corresponding proof."`
329+
CustodianProofRetrievalDelay time.Duration `long:"custodianproofretrievaldelay" description:"The number of seconds the custodian waits after identifying an asset transfer on-chain and before retrieving the corresponding proof. Valid time units are {s, m, h}."`
326330

327331
ChainConf *ChainConfig
328332
RpcConf *RpcConfig
@@ -385,6 +389,7 @@ func DefaultConfig() Config {
385389
Lnd: &LndConfig{
386390
Host: "localhost:10009",
387391
MacaroonPath: defaultLndMacaroonPath,
392+
RPCTimeout: defaultLndRPCTimeout,
388393
},
389394
DatabaseBackend: DatabaseBackendSqlite,
390395
Sqlite: &tapdb.SqliteConfig{
@@ -428,7 +433,6 @@ func DefaultConfig() Config {
428433
AddrBook: &AddrBookConfig{
429434
DisableSyncer: false,
430435
},
431-
// nolint: lll
432436
Experimental: &ExperimentalConfig{
433437
Rfq: rfq.CliConfig{
434438
AcceptPriceDeviationPpm: rfq.DefaultAcceptPriceDeviationPpm,
@@ -1150,5 +1154,6 @@ func getLnd(network string, cfg *LndConfig,
11501154
BlockUntilChainSynced: true,
11511155
BlockUntilUnlocked: true,
11521156
CallerCtx: ctxc,
1157+
RPCTimeout: cfg.RPCTimeout,
11531158
})
11541159
}

tapdb/postgres.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ var (
4343
)
4444

4545
// PostgresConfig holds the postgres database configuration.
46+
//
47+
// nolint:lll
4648
type PostgresConfig struct {
4749
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
4850
Host string `long:"host" description:"Database server hostname."`
@@ -52,8 +54,8 @@ type PostgresConfig struct {
5254
DBName string `long:"dbname" description:"Database name to use."`
5355
MaxOpenConnections int `long:"maxconnections" description:"Max open connections to keep alive to the database server."`
5456
MaxIdleConnections int `long:"maxidleconnections" description:"Max number of idle connections to keep in the connection pool."`
55-
ConnMaxLifetime time.Duration `long:"connmaxlifetime" description:"Max amount of time a connection can be reused for before it is closed."`
56-
ConnMaxIdleTime time.Duration `long:"connmaxidletime" description:"Max amount of time a connection can be idle for before it is closed."`
57+
ConnMaxLifetime time.Duration `long:"connmaxlifetime" description:"Max amount of time a connection can be reused for before it is closed. Valid time units are {s, m, h}."`
58+
ConnMaxIdleTime time.Duration `long:"connmaxidletime" description:"Max amount of time a connection can be idle for before it is closed. Valid time units are {s, m, h}."`
5759
RequireSSL bool `long:"requiressl" description:"Whether to require using SSL (mode: require) when connecting to the server."`
5860
}
5961

0 commit comments

Comments
 (0)