Merge pull request #7066 from yyforyongyu/switch-config-mailbox

htlcswitch: make mailbox HTLC delivery timeout configurable
This commit is contained in:
Oliver Gugger 2022-11-15 11:50:03 +01:00 committed by GitHub
commit 817af408e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 21 deletions

View File

@ -444,6 +444,8 @@ type Config struct {
Sweeper *lncfg.Sweeper `group:"sweeper" namespace:"sweeper"` Sweeper *lncfg.Sweeper `group:"sweeper" namespace:"sweeper"`
Htlcswitch *lncfg.Htlcswitch `group:"htlcswitch" namespace:"htlcswitch"`
// LogWriter is the root logger that all of the daemon's subloggers are // LogWriter is the root logger that all of the daemon's subloggers are
// hooked up to. // hooked up to.
LogWriter *build.RotatingLogWriter LogWriter *build.RotatingLogWriter
@ -462,6 +464,8 @@ type Config struct {
} }
// DefaultConfig returns all default values for the Config struct. // DefaultConfig returns all default values for the Config struct.
//
// nolint:lll
func DefaultConfig() Config { func DefaultConfig() Config {
return Config{ return Config{
LndDir: DefaultLndDir, LndDir: DefaultLndDir,
@ -643,6 +647,9 @@ func DefaultConfig() Config {
Sweeper: &lncfg.Sweeper{ Sweeper: &lncfg.Sweeper{
BatchWindowDuration: sweep.DefaultBatchWindowDuration, BatchWindowDuration: sweep.DefaultBatchWindowDuration,
}, },
Htlcswitch: &lncfg.Htlcswitch{
MailboxDeliveryTimeout: htlcswitch.DefaultMailboxDeliveryTimeout,
},
} }
} }
@ -1660,6 +1667,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
cfg.RPCMiddleware, cfg.RPCMiddleware,
cfg.RemoteSigner, cfg.RemoteSigner,
cfg.Sweeper, cfg.Sweeper,
cfg.Htlcswitch,
) )
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -168,6 +168,9 @@ certain large transactions](https://github.com/lightningnetwork/lnd/pull/7100).
received](https://github.com/lightningnetwork/lnd/pull/7126) to avoid CPU received](https://github.com/lightningnetwork/lnd/pull/7126) to avoid CPU
spike. spike.
* [A new config option, `mailboxdeliverytimeout` has been added to
`htlcswitch`](https://github.com/lightningnetwork/lnd/pull/7066).
## Code Health ## Code Health
* [test: use `T.TempDir` to create temporary test * [test: use `T.TempDir` to create temporary test

View File

@ -190,15 +190,17 @@ func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error)
EpochChan: make(chan *chainntnfs.BlockEpoch), EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation), ConfChan: make(chan *chainntnfs.TxConfirmation),
}, },
FwdEventTicker: ticker.NewForce(DefaultFwdEventInterval), FwdEventTicker: ticker.NewForce(
LogEventTicker: ticker.NewForce(DefaultLogInterval), DefaultFwdEventInterval,
AckEventTicker: ticker.NewForce(DefaultAckInterval), ),
HtlcNotifier: &mockHTLCNotifier{}, LogEventTicker: ticker.NewForce(DefaultLogInterval),
Clock: clock.NewDefaultClock(), AckEventTicker: ticker.NewForce(DefaultAckInterval),
HTLCExpiry: time.Hour, HtlcNotifier: &mockHTLCNotifier{},
DustThreshold: DefaultDustThreshold, Clock: clock.NewDefaultClock(),
SignAliasUpdate: signAliasUpdate, MailboxDeliveryTimeout: time.Hour,
IsAlias: isAlias, DustThreshold: DefaultDustThreshold,
SignAliasUpdate: signAliasUpdate,
IsAlias: isAlias,
} }
return New(cfg, startingHeight) return New(cfg, startingHeight)

View File

@ -39,9 +39,9 @@ const (
// fails in a forwarding package. // fails in a forwarding package.
DefaultAckInterval = 15 * time.Second DefaultAckInterval = 15 * time.Second
// DefaultHTLCExpiry is the duration after which Adds will be cancelled // DefaultMailboxDeliveryTimeout is the duration after which Adds will
// if they could not get added to an outgoing commitment. // be cancelled if they could not get added to an outgoing commitment.
DefaultHTLCExpiry = time.Minute DefaultMailboxDeliveryTimeout = time.Minute
) )
var ( var (
@ -202,11 +202,11 @@ type Config struct {
// Clock is a time source for the switch. // Clock is a time source for the switch.
Clock clock.Clock Clock clock.Clock
// HTLCExpiry is the interval after which Adds will be cancelled if they // MailboxDeliveryTimeout is the interval after which Adds will be
// have not been yet been delivered to a link. The computed deadline // cancelled if they have not been yet been delivered to a link. The
// will expiry this long after the Adds are added to a mailbox via // computed deadline will expiry this long after the Adds are added to
// AddPacket. // a mailbox via AddPacket.
HTLCExpiry time.Duration MailboxDeliveryTimeout time.Duration
// DustThreshold is the threshold in milli-satoshis after which we'll // DustThreshold is the threshold in milli-satoshis after which we'll
// fail incoming or outgoing dust payments for a particular channel. // fail incoming or outgoing dust payments for a particular channel.
@ -386,7 +386,7 @@ func New(cfg Config, currentHeight uint32) (*Switch, error) {
s.mailOrchestrator = newMailOrchestrator(&mailOrchConfig{ s.mailOrchestrator = newMailOrchestrator(&mailOrchConfig{
forwardPackets: s.ForwardPackets, forwardPackets: s.ForwardPackets,
clock: s.cfg.Clock, clock: s.cfg.Clock,
expiry: s.cfg.HTLCExpiry, expiry: s.cfg.MailboxDeliveryTimeout,
failMailboxUpdate: s.failMailboxUpdate, failMailboxUpdate: s.failMailboxUpdate,
}) })

34
lncfg/htlcswitch.go Normal file
View File

@ -0,0 +1,34 @@
package lncfg
import (
"fmt"
"time"
)
var (
// MaxMailboxDeliveryTimeout specifies the max allowed timeout value.
// This value is derived from the itest `async_bidirectional_payments`,
// where both side send 483 payments at the same time to stress test
// lnd.
MaxMailboxDeliveryTimeout = 2 * time.Minute
)
// nolint:lll
type Htlcswitch struct {
MailboxDeliveryTimeout time.Duration `long:"mailboxdeliverytimeout" description:"The timeout value when delivering HTLCs to a channel link. Setting this value too small will result in local payment failures if large number of payments are sent over a short period."`
}
// Validate checks the values configured for htlcswitch.
func (h *Htlcswitch) Validate() error {
if h.MailboxDeliveryTimeout <= 0 {
return fmt.Errorf("mailboxdeliverytimeout must be positive")
}
if h.MailboxDeliveryTimeout > MaxMailboxDeliveryTimeout {
return fmt.Errorf("mailboxdeliverytimeout: %v exceeds "+
"maximum: %v", h.MailboxDeliveryTimeout,
MaxMailboxDeliveryTimeout)
}
return nil
}

View File

@ -1423,3 +1423,10 @@ litecoin.node=ltcd
; window to allow more inputs to be added and thereby lower the fee per input. ; window to allow more inputs to be added and thereby lower the fee per input.
; sweeper.batchwindowduration=30s ; sweeper.batchwindowduration=30s
[htlcswitch]
; The timeout value when delivering HTLCs to a channel link. Setting this value
; too small will result in local payment failures if large number of payments
; are sent over a short period.
; htlcswitch.mailboxdeliverytimeout=60s

View File

@ -658,7 +658,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
AllowCircularRoute: cfg.AllowCircularRoute, AllowCircularRoute: cfg.AllowCircularRoute,
RejectHTLC: cfg.RejectHTLC, RejectHTLC: cfg.RejectHTLC,
Clock: clock.NewDefaultClock(), Clock: clock.NewDefaultClock(),
HTLCExpiry: htlcswitch.DefaultHTLCExpiry, MailboxDeliveryTimeout: cfg.Htlcswitch.MailboxDeliveryTimeout,
DustThreshold: thresholdMSats, DustThreshold: thresholdMSats,
SignAliasUpdate: s.signAliasUpdate, SignAliasUpdate: s.signAliasUpdate,
IsAlias: aliasmgr.IsAlias, IsAlias: aliasmgr.IsAlias,
@ -997,8 +997,8 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
return nil, err return nil, err
} }
srvrLog.Tracef("Sweeper batch window duration: %v", srvrLog.Debugf("Sweeper batch window duration: %v",
sweep.DefaultBatchWindowDuration) cfg.Sweeper.BatchWindowDuration)
sweeperStore, err := sweep.NewSweeperStore( sweeperStore, err := sweep.NewSweeperStore(
dbs.ChanStateDB, s.cfg.ActiveNetParams.GenesisHash, dbs.ChanStateDB, s.cfg.ActiveNetParams.GenesisHash,