funding: enable configurable channel reserve
In this commit, the channel reserve of an initiated channel is made to be optionally configurable.
This commit is contained in:
1 parent
10f0eddd51
commit
6467b0ee12
2 files changed
+163
-70
No files matched your search
+60
-57
@@ -142,10 +142,11 @@ type reservationWithCtx struct {
|
||||
forwardingPolicy htlcswitch.ForwardingPolicy
|
||||
|
||||
// Constraints we require for the remote.
|
||||
remoteCsvDelay uint16
|
||||
remoteMinHtlc lnwire.MilliSatoshi
|
||||
remoteMaxValue lnwire.MilliSatoshi
|
||||
remoteMaxHtlcs uint16
|
||||
remoteCsvDelay uint16
|
||||
remoteMinHtlc lnwire.MilliSatoshi
|
||||
remoteMaxValue lnwire.MilliSatoshi
|
||||
remoteMaxHtlcs uint16
|
||||
remoteChanReserve btcutil.Amount
|
||||
|
||||
// maxLocalCsv is the maximum csv we will accept from the remote.
|
||||
maxLocalCsv uint16
|
||||
@@ -224,6 +225,10 @@ type InitFundingMsg struct {
|
||||
// RemoteCsvDelay is the CSV delay we require for the remote peer.
|
||||
RemoteCsvDelay uint16
|
||||
|
||||
// RemoteChanReserve is the channel reserve we required for the remote
|
||||
// peer.
|
||||
RemoteChanReserve btcutil.Amount
|
||||
|
||||
// MinConfs indicates the minimum number of confirmations that each
|
||||
// output selected to fund the channel should satisfy.
|
||||
MinConfs int32
|
||||
@@ -1620,17 +1625,18 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
|
||||
f.activeReservations[peerIDKey] = make(pendingChannels)
|
||||
}
|
||||
resCtx := &reservationWithCtx{
|
||||
reservation: reservation,
|
||||
chanAmt: amt,
|
||||
forwardingPolicy: forwardingPolicy,
|
||||
remoteCsvDelay: remoteCsvDelay,
|
||||
remoteMinHtlc: minHtlc,
|
||||
remoteMaxValue: remoteMaxValue,
|
||||
remoteMaxHtlcs: maxHtlcs,
|
||||
maxLocalCsv: f.cfg.MaxLocalCSVDelay,
|
||||
channelType: msg.ChannelType,
|
||||
err: make(chan error, 1),
|
||||
peer: peer,
|
||||
reservation: reservation,
|
||||
chanAmt: amt,
|
||||
forwardingPolicy: forwardingPolicy,
|
||||
remoteCsvDelay: remoteCsvDelay,
|
||||
remoteMinHtlc: minHtlc,
|
||||
remoteMaxValue: remoteMaxValue,
|
||||
remoteMaxHtlcs: maxHtlcs,
|
||||
remoteChanReserve: chanReserve,
|
||||
maxLocalCsv: f.cfg.MaxLocalCSVDelay,
|
||||
channelType: msg.ChannelType,
|
||||
err: make(chan error, 1),
|
||||
peer: peer,
|
||||
}
|
||||
f.activeReservations[peerIDKey][msg.PendingChannelID] = resCtx
|
||||
f.resMtx.Unlock()
|
||||
@@ -1850,14 +1856,6 @@ func (f *Manager) handleFundingAccept(peer lnpeer.Peer,
|
||||
return
|
||||
}
|
||||
|
||||
// As they've accepted our channel constraints, we'll regenerate them
|
||||
// here so we can properly commit their accepted constraints to the
|
||||
// reservation. Also make sure that we re-generate the ChannelReserve
|
||||
// with our dust limit or we can get stuck channels.
|
||||
chanReserve := f.cfg.RequiredRemoteChanReserve(
|
||||
resCtx.chanAmt, resCtx.reservation.OurContribution().DustLimit,
|
||||
)
|
||||
|
||||
// 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
|
||||
@@ -1868,7 +1866,7 @@ func (f *Manager) handleFundingAccept(peer lnpeer.Peer,
|
||||
ChannelConstraints: channeldb.ChannelConstraints{
|
||||
DustLimit: msg.DustLimit,
|
||||
MaxPendingAmount: resCtx.remoteMaxValue,
|
||||
ChanReserve: chanReserve,
|
||||
ChanReserve: resCtx.remoteChanReserve,
|
||||
MinHTLC: resCtx.remoteMinHtlc,
|
||||
MaxAcceptedHtlcs: resCtx.remoteMaxHtlcs,
|
||||
CsvDelay: resCtx.remoteCsvDelay,
|
||||
@@ -3888,6 +3886,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
||||
maxValue = msg.MaxValueInFlight
|
||||
maxHtlcs = msg.MaxHtlcs
|
||||
maxCSV = msg.MaxLocalCsv
|
||||
chanReserve = msg.RemoteChanReserve
|
||||
)
|
||||
|
||||
// If no maximum CSV delay was set for this channel, we use our default
|
||||
@@ -4092,35 +4091,6 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
||||
forwardingPolicy.FeeRate = lnwire.MilliSatoshi(*feeRate)
|
||||
}
|
||||
|
||||
// If a pending channel map for this peer isn't already created, then
|
||||
// we create one, ultimately allowing us to track this pending
|
||||
// reservation within the target peer.
|
||||
peerIDKey := newSerializedKey(peerKey)
|
||||
f.resMtx.Lock()
|
||||
if _, ok := f.activeReservations[peerIDKey]; !ok {
|
||||
f.activeReservations[peerIDKey] = make(pendingChannels)
|
||||
}
|
||||
|
||||
resCtx := &reservationWithCtx{
|
||||
chanAmt: capacity,
|
||||
forwardingPolicy: forwardingPolicy,
|
||||
remoteCsvDelay: remoteCsvDelay,
|
||||
remoteMinHtlc: minHtlcIn,
|
||||
remoteMaxValue: maxValue,
|
||||
remoteMaxHtlcs: maxHtlcs,
|
||||
maxLocalCsv: maxCSV,
|
||||
channelType: msg.ChannelType,
|
||||
reservation: reservation,
|
||||
peer: msg.Peer,
|
||||
updates: msg.Updates,
|
||||
err: msg.Err,
|
||||
}
|
||||
f.activeReservations[peerIDKey][chanID] = resCtx
|
||||
f.resMtx.Unlock()
|
||||
|
||||
// Update the timestamp once the InitFundingMsg has been handled.
|
||||
defer resCtx.updateTimestamp()
|
||||
|
||||
// Once the reservation has been created, and indexed, queue a funding
|
||||
// request to the remote peer, kicking off the funding workflow.
|
||||
ourContribution := reservation.OurContribution()
|
||||
@@ -4131,10 +4101,43 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
||||
|
||||
log.Infof("Dust limit for pendingID(%x): %v", chanID, ourDustLimit)
|
||||
|
||||
// Finally, we'll use the current value of the channels and our default
|
||||
// policy to determine of required commitment constraints for the
|
||||
// remote party.
|
||||
chanReserve := f.cfg.RequiredRemoteChanReserve(capacity, ourDustLimit)
|
||||
// If the channel reserve is not specified, then we calculate an
|
||||
// appropriate amount here.
|
||||
if chanReserve == 0 {
|
||||
chanReserve = f.cfg.RequiredRemoteChanReserve(
|
||||
capacity, ourDustLimit,
|
||||
)
|
||||
}
|
||||
|
||||
// If a pending channel map for this peer isn't already created, then
|
||||
// we create one, ultimately allowing us to track this pending
|
||||
// reservation within the target peer.
|
||||
peerIDKey := newSerializedKey(peerKey)
|
||||
f.resMtx.Lock()
|
||||
if _, ok := f.activeReservations[peerIDKey]; !ok {
|
||||
f.activeReservations[peerIDKey] = make(pendingChannels)
|
||||
}
|
||||
|
||||
resCtx := &reservationWithCtx{
|
||||
chanAmt: capacity,
|
||||
forwardingPolicy: forwardingPolicy,
|
||||
remoteCsvDelay: remoteCsvDelay,
|
||||
remoteMinHtlc: minHtlcIn,
|
||||
remoteMaxValue: maxValue,
|
||||
remoteMaxHtlcs: maxHtlcs,
|
||||
remoteChanReserve: chanReserve,
|
||||
maxLocalCsv: maxCSV,
|
||||
channelType: msg.ChannelType,
|
||||
reservation: reservation,
|
||||
peer: msg.Peer,
|
||||
updates: msg.Updates,
|
||||
err: msg.Err,
|
||||
}
|
||||
f.activeReservations[peerIDKey][chanID] = resCtx
|
||||
f.resMtx.Unlock()
|
||||
|
||||
// Update the timestamp once the InitFundingMsg has been handled.
|
||||
defer resCtx.updateTimestamp()
|
||||
|
||||
// Check the sanity of the selected channel constraints.
|
||||
channelConstraints := &channeldb.ChannelConstraints{
|
||||
|
||||
Reference in new issue
Block a user