Skip to content

Commit 9aa193b

Browse files
committed
staticaddr: configurable max htlc tx fee
1 parent 7503f44 commit 9aa193b

File tree

3 files changed

+55
-30
lines changed

3 files changed

+55
-30
lines changed

client.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ type ClientConfig struct {
131131
// MaxPaymentRetries is the maximum times we retry an off-chain payment
132132
// (used in loop out).
133133
MaxPaymentRetries int
134+
135+
// MaxStaticAddrHtlcFeePercentage is the percentage of the swap amount
136+
// that we allow the server to charge for the htlc transaction.
137+
// Although highly unlikely, this is a defense against the server
138+
// publishing the htlc without paying the swap invoice, forcing us to
139+
// sweep the timeout path.
140+
MaxStaticAddrHtlcFeePercentage float64
141+
142+
// MaxStaticAddrHtlcBackupFeePercentage is the percentage of the swap
143+
// amount that we allow the server to charge for the htlc backup
144+
// transactions. This is a defense against the server publishing the
145+
// htlc backup without paying the swap invoice, forcing us to sweep the
146+
// timeout path. This value is elevated compared to
147+
// MaxStaticAddrHtlcFeePercentage since it serves the server as backup
148+
// transaction in case of fee spikes.
149+
MaxStaticAddrHtlcBackupFeePercentage float64
134150
}
135151

136152
// NewClient returns a new instance to initiate swaps with.

loopd/config.go

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ var (
4242
LoopDirBase, DefaultNetwork, defaultSqliteDatabaseFileName,
4343
)
4444

45-
defaultMaxLogFiles = 3
46-
defaultMaxLogFileSize = 10
47-
defaultLoopOutMaxParts = uint32(5)
48-
defaultTotalPaymentTimeout = time.Minute * 60
49-
defaultMaxPaymentRetries = 3
45+
defaultMaxLogFiles = 3
46+
defaultMaxLogFileSize = 10
47+
defaultLoopOutMaxParts = uint32(5)
48+
defaultTotalPaymentTimeout = time.Minute * 60
49+
defaultMaxPaymentRetries = 3
50+
defaultMaxStaticAddrHtlcFeePercentage = 0.2
51+
defaultMaxStaticAddrHtlcBackupFeePercentage = 0.5
5052

5153
// defaultRPCBatchSize is the default batch size to use for RPC calls
5254
// we make to LND during migrations. If operations on the LND side are
@@ -183,6 +185,9 @@ type Config struct {
183185
TotalPaymentTimeout time.Duration `long:"totalpaymenttimeout" description:"The timeout to use for off-chain payments."`
184186
MaxPaymentRetries int `long:"maxpaymentretries" description:"The maximum number of times an off-chain payment may be retried."`
185187

188+
MaxStaticAddrHtlcFeePercentage float64 `long:"maxstaticaddrhtlcfeepercentage" description:"The maximum fee percentage that the server can charge for the htlc tx."`
189+
MaxStaticAddrHtlcBackupFeePercentage float64 `long:"maxstaticaddrhtlcbackupfeepercentage" description:"The maximum fee percentage that the server can charge for the htlc backup tx."`
190+
186191
EnableExperimental bool `long:"experimental" description:"Enable experimental features: reservations"`
187192

188193
MigrationRPCBatchSize int `long:"migrationrpcbatchsize" description:"The RPC batch size to use during migrations."`
@@ -215,21 +220,23 @@ func DefaultConfig() Config {
215220
Sqlite: &loopdb.SqliteConfig{
216221
DatabaseFileName: defaultSqliteDatabasePath,
217222
},
218-
LogDir: defaultLogDir,
219-
MaxLogFiles: defaultMaxLogFiles,
220-
MaxLogFileSize: defaultMaxLogFileSize,
221-
DebugLevel: defaultLogLevel,
222-
TLSCertPath: DefaultTLSCertPath,
223-
TLSKeyPath: DefaultTLSKeyPath,
224-
TLSValidity: DefaultAutogenValidity,
225-
MacaroonPath: DefaultMacaroonPath,
226-
MaxL402Cost: l402.DefaultMaxCostSats,
227-
MaxL402Fee: l402.DefaultMaxRoutingFeeSats,
228-
LoopOutMaxParts: defaultLoopOutMaxParts,
229-
TotalPaymentTimeout: defaultTotalPaymentTimeout,
230-
MaxPaymentRetries: defaultMaxPaymentRetries,
231-
EnableExperimental: false,
232-
MigrationRPCBatchSize: defaultRPCBatchSize,
223+
LogDir: defaultLogDir,
224+
MaxLogFiles: defaultMaxLogFiles,
225+
MaxLogFileSize: defaultMaxLogFileSize,
226+
DebugLevel: defaultLogLevel,
227+
TLSCertPath: DefaultTLSCertPath,
228+
TLSKeyPath: DefaultTLSKeyPath,
229+
TLSValidity: DefaultAutogenValidity,
230+
MacaroonPath: DefaultMacaroonPath,
231+
MaxL402Cost: l402.DefaultMaxCostSats,
232+
MaxL402Fee: l402.DefaultMaxRoutingFeeSats,
233+
LoopOutMaxParts: defaultLoopOutMaxParts,
234+
TotalPaymentTimeout: defaultTotalPaymentTimeout,
235+
MaxPaymentRetries: defaultMaxPaymentRetries,
236+
MaxStaticAddrHtlcFeePercentage: defaultMaxStaticAddrHtlcFeePercentage,
237+
MaxStaticAddrHtlcBackupFeePercentage: defaultMaxStaticAddrHtlcBackupFeePercentage,
238+
EnableExperimental: false,
239+
MigrationRPCBatchSize: defaultRPCBatchSize,
233240
Lnd: &lndConfig{
234241
Host: "localhost:10009",
235242
MacaroonPath: DefaultLndMacaroonPath,

loopd/utils.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ func getClient(cfg *Config, swapDb loopdb.SwapStore,
4040
}
4141

4242
clientConfig := &loop.ClientConfig{
43-
ServerAddress: cfg.Server.Host,
44-
ProxyAddress: cfg.Server.Proxy,
45-
SwapServerNoTLS: cfg.Server.NoTLS,
46-
TLSPathServer: cfg.Server.TLSPath,
47-
Lnd: lnd,
48-
MaxL402Cost: btcutil.Amount(cfg.MaxL402Cost),
49-
MaxL402Fee: btcutil.Amount(cfg.MaxL402Fee),
50-
LoopOutMaxParts: cfg.LoopOutMaxParts,
51-
TotalPaymentTimeout: cfg.TotalPaymentTimeout,
52-
MaxPaymentRetries: cfg.MaxPaymentRetries,
43+
ServerAddress: cfg.Server.Host,
44+
ProxyAddress: cfg.Server.Proxy,
45+
SwapServerNoTLS: cfg.Server.NoTLS,
46+
TLSPathServer: cfg.Server.TLSPath,
47+
Lnd: lnd,
48+
MaxL402Cost: btcutil.Amount(cfg.MaxL402Cost),
49+
MaxL402Fee: btcutil.Amount(cfg.MaxL402Fee),
50+
LoopOutMaxParts: cfg.LoopOutMaxParts,
51+
TotalPaymentTimeout: cfg.TotalPaymentTimeout,
52+
MaxPaymentRetries: cfg.MaxPaymentRetries,
53+
MaxStaticAddrHtlcFeePercentage: cfg.MaxStaticAddrHtlcFeePercentage,
54+
MaxStaticAddrHtlcBackupFeePercentage: cfg.MaxStaticAddrHtlcBackupFeePercentage,
5355
}
5456

5557
if cfg.MaxL402Cost == defaultCost && cfg.MaxLSATCost != 0 {

0 commit comments

Comments
 (0)