fundingmanager+lnd: propose remote channel reserve above dust limit

This commit is contained in:
Wilmer Paulino 2018-05-14 14:03:58 -04:00
parent 3c33a8cb67
commit 2e076ba21e
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
3 changed files with 29 additions and 16 deletions

@ -279,10 +279,10 @@ type fundingConfig struct {
RequiredRemoteDelay func(btcutil.Amount) uint16 RequiredRemoteDelay func(btcutil.Amount) uint16
// RequiredRemoteChanReserve is a function closure that, given the // RequiredRemoteChanReserve is a function closure that, given the
// channel capacity, will return an appropriate amount for the remote // channel capacity and dust limit, will return an appropriate amount
// peer's required channel reserve that is to be adhered to at all // for the remote peer's required channel reserve that is to be adhered
// times. // to at all times.
RequiredRemoteChanReserve func(btcutil.Amount) btcutil.Amount RequiredRemoteChanReserve func(capacity, dustLimit btcutil.Amount) btcutil.Amount
// RequiredRemoteMaxValue is a function closure that, given the channel // RequiredRemoteMaxValue is a function closure that, given the channel
// capacity, returns the amount of MilliSatoshis that our remote peer // capacity, returns the amount of MilliSatoshis that our remote peer
@ -1008,12 +1008,9 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
"amt=%v, push_amt=%v", numConfsReq, fmsg.msg.PendingChannelID, "amt=%v, push_amt=%v", numConfsReq, fmsg.msg.PendingChannelID,
amt, msg.PushAmount) amt, msg.PushAmount)
// Using the RequiredRemoteDelay closure, we'll compute the remote CSV // Generate our required constraints for the remote party.
// delay we require given the total amount of funds within the channel.
remoteCsvDelay := f.cfg.RequiredRemoteDelay(amt) remoteCsvDelay := f.cfg.RequiredRemoteDelay(amt)
chanReserve := f.cfg.RequiredRemoteChanReserve(amt, msg.DustLimit)
// We'll also generate our required constraints for the remote party,
chanReserve := f.cfg.RequiredRemoteChanReserve(amt)
maxValue := f.cfg.RequiredRemoteMaxValue(amt) maxValue := f.cfg.RequiredRemoteMaxValue(amt)
maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(amt) maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(amt)
minHtlc := f.cfg.DefaultRoutingPolicy.MinHTLC minHtlc := f.cfg.DefaultRoutingPolicy.MinHTLC
@ -1161,7 +1158,7 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) {
// As they've accepted our channel constraints, we'll regenerate them // As they've accepted our channel constraints, we'll regenerate them
// here so we can properly commit their accepted constraints to the // here so we can properly commit their accepted constraints to the
// reservation. // reservation.
chanReserve := f.cfg.RequiredRemoteChanReserve(resCtx.chanAmt) chanReserve := f.cfg.RequiredRemoteChanReserve(resCtx.chanAmt, msg.DustLimit)
maxValue := f.cfg.RequiredRemoteMaxValue(resCtx.chanAmt) maxValue := f.cfg.RequiredRemoteMaxValue(resCtx.chanAmt)
maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(resCtx.chanAmt) maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(resCtx.chanAmt)
@ -2573,7 +2570,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
// Finally, we'll use the current value of the channels and our default // Finally, we'll use the current value of the channels and our default
// policy to determine of required commitment constraints for the // policy to determine of required commitment constraints for the
// remote party. // remote party.
chanReserve := f.cfg.RequiredRemoteChanReserve(capacity) chanReserve := f.cfg.RequiredRemoteChanReserve(capacity, ourDustLimit)
maxValue := f.cfg.RequiredRemoteMaxValue(capacity) maxValue := f.cfg.RequiredRemoteMaxValue(capacity)
maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(capacity) maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(capacity)

@ -294,8 +294,15 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
RequiredRemoteDelay: func(amt btcutil.Amount) uint16 { RequiredRemoteDelay: func(amt btcutil.Amount) uint16 {
return 4 return 4
}, },
RequiredRemoteChanReserve: func(chanAmt btcutil.Amount) btcutil.Amount { RequiredRemoteChanReserve: func(chanAmt,
return chanAmt / 100 dustLimit btcutil.Amount) btcutil.Amount {
reserve := chanAmt / 100
if reserve < dustLimit {
reserve = dustLimit
}
return reserve
}, },
RequiredRemoteMaxValue: func(chanAmt btcutil.Amount) lnwire.MilliSatoshi { RequiredRemoteMaxValue: func(chanAmt btcutil.Amount) lnwire.MilliSatoshi {
reserve := lnwire.NewMSatFromSatoshis(chanAmt / 100) reserve := lnwire.NewMSatFromSatoshis(chanAmt / 100)

15
lnd.go

@ -464,11 +464,20 @@ func lndMain() error {
cid := lnwire.NewChanIDFromOutPoint(&chanPoint) cid := lnwire.NewChanIDFromOutPoint(&chanPoint)
return server.htlcSwitch.UpdateShortChanID(cid) return server.htlcSwitch.UpdateShortChanID(cid)
}, },
RequiredRemoteChanReserve: func(chanAmt btcutil.Amount) btcutil.Amount { RequiredRemoteChanReserve: func(chanAmt,
dustLimit btcutil.Amount) btcutil.Amount {
// By default, we'll require the remote peer to maintain // By default, we'll require the remote peer to maintain
// at least 1% of the total channel capacity at all // at least 1% of the total channel capacity at all
// times. // times. If this value ends up dipping below the dust
return chanAmt / 100 // limit, then we'll use the dust limit itself as the
// reserve as required by BOLT #2.
reserve := chanAmt / 100
if reserve < dustLimit {
reserve = dustLimit
}
return reserve
}, },
RequiredRemoteMaxValue: func(chanAmt btcutil.Amount) lnwire.MilliSatoshi { RequiredRemoteMaxValue: func(chanAmt btcutil.Amount) lnwire.MilliSatoshi {
// By default, we'll allow the remote peer to fully // By default, we'll allow the remote peer to fully