mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 06:07:16 +01:00
multi: break ChannelConstraints into two sub-structures
This commit breaks the ChannelConstraints structure into two sub-structures that reflect the fundamental differences in how these parameters are used. On its face it may not seem necessary, however the distinction introduced here is relevant for how we will be implementing the Dynamic Commitments proposal.
This commit is contained in:
@@ -1671,16 +1671,18 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
|
||||
|
||||
// We'll also validate and apply all the constraints the initiating
|
||||
// party is attempting to dictate for our commitment transaction.
|
||||
channelConstraints := &channeldb.ChannelConstraints{
|
||||
DustLimit: msg.DustLimit,
|
||||
stateBounds := &channeldb.ChannelStateBounds{
|
||||
ChanReserve: msg.ChannelReserve,
|
||||
MaxPendingAmount: msg.MaxValueInFlight,
|
||||
MinHTLC: msg.HtlcMinimum,
|
||||
MaxAcceptedHtlcs: msg.MaxAcceptedHTLCs,
|
||||
CsvDelay: msg.CsvDelay,
|
||||
}
|
||||
commitParams := &channeldb.CommitmentParams{
|
||||
DustLimit: msg.DustLimit,
|
||||
CsvDelay: msg.CsvDelay,
|
||||
}
|
||||
err = reservation.CommitConstraints(
|
||||
channelConstraints, f.cfg.MaxLocalCSVDelay, true,
|
||||
stateBounds, commitParams, f.cfg.MaxLocalCSVDelay, true,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Unacceptable channel constraints: %v", err)
|
||||
@@ -1780,7 +1782,7 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
|
||||
// interactively.
|
||||
ourContribution := reservation.OurContribution()
|
||||
forwardingPolicy := f.defaultForwardingPolicy(
|
||||
ourContribution.ChannelConstraints,
|
||||
ourContribution.ChannelStateBounds,
|
||||
)
|
||||
|
||||
// Once the reservation has been created successfully, we add it to
|
||||
@@ -1810,37 +1812,41 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
|
||||
// Update the timestamp once the fundingOpenMsg has been handled.
|
||||
defer resCtx.updateTimestamp()
|
||||
|
||||
cfg := channeldb.ChannelConfig{
|
||||
ChannelStateBounds: channeldb.ChannelStateBounds{
|
||||
MaxPendingAmount: remoteMaxValue,
|
||||
ChanReserve: chanReserve,
|
||||
MinHTLC: minHtlc,
|
||||
MaxAcceptedHtlcs: maxHtlcs,
|
||||
},
|
||||
CommitmentParams: channeldb.CommitmentParams{
|
||||
DustLimit: msg.DustLimit,
|
||||
CsvDelay: remoteCsvDelay,
|
||||
},
|
||||
MultiSigKey: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.FundingKey),
|
||||
},
|
||||
RevocationBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.RevocationPoint),
|
||||
},
|
||||
PaymentBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.PaymentPoint),
|
||||
},
|
||||
DelayBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.DelayedPaymentPoint),
|
||||
},
|
||||
HtlcBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.HtlcPoint),
|
||||
},
|
||||
}
|
||||
|
||||
// With our parameters set, we'll now process their contribution so we
|
||||
// can move the funding workflow ahead.
|
||||
remoteContribution := &lnwallet.ChannelContribution{
|
||||
FundingAmount: amt,
|
||||
FirstCommitmentPoint: msg.FirstCommitmentPoint,
|
||||
ChannelConfig: &channeldb.ChannelConfig{
|
||||
ChannelConstraints: channeldb.ChannelConstraints{
|
||||
DustLimit: msg.DustLimit,
|
||||
MaxPendingAmount: remoteMaxValue,
|
||||
ChanReserve: chanReserve,
|
||||
MinHTLC: minHtlc,
|
||||
MaxAcceptedHtlcs: maxHtlcs,
|
||||
CsvDelay: remoteCsvDelay,
|
||||
},
|
||||
MultiSigKey: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.FundingKey),
|
||||
},
|
||||
RevocationBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.RevocationPoint),
|
||||
},
|
||||
PaymentBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.PaymentPoint),
|
||||
},
|
||||
DelayBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.DelayedPaymentPoint),
|
||||
},
|
||||
HtlcBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.HtlcPoint),
|
||||
},
|
||||
},
|
||||
UpfrontShutdown: msg.UpfrontShutdownScript,
|
||||
ChannelConfig: &cfg,
|
||||
UpfrontShutdown: msg.UpfrontShutdownScript,
|
||||
}
|
||||
|
||||
if resCtx.reservation.IsTaproot() {
|
||||
@@ -1867,8 +1873,12 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
|
||||
|
||||
log.Infof("Sending fundingResp for pending_id(%x)",
|
||||
msg.PendingChannelID)
|
||||
log.Debugf("Remote party accepted commitment constraints: %v",
|
||||
spew.Sdump(remoteContribution.ChannelConfig.ChannelConstraints))
|
||||
bounds := remoteContribution.ChannelConfig.ChannelStateBounds
|
||||
log.Debugf("Remote party accepted channel state space bounds: %v",
|
||||
spew.Sdump(bounds))
|
||||
params := remoteContribution.ChannelConfig.CommitmentParams
|
||||
log.Debugf("Remote party accepted commitment rendering params: %v",
|
||||
spew.Sdump(params))
|
||||
|
||||
// With the initiator's contribution recorded, respond with our
|
||||
// contribution in the next message of the workflow.
|
||||
@@ -2036,16 +2046,18 @@ func (f *Manager) funderProcessAcceptChannel(peer lnpeer.Peer,
|
||||
// required confirmations, and also the set of channel constraints
|
||||
// they've specified for commitment states we can create.
|
||||
resCtx.reservation.SetNumConfsRequired(uint16(minDepth))
|
||||
channelConstraints := &channeldb.ChannelConstraints{
|
||||
DustLimit: msg.DustLimit,
|
||||
bounds := channeldb.ChannelStateBounds{
|
||||
ChanReserve: msg.ChannelReserve,
|
||||
MaxPendingAmount: msg.MaxValueInFlight,
|
||||
MinHTLC: msg.HtlcMinimum,
|
||||
MaxAcceptedHtlcs: msg.MaxAcceptedHTLCs,
|
||||
CsvDelay: msg.CsvDelay,
|
||||
}
|
||||
commitParams := channeldb.CommitmentParams{
|
||||
DustLimit: msg.DustLimit,
|
||||
CsvDelay: msg.CsvDelay,
|
||||
}
|
||||
err = resCtx.reservation.CommitConstraints(
|
||||
channelConstraints, resCtx.maxLocalCsv, false,
|
||||
&bounds, &commitParams, resCtx.maxLocalCsv, false,
|
||||
)
|
||||
if err != nil {
|
||||
log.Warnf("Unacceptable channel constraints: %v", err)
|
||||
@@ -2053,38 +2065,42 @@ func (f *Manager) funderProcessAcceptChannel(peer lnpeer.Peer,
|
||||
return
|
||||
}
|
||||
|
||||
cfg := channeldb.ChannelConfig{
|
||||
ChannelStateBounds: channeldb.ChannelStateBounds{
|
||||
MaxPendingAmount: resCtx.remoteMaxValue,
|
||||
ChanReserve: resCtx.remoteChanReserve,
|
||||
MinHTLC: resCtx.remoteMinHtlc,
|
||||
MaxAcceptedHtlcs: resCtx.remoteMaxHtlcs,
|
||||
},
|
||||
CommitmentParams: channeldb.CommitmentParams{
|
||||
DustLimit: msg.DustLimit,
|
||||
CsvDelay: resCtx.remoteCsvDelay,
|
||||
},
|
||||
MultiSigKey: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.FundingKey),
|
||||
},
|
||||
RevocationBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.RevocationPoint),
|
||||
},
|
||||
PaymentBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.PaymentPoint),
|
||||
},
|
||||
DelayBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.DelayedPaymentPoint),
|
||||
},
|
||||
HtlcBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.HtlcPoint),
|
||||
},
|
||||
}
|
||||
|
||||
// The remote node has responded with their portion of the channel
|
||||
// contribution. At this point, we can process their contribution which
|
||||
// allows us to construct and sign both the commitment transaction, and
|
||||
// the funding transaction.
|
||||
remoteContribution := &lnwallet.ChannelContribution{
|
||||
FirstCommitmentPoint: msg.FirstCommitmentPoint,
|
||||
ChannelConfig: &channeldb.ChannelConfig{
|
||||
ChannelConstraints: channeldb.ChannelConstraints{
|
||||
DustLimit: msg.DustLimit,
|
||||
MaxPendingAmount: resCtx.remoteMaxValue,
|
||||
ChanReserve: resCtx.remoteChanReserve,
|
||||
MinHTLC: resCtx.remoteMinHtlc,
|
||||
MaxAcceptedHtlcs: resCtx.remoteMaxHtlcs,
|
||||
CsvDelay: resCtx.remoteCsvDelay,
|
||||
},
|
||||
MultiSigKey: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.FundingKey),
|
||||
},
|
||||
RevocationBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.RevocationPoint),
|
||||
},
|
||||
PaymentBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.PaymentPoint),
|
||||
},
|
||||
DelayBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.DelayedPaymentPoint),
|
||||
},
|
||||
HtlcBasePoint: keychain.KeyDescriptor{
|
||||
PubKey: copyPubKey(msg.HtlcPoint),
|
||||
},
|
||||
},
|
||||
UpfrontShutdown: msg.UpfrontShutdownScript,
|
||||
ChannelConfig: &cfg,
|
||||
UpfrontShutdown: msg.UpfrontShutdownScript,
|
||||
}
|
||||
|
||||
if resCtx.reservation.IsTaproot() {
|
||||
@@ -2149,8 +2165,12 @@ func (f *Manager) funderProcessAcceptChannel(peer lnpeer.Peer,
|
||||
log.Infof("pendingChan(%x): remote party proposes num_confs=%v, "+
|
||||
"csv_delay=%v", pendingChanID[:], msg.MinAcceptDepth,
|
||||
msg.CsvDelay)
|
||||
log.Debugf("Remote party accepted commitment constraints: %v",
|
||||
spew.Sdump(remoteContribution.ChannelConfig.ChannelConstraints))
|
||||
bounds = remoteContribution.ChannelConfig.ChannelStateBounds
|
||||
log.Debugf("Remote party accepted channel state space bounds: %v",
|
||||
spew.Sdump(bounds))
|
||||
commitParams = remoteContribution.ChannelConfig.CommitmentParams
|
||||
log.Debugf("Remote party accepted commitment rendering params: %v",
|
||||
spew.Sdump(commitParams))
|
||||
|
||||
// If the user requested funding through a PSBT, we cannot directly
|
||||
// continue now and need to wait for the fully funded and signed PSBT
|
||||
@@ -4070,7 +4090,7 @@ func (f *Manager) ensureInitialForwardingPolicy(chanID lnwire.ChannelID,
|
||||
"falling back to default values: %v", err)
|
||||
|
||||
forwardingPolicy = f.defaultForwardingPolicy(
|
||||
channel.LocalChanCfg.ChannelConstraints,
|
||||
channel.LocalChanCfg.ChannelStateBounds,
|
||||
)
|
||||
needDBUpdate = true
|
||||
}
|
||||
@@ -4695,7 +4715,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
||||
// useBaseFee or useFeeRate are false the client did not provide fee
|
||||
// values hence we assume default fee settings from the config.
|
||||
forwardingPolicy := f.defaultForwardingPolicy(
|
||||
ourContribution.ChannelConstraints,
|
||||
ourContribution.ChannelStateBounds,
|
||||
)
|
||||
if baseFee != nil {
|
||||
forwardingPolicy.BaseFee = lnwire.MilliSatoshi(*baseFee)
|
||||
@@ -4750,16 +4770,18 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
||||
defer resCtx.updateTimestamp()
|
||||
|
||||
// Check the sanity of the selected channel constraints.
|
||||
channelConstraints := &channeldb.ChannelConstraints{
|
||||
DustLimit: ourDustLimit,
|
||||
bounds := &channeldb.ChannelStateBounds{
|
||||
ChanReserve: chanReserve,
|
||||
MaxPendingAmount: maxValue,
|
||||
MinHTLC: minHtlcIn,
|
||||
MaxAcceptedHtlcs: maxHtlcs,
|
||||
CsvDelay: remoteCsvDelay,
|
||||
}
|
||||
commitParams := &channeldb.CommitmentParams{
|
||||
DustLimit: ourDustLimit,
|
||||
CsvDelay: remoteCsvDelay,
|
||||
}
|
||||
err = lnwallet.VerifyConstraints(
|
||||
channelConstraints, resCtx.maxLocalCsv, capacity,
|
||||
bounds, commitParams, resCtx.maxLocalCsv, capacity,
|
||||
)
|
||||
if err != nil {
|
||||
_, reserveErr := f.cancelReservationCtx(peerKey, chanID, false)
|
||||
@@ -5032,11 +5054,11 @@ func copyPubKey(pub *btcec.PublicKey) *btcec.PublicKey {
|
||||
// defaultForwardingPolicy returns the default forwarding policy based on the
|
||||
// default routing policy and our local channel constraints.
|
||||
func (f *Manager) defaultForwardingPolicy(
|
||||
constraints channeldb.ChannelConstraints) *models.ForwardingPolicy {
|
||||
bounds channeldb.ChannelStateBounds) *models.ForwardingPolicy {
|
||||
|
||||
return &models.ForwardingPolicy{
|
||||
MinHTLCOut: constraints.MinHTLC,
|
||||
MaxHTLC: constraints.MaxPendingAmount,
|
||||
MinHTLCOut: bounds.MinHTLC,
|
||||
MaxHTLC: bounds.MaxPendingAmount,
|
||||
BaseFee: f.cfg.DefaultRoutingPolicy.BaseFee,
|
||||
FeeRate: f.cfg.DefaultRoutingPolicy.FeeRate,
|
||||
TimeLockDelta: f.cfg.DefaultRoutingPolicy.TimeLockDelta,
|
||||
|
||||
Reference in New Issue
Block a user