fundingmanager: channel constraints closures
This commit makes more channel constraints available via closures part of the fundingConfig, moving them from the reservation.RemoteChanConstraints method.
This commit is contained in:
parent
509adce2ad
commit
997b1ea8ee
@ -236,6 +236,22 @@ type fundingConfig struct {
|
|||||||
// contract breach.
|
// contract breach.
|
||||||
RequiredRemoteDelay func(btcutil.Amount) uint16
|
RequiredRemoteDelay func(btcutil.Amount) uint16
|
||||||
|
|
||||||
|
// RequiredRemoteChanReserve is a function closure that, given the
|
||||||
|
// channel capacity, will return an appropriate amount for the remote
|
||||||
|
// peer's required channel reserve that is to be adhered to at all
|
||||||
|
// times.
|
||||||
|
RequiredRemoteChanReserve func(btcutil.Amount) btcutil.Amount
|
||||||
|
|
||||||
|
// RequiredRemoteMaxValue is a function closure that, given the
|
||||||
|
// channel capacity, returns the amount of MilliSatoshis that our
|
||||||
|
// remote peer can have in total outstanding HTLCs with us.
|
||||||
|
RequiredRemoteMaxValue func(btcutil.Amount) lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// RequiredRemoteMaxHTLCs is a function closure that, given the
|
||||||
|
// channel capacity, returns the number of maximum HTLCs the remote
|
||||||
|
// peer can offer us.
|
||||||
|
RequiredRemoteMaxHTLCs func(btcutil.Amount) uint16
|
||||||
|
|
||||||
// WatchNewChannel is to be called once a new channel enters the final
|
// WatchNewChannel is to be called once a new channel enters the final
|
||||||
// funding stage: waiting for on-chain confirmation. This method sends
|
// funding stage: waiting for on-chain confirmation. This method sends
|
||||||
// the channel to the ChainArbitrator so it can watch for any on-chain
|
// the channel to the ChainArbitrator so it can watch for any on-chain
|
||||||
@ -868,7 +884,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
// party is attempting to dictate for our commitment transaction.
|
// party is attempting to dictate for our commitment transaction.
|
||||||
err = reservation.CommitConstraints(
|
err = reservation.CommitConstraints(
|
||||||
uint16(msg.CsvDelay), msg.MaxAcceptedHTLCs,
|
uint16(msg.CsvDelay), msg.MaxAcceptedHTLCs,
|
||||||
msg.MaxValueInFlight, msg.ChannelReserve,
|
msg.MaxValueInFlight, msg.HtlcMinimum, msg.ChannelReserve,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.failFundingFlow(
|
f.failFundingFlow(
|
||||||
@ -904,7 +920,9 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
remoteCsvDelay := f.cfg.RequiredRemoteDelay(amt)
|
remoteCsvDelay := f.cfg.RequiredRemoteDelay(amt)
|
||||||
|
|
||||||
// We'll also generate our required constraints for the remote party,
|
// We'll also generate our required constraints for the remote party,
|
||||||
chanReserve, maxValue, maxHtlcs := reservation.RemoteChanConstraints()
|
chanReserve := f.cfg.RequiredRemoteChanReserve(amt)
|
||||||
|
maxValue := f.cfg.RequiredRemoteMaxValue(amt)
|
||||||
|
maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(amt)
|
||||||
|
|
||||||
// With our parameters set, we'll now process their contribution so we
|
// With our parameters set, we'll now process their contribution so we
|
||||||
// can move the funding workflow ahead.
|
// can move the funding workflow ahead.
|
||||||
@ -1004,7 +1022,7 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) {
|
|||||||
resCtx.reservation.SetNumConfsRequired(uint16(msg.MinAcceptDepth))
|
resCtx.reservation.SetNumConfsRequired(uint16(msg.MinAcceptDepth))
|
||||||
err = resCtx.reservation.CommitConstraints(
|
err = resCtx.reservation.CommitConstraints(
|
||||||
uint16(msg.CsvDelay), msg.MaxAcceptedHTLCs,
|
uint16(msg.CsvDelay), msg.MaxAcceptedHTLCs,
|
||||||
msg.MaxValueInFlight, msg.ChannelReserve,
|
msg.MaxValueInFlight, msg.HtlcMinimum, msg.ChannelReserve,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.failFundingFlow(
|
f.failFundingFlow(
|
||||||
@ -1018,7 +1036,9 @@ 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, maxValue, maxHtlcs := resCtx.reservation.RemoteChanConstraints()
|
chanReserve := f.cfg.RequiredRemoteChanReserve(resCtx.chanAmt)
|
||||||
|
maxValue := f.cfg.RequiredRemoteMaxValue(resCtx.chanAmt)
|
||||||
|
maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(resCtx.chanAmt)
|
||||||
|
|
||||||
// The remote node has responded with their portion of the channel
|
// The remote node has responded with their portion of the channel
|
||||||
// contribution. At this point, we can process their contribution which
|
// contribution. At this point, we can process their contribution which
|
||||||
@ -2389,7 +2409,9 @@ 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, maxValue, maxHtlcs := reservation.RemoteChanConstraints()
|
chanReserve := f.cfg.RequiredRemoteChanReserve(capacity)
|
||||||
|
maxValue := f.cfg.RequiredRemoteMaxValue(capacity)
|
||||||
|
maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(capacity)
|
||||||
|
|
||||||
fndgLog.Infof("Starting funding workflow with %v for pendingID(%x)",
|
fndgLog.Infof("Starting funding workflow with %v for pendingID(%x)",
|
||||||
msg.peerAddress.Address, chanID)
|
msg.peerAddress.Address, chanID)
|
||||||
|
@ -278,6 +278,16 @@ 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 {
|
||||||
|
return chanAmt / 100
|
||||||
|
},
|
||||||
|
RequiredRemoteMaxValue: func(chanAmt btcutil.Amount) lnwire.MilliSatoshi {
|
||||||
|
reserve := lnwire.NewMSatFromSatoshis(chanAmt / 100)
|
||||||
|
return lnwire.NewMSatFromSatoshis(chanAmt) - reserve
|
||||||
|
},
|
||||||
|
RequiredRemoteMaxHTLCs: func(chanAmt btcutil.Amount) uint16 {
|
||||||
|
return uint16(lnwallet.MaxHTLCNumber / 2)
|
||||||
|
},
|
||||||
ArbiterChan: arbiterChan,
|
ArbiterChan: arbiterChan,
|
||||||
WatchNewChannel: func(*channeldb.OpenChannel) error {
|
WatchNewChannel: func(*channeldb.OpenChannel) error {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user