diff --git a/config.go b/config.go index 1865b6e81..93401a038 100644 --- a/config.go +++ b/config.go @@ -355,6 +355,8 @@ type Config struct { GcCanceledInvoicesOnTheFly bool `long:"gc-canceled-invoices-on-the-fly" description:"If true, we'll delete newly canceled invoices on the fly."` + DustThreshold uint64 `long:"dust-threshold" description:"Sets the dust sum threshold in satoshis for a channel after which dust HTLC's will be failed."` + Invoices *lncfg.Invoices `group:"invoices" namespace:"invoices"` Routing *lncfg.Routing `group:"routing" namespace:"routing"` @@ -550,6 +552,7 @@ func DefaultConfig() Config { MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry, MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation, MaxCommitFeeRateAnchors: lnwallet.DefaultAnchorsCommitMaxFeeRateSatPerVByte, + DustThreshold: uint64(htlcswitch.DefaultDustThreshold.ToSatoshis()), LogWriter: build.NewRotatingLogWriter(), DB: lncfg.DefaultDB(), Cluster: lncfg.DefaultCluster(), diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index cda704ce5..3283ec646 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -189,6 +189,7 @@ func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error) HtlcNotifier: &mockHTLCNotifier{}, Clock: clock.NewDefaultClock(), HTLCExpiry: time.Hour, + DustThreshold: DefaultDustThreshold, } return New(cfg, startingHeight) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 9c2c9715f..daa429b39 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -77,9 +77,9 @@ var ( // threshold. errDustThresholdExceeded = errors.New("dust threshold exceeded") - // defaultDustThreshold is the default threshold after which we'll fail - // payments if they are dust. This is currently set to 500k sats. - defaultDustThreshold = lnwire.MilliSatoshi(500_000_000) + // DefaultDustThreshold is the default threshold after which we'll fail + // payments if they are dust. This is currently set to 500m msats. + DefaultDustThreshold = lnwire.MilliSatoshi(500_000_000) ) // plexPacket encapsulates switch packet and adds error channel to receive @@ -187,6 +187,10 @@ type Config struct { // will expiry this long after the Adds are added to a mailbox via // AddPacket. HTLCExpiry time.Duration + + // DustThreshold is the threshold in milli-satoshis after which we'll + // fail incoming or outgoing dust payments for a particular channel. + DustThreshold lnwire.MilliSatoshi } // Switch is the central messaging bus for all incoming/outgoing HTLCs. @@ -2375,7 +2379,7 @@ func (s *Switch) evaluateDustThreshold(link ChannelLink, } // Finally check against the defined dust threshold. - if localSum > defaultDustThreshold { + if localSum > s.cfg.DustThreshold { return true } } @@ -2393,7 +2397,7 @@ func (s *Switch) evaluateDustThreshold(link ChannelLink, } // Finally check against the defined dust threshold. - if remoteSum > defaultDustThreshold { + if remoteSum > s.cfg.DustThreshold { return true } } diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index 0850b8c2f..0b342e382 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -203,6 +203,7 @@ func TestLightningNetworkDaemon(t *testing.T) { // TODO(roasbeef): create master balanced channel with all the monies? aliceBobArgs := []string{ "--default-remote-max-htlcs=483", + "--dust-threshold=5000000", } // Run the subset of the test cases selected in this tranche. diff --git a/sample-lnd.conf b/sample-lnd.conf index 1b889ed13..ad0ea1dc7 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -365,6 +365,11 @@ ; propagation (default: 10) ; max-commit-fee-rate-anchors=5 +; A threshold defining the maximum amount of dust a given channel can have +; after which forwarding and sending dust HTLC's to and from the channel will +; fail. This amount is expressed in satoshis. (default: 500000) +; dust-threshold=1000000 + ; If true, lnd will abort committing a migration if it would otherwise have been ; successful. This leaves the database unmodified, and still compatible with the ; previously active version of lnd. diff --git a/server.go b/server.go index 87cec505e..d80f5bb79 100644 --- a/server.go +++ b/server.go @@ -490,6 +490,9 @@ func newServer(cfg *Config, listenAddrs []net.Addr, s.htlcNotifier = htlcswitch.NewHtlcNotifier(time.Now) + thresholdSats := btcutil.Amount(cfg.DustThreshold) + thresholdMSats := lnwire.NewMSatFromSatoshis(thresholdSats) + s.htlcSwitch, err = htlcswitch.New(htlcswitch.Config{ DB: dbs.chanStateDB, LocalChannelClose: func(pubKey []byte, @@ -519,6 +522,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, RejectHTLC: cfg.RejectHTLC, Clock: clock.NewDefaultClock(), HTLCExpiry: htlcswitch.DefaultHTLCExpiry, + DustThreshold: thresholdMSats, }, uint32(currentHeight)) if err != nil { return nil, err