chanfunding: allow to set a reserved amount not used for funding
This commit is contained in:
1 parent
d7f578b0d9
commit
8c1cf21707
5 files changed
+99
-23
No files matched your search
+30
-6
@@ -836,6 +836,7 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
|
||||
|
||||
localFundingAmt := req.LocalFundingAmt
|
||||
remoteFundingAmt := req.RemoteFundingAmt
|
||||
hasAnchors := req.CommitType.HasAnchors()
|
||||
|
||||
var (
|
||||
fundingIntent chanfunding.Intent
|
||||
@@ -855,9 +856,33 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
|
||||
// funder in the attached request to provision the inputs/outputs
|
||||
// that'll ultimately be used to construct the funding transaction.
|
||||
if !ok {
|
||||
var err error
|
||||
var numAnchorChans int
|
||||
|
||||
// Get the number of anchor channels to determine if there is a
|
||||
// reserved value that must be respected when funding up to the
|
||||
// maximum amount. Since private channels (most likely) won't be
|
||||
// used for routing other than the last hop, they bear a smaller
|
||||
// risk that we must force close them in order to resolve a HTLC
|
||||
// up/downstream. Hence we exclude them from the count of anchor
|
||||
// channels in order to attribute the respective anchor amount
|
||||
// to the channel capacity.
|
||||
if req.FundUpToMaxAmt > 0 && req.MinFundAmt > 0 {
|
||||
numAnchorChans, err = l.CurrentNumAnchorChans()
|
||||
if err != nil {
|
||||
req.err <- err
|
||||
req.resp <- nil
|
||||
return
|
||||
}
|
||||
|
||||
isPublic := req.Flags&lnwire.FFAnnounceChannel != 0
|
||||
if hasAnchors && isPublic {
|
||||
numAnchorChans++
|
||||
}
|
||||
}
|
||||
|
||||
// Coin selection is done on the basis of sat/kw, so we'll use
|
||||
// the fee rate passed in to perform coin selection.
|
||||
var err error
|
||||
fundingReq := &chanfunding.Request{
|
||||
RemoteAmt: req.RemoteFundingAmt,
|
||||
LocalAmt: req.LocalFundingAmt,
|
||||
@@ -867,6 +892,9 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
|
||||
PushAmt: lnwire.MilliSatoshi.ToSatoshis(
|
||||
req.PushMSat,
|
||||
),
|
||||
WalletReserve: l.RequiredReserve(
|
||||
uint32(numAnchorChans),
|
||||
),
|
||||
MinConfs: req.MinConfs,
|
||||
SubtractFees: req.SubtractFees,
|
||||
FeeRate: req.FundingFeePerKw,
|
||||
@@ -939,7 +967,6 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
|
||||
// funding tx ready, so this will always pass. We'll do another check
|
||||
// when the PSBT has been verified.
|
||||
isPublic := req.Flags&lnwire.FFAnnounceChannel != 0
|
||||
hasAnchors := req.CommitType.HasAnchors()
|
||||
if enforceNewReservedValue {
|
||||
err = l.enforceNewReservedValue(fundingIntent, isPublic, hasAnchors)
|
||||
if err != nil {
|
||||
@@ -1160,10 +1187,7 @@ func (l *LightningWallet) CheckReservedValue(in []wire.OutPoint,
|
||||
}
|
||||
|
||||
// We reserve a given amount for each anchor channel.
|
||||
reserved := btcutil.Amount(numAnchorChans) * AnchorChanReservedValue
|
||||
if reserved > MaxAnchorChanReservedValue {
|
||||
reserved = MaxAnchorChanReservedValue
|
||||
}
|
||||
reserved := l.RequiredReserve(uint32(numAnchorChans))
|
||||
|
||||
if walletBalance < reserved {
|
||||
walletLog.Debugf("Reserved value=%v above final "+
|
||||
|
||||
Reference in new issue
Block a user