multi: make PendingCommitInterval configurable

This commit is contained in:
yyforyongyu 2022-01-21 07:44:57 +08:00
parent 13ade7e9ce
commit 1c8c0b4fa0
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
4 changed files with 63 additions and 24 deletions

View file

@ -168,14 +168,24 @@ const (
// TODO(halseth): find a more scientific choice of value.
defaultMaxLocalCSVDelay = 10000
// defaultChannelCommitInterval is the default maximum time between receiving a
// channel state update and signing a new commitment.
// defaultChannelCommitInterval is the default maximum time between
// receiving a channel state update and signing a new commitment.
defaultChannelCommitInterval = 50 * time.Millisecond
// maxChannelCommitInterval is the maximum time the commit interval can
// be configured to.
maxChannelCommitInterval = time.Hour
// defaultPendingCommitInterval specifies the default timeout value
// while waiting for the remote party to revoke a locally initiated
// commitment state.
defaultPendingCommitInterval = 1 * time.Minute
// maxPendingCommitInterval specifies the max allowed duration when
// waiting for the remote party to revoke a locally initiated
// commitment state.
maxPendingCommitInterval = 5 * time.Minute
// defaultChannelCommitBatchSize is the default maximum number of
// channel state updates that is accumulated before signing a new
// commitment.
@ -340,8 +350,11 @@ type Config struct {
MaxChanSize int64 `long:"maxchansize" description:"The largest channel size (in satoshis) that we should accept. Incoming channels larger than this will be rejected"`
CoopCloseTargetConfs uint32 `long:"coop-close-target-confs" description:"The target number of blocks that a cooperative channel close transaction should confirm in. This is used to estimate the fee to use as the lower bound during fee negotiation for the channel closure."`
ChannelCommitInterval time.Duration `long:"channel-commit-interval" description:"The maximum time that is allowed to pass between receiving a channel state update and signing the next commitment. Setting this to a longer duration allows for more efficient channel operations at the cost of latency."`
ChannelCommitBatchSize uint32 `long:"channel-commit-batch-size" description:"The maximum number of channel state updates that is accumulated before signing a new commitment."`
ChannelCommitInterval time.Duration `long:"channel-commit-interval" description:"The maximum time that is allowed to pass between receiving a channel state update and signing the next commitment. Setting this to a longer duration allows for more efficient channel operations at the cost of latency."`
PendingCommitInterval time.Duration `long:"pending-commit-interval" description:"The maximum time that is allowed to pass while waiting for the remote party to revoke a locally initiated commitment state. Setting this to a longer duration if a slow response is expected from the remote party or large number of payments are attempted at the same time."`
ChannelCommitBatchSize uint32 `long:"channel-commit-batch-size" description:"The maximum number of channel state updates that is accumulated before signing a new commitment."`
DefaultRemoteMaxHtlcs uint16 `long:"default-remote-max-htlcs" description:"The default max_htlc applied when opening or accepting channels. This value limits the number of concurrent HTLCs that the remote party can add to the commitment. The maximum possible value is 483."`
@ -601,6 +614,7 @@ func DefaultConfig() Config {
registeredChains: chainreg.NewChainRegistry(),
ActiveNetParams: chainreg.BitcoinTestNetParams,
ChannelCommitInterval: defaultChannelCommitInterval,
PendingCommitInterval: defaultPendingCommitInterval,
ChannelCommitBatchSize: defaultChannelCommitBatchSize,
CoinSelectionStrategy: defaultCoinSelectionStrategy,
RemoteSigner: &lncfg.RemoteSigner{
@ -1578,6 +1592,14 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
maxChannelCommitInterval)
}
// Limit PendingCommitInterval so we don't wait too long for the remote
// party to send back a revoke.
if cfg.PendingCommitInterval > maxPendingCommitInterval {
return nil, mkErr("pending-commit-interval (%v) must be less "+
"than %v", cfg.PendingCommitInterval,
maxPendingCommitInterval)
}
if err := cfg.Gossip.Parse(); err != nil {
return nil, mkErr("error parsing gossip syncer: %v", err)
}

View file

@ -318,6 +318,13 @@ type Config struct {
// operations at the cost of latency.
ChannelCommitInterval time.Duration
// PendingCommitInterval is the maximum time that is allowed to pass
// while waiting for the remote party to revoke a locally initiated
// commitment state. Setting this to a longer duration if a slow
// response is expected from the remote party or large number of
// payments are attempted at the same time.
PendingCommitInterval time.Duration
// ChannelCommitBatchSize is the maximum number of channel state updates
// that is accumulated before signing a new commitment.
ChannelCommitBatchSize uint32
@ -832,26 +839,28 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint,
}
linkCfg := htlcswitch.ChannelLinkConfig{
Peer: p,
DecodeHopIterators: p.cfg.Sphinx.DecodeHopIterators,
ExtractErrorEncrypter: p.cfg.Sphinx.ExtractErrorEncrypter,
FetchLastChannelUpdate: p.cfg.FetchLastChanUpdate,
HodlMask: p.cfg.Hodl.Mask(),
Registry: p.cfg.Invoices,
BestHeight: p.cfg.Switch.BestHeight,
Circuits: p.cfg.Switch.CircuitModifier(),
ForwardPackets: p.cfg.InterceptSwitch.ForwardPackets,
FwrdingPolicy: *forwardingPolicy,
FeeEstimator: p.cfg.FeeEstimator,
PreimageCache: p.cfg.WitnessBeacon,
ChainEvents: chainEvents,
UpdateContractSignals: updateContractSignals,
NotifyContractUpdate: notifyContractUpdate,
OnChannelFailure: onChannelFailure,
SyncStates: syncStates,
BatchTicker: ticker.New(p.cfg.ChannelCommitInterval),
FwdPkgGCTicker: ticker.New(time.Hour),
PendingCommitTicker: ticker.New(time.Minute),
Peer: p,
DecodeHopIterators: p.cfg.Sphinx.DecodeHopIterators,
ExtractErrorEncrypter: p.cfg.Sphinx.ExtractErrorEncrypter,
FetchLastChannelUpdate: p.cfg.FetchLastChanUpdate,
HodlMask: p.cfg.Hodl.Mask(),
Registry: p.cfg.Invoices,
BestHeight: p.cfg.Switch.BestHeight,
Circuits: p.cfg.Switch.CircuitModifier(),
ForwardPackets: p.cfg.InterceptSwitch.ForwardPackets,
FwrdingPolicy: *forwardingPolicy,
FeeEstimator: p.cfg.FeeEstimator,
PreimageCache: p.cfg.WitnessBeacon,
ChainEvents: chainEvents,
UpdateContractSignals: updateContractSignals,
NotifyContractUpdate: notifyContractUpdate,
OnChannelFailure: onChannelFailure,
SyncStates: syncStates,
BatchTicker: ticker.New(p.cfg.ChannelCommitInterval),
FwdPkgGCTicker: ticker.New(time.Hour),
PendingCommitTicker: ticker.New(
p.cfg.PendingCommitInterval,
),
BatchSize: p.cfg.ChannelCommitBatchSize,
UnsafeReplay: p.cfg.UnsafeReplay,
MinFeeUpdateTimeout: htlcswitch.DefaultMinLinkFeeUpdateTimeout,

View file

@ -297,6 +297,13 @@
; capped at 1 hour. The default is 50 milliseconds.
; channel-commit-interval=1h
; The maximum time that is allowed to pass while waiting for the remote party
; to revoke a locally initiated commitment state. Setting this to a longer
; duration if a slow response is expected from the remote party or large
; number of payments are attempted at the same time.
; (default: 1m0s)
; pending-commit-interval=5m
; The maximum number of channel state updates that is accumulated before signing
; a new commitment.
; channel-commit-batch-size=10

View file

@ -3526,6 +3526,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
MaxAnchorsCommitFeeRate: chainfee.SatPerKVByte(
s.cfg.MaxCommitFeeRateAnchors * 1000).FeePerKWeight(),
ChannelCommitInterval: s.cfg.ChannelCommitInterval,
PendingCommitInterval: s.cfg.PendingCommitInterval,
ChannelCommitBatchSize: s.cfg.ChannelCommitBatchSize,
HandleCustomMessage: s.handleCustomMessage,
Quit: s.quit,