Skip to content

Commit f97e87e

Browse files
committed
staticaddr: configurable max htlc tx fee
In this commit we introduce maximum fee percentages for the static loop-in htlc transactions. Since the server has the ability to publish htlc transactions without settling the swap payment we have to restrict the amount the server allocates for fees of these transactions.
1 parent d4dd636 commit f97e87e

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
@@ -141,6 +141,22 @@ type ClientConfig struct {
141141
// MaxPaymentRetries is the maximum times we retry an off-chain payment
142142
// (used in loop out).
143143
MaxPaymentRetries int
144+
145+
// MaxStaticAddrHtlcFeePercentage is the percentage of the swap amount
146+
// that we allow the server to charge for the htlc transaction.
147+
// Although highly unlikely, this is a defense against the server
148+
// publishing the htlc without paying the swap invoice, forcing us to
149+
// sweep the timeout path.
150+
MaxStaticAddrHtlcFeePercentage float64
151+
152+
// MaxStaticAddrHtlcBackupFeePercentage is the percentage of the swap
153+
// amount that we allow the server to charge for the htlc backup
154+
// transactions. This is a defense against the server publishing the
155+
// htlc backup without paying the swap invoice, forcing us to sweep the
156+
// timeout path. This value is elevated compared to
157+
// MaxStaticAddrHtlcFeePercentage since it serves the server as backup
158+
// transaction in case of fee spikes.
159+
MaxStaticAddrHtlcBackupFeePercentage float64
144160
}
145161

146162
// 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. The backup transaction is only used in rare cases when the regular htlc tx is not confirmed on time. These backup transactions refer to high fee or extremely high fee transactions in the API."`
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)