fundingmanager+server: define subtractFees
Let one initiate a funding request with the remaining funds in the wallet.
This commit is contained in:
parent
87c8165f01
commit
b9816259cb
|
@ -1722,8 +1722,8 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) {
|
||||||
return
|
return
|
||||||
case shortChanID, ok = <-confChan:
|
case shortChanID, ok = <-confChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
fndgLog.Errorf("waiting for funding confirmation" +
|
fndgLog.Errorf("waiting for funding " +
|
||||||
" failed")
|
"confirmation failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1893,8 +1893,9 @@ func makeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) {
|
||||||
// when a channel has become active for lightning transactions.
|
// when a channel has become active for lightning transactions.
|
||||||
// The wait can be canceled by closing the cancelChan. In case of success,
|
// The wait can be canceled by closing the cancelChan. In case of success,
|
||||||
// a *lnwire.ShortChannelID will be passed to confChan.
|
// a *lnwire.ShortChannelID will be passed to confChan.
|
||||||
func (f *fundingManager) waitForFundingConfirmation(completeChan *channeldb.OpenChannel,
|
func (f *fundingManager) waitForFundingConfirmation(
|
||||||
cancelChan <-chan struct{}, confChan chan<- *lnwire.ShortChannelID) {
|
completeChan *channeldb.OpenChannel, cancelChan <-chan struct{},
|
||||||
|
confChan chan<- *lnwire.ShortChannelID) {
|
||||||
|
|
||||||
defer close(confChan)
|
defer close(confChan)
|
||||||
|
|
||||||
|
@ -1904,16 +1905,19 @@ func (f *fundingManager) waitForFundingConfirmation(completeChan *channeldb.Open
|
||||||
fundingScript, err := makeFundingScript(completeChan)
|
fundingScript, err := makeFundingScript(completeChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fndgLog.Errorf("unable to create funding script for "+
|
fndgLog.Errorf("unable to create funding script for "+
|
||||||
"ChannelPoint(%v): %v", completeChan.FundingOutpoint, err)
|
"ChannelPoint(%v): %v", completeChan.FundingOutpoint,
|
||||||
|
err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
numConfs := uint32(completeChan.NumConfsRequired)
|
numConfs := uint32(completeChan.NumConfsRequired)
|
||||||
confNtfn, err := f.cfg.Notifier.RegisterConfirmationsNtfn(
|
confNtfn, err := f.cfg.Notifier.RegisterConfirmationsNtfn(
|
||||||
&txid, fundingScript, numConfs, completeChan.FundingBroadcastHeight,
|
&txid, fundingScript, numConfs,
|
||||||
|
completeChan.FundingBroadcastHeight,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fndgLog.Errorf("Unable to register for confirmation of "+
|
fndgLog.Errorf("Unable to register for confirmation of "+
|
||||||
"ChannelPoint(%v): %v", completeChan.FundingOutpoint, err)
|
"ChannelPoint(%v): %v", completeChan.FundingOutpoint,
|
||||||
|
err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1928,14 +1932,17 @@ func (f *fundingManager) waitForFundingConfirmation(completeChan *channeldb.Open
|
||||||
select {
|
select {
|
||||||
case confDetails, ok = <-confNtfn.Confirmed:
|
case confDetails, ok = <-confNtfn.Confirmed:
|
||||||
// fallthrough
|
// fallthrough
|
||||||
|
|
||||||
case <-cancelChan:
|
case <-cancelChan:
|
||||||
fndgLog.Warnf("canceled waiting for funding confirmation, "+
|
fndgLog.Warnf("canceled waiting for funding confirmation, "+
|
||||||
"stopping funding flow for ChannelPoint(%v)",
|
"stopping funding flow for ChannelPoint(%v)",
|
||||||
completeChan.FundingOutpoint)
|
completeChan.FundingOutpoint)
|
||||||
return
|
return
|
||||||
|
|
||||||
case <-f.quit:
|
case <-f.quit:
|
||||||
fndgLog.Warnf("fundingManager shutting down, stopping funding "+
|
fndgLog.Warnf("fundingManager shutting down, stopping funding "+
|
||||||
"flow for ChannelPoint(%v)", completeChan.FundingOutpoint)
|
"flow for ChannelPoint(%v)",
|
||||||
|
completeChan.FundingOutpoint)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1948,6 +1955,18 @@ func (f *fundingManager) waitForFundingConfirmation(completeChan *channeldb.Open
|
||||||
|
|
||||||
fundingPoint := completeChan.FundingOutpoint
|
fundingPoint := completeChan.FundingOutpoint
|
||||||
chanID := lnwire.NewChanIDFromOutPoint(&fundingPoint)
|
chanID := lnwire.NewChanIDFromOutPoint(&fundingPoint)
|
||||||
|
if int(fundingPoint.Index) >= len(confDetails.Tx.TxOut) {
|
||||||
|
fndgLog.Warnf("Funding point index does not exist for "+
|
||||||
|
"ChannelPoint(%v)", completeChan.FundingOutpoint)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
outputAmt := btcutil.Amount(confDetails.Tx.TxOut[fundingPoint.Index].Value)
|
||||||
|
if outputAmt != completeChan.Capacity {
|
||||||
|
fndgLog.Warnf("Invalid output value for ChannelPoint(%v)",
|
||||||
|
completeChan.FundingOutpoint)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fndgLog.Infof("ChannelPoint(%v) is now active: ChannelID(%x)",
|
fndgLog.Infof("ChannelPoint(%v) is now active: ChannelID(%x)",
|
||||||
fundingPoint, chanID[:])
|
fundingPoint, chanID[:])
|
||||||
|
@ -2742,7 +2761,6 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
||||||
var (
|
var (
|
||||||
peerKey = msg.peer.IdentityKey()
|
peerKey = msg.peer.IdentityKey()
|
||||||
localAmt = msg.localFundingAmt
|
localAmt = msg.localFundingAmt
|
||||||
capacity = localAmt
|
|
||||||
minHtlc = msg.minHtlc
|
minHtlc = msg.minHtlc
|
||||||
remoteCsvDelay = msg.remoteCsvDelay
|
remoteCsvDelay = msg.remoteCsvDelay
|
||||||
)
|
)
|
||||||
|
@ -2756,10 +2774,11 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
||||||
ourDustLimit = defaultLitecoinDustLimit
|
ourDustLimit = defaultLitecoinDustLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
fndgLog.Infof("Initiating fundingRequest(localAmt=%v, remoteAmt=%v, "+
|
fndgLog.Infof("Initiating fundingRequest(local_amt=%v "+
|
||||||
"capacity=%v, chainhash=%v, peer=%x, dustLimit=%v, min_confs=%v)",
|
"(subtract_fees=%v), push_amt=%v, chain_hash=%v, peer=%x, "+
|
||||||
localAmt, msg.pushAmt, capacity, msg.chainHash,
|
"dust_limit=%v, min_confs=%v)", localAmt, msg.subtractFees,
|
||||||
peerKey.SerializeCompressed(), ourDustLimit, msg.minConfs)
|
msg.pushAmt, msg.chainHash, peerKey.SerializeCompressed(),
|
||||||
|
ourDustLimit, msg.minConfs)
|
||||||
|
|
||||||
// First, we'll query the fee estimator for a fee that should get the
|
// First, we'll query the fee estimator for a fee that should get the
|
||||||
// commitment transaction confirmed by the next few blocks (conf target
|
// commitment transaction confirmed by the next few blocks (conf target
|
||||||
|
@ -2786,6 +2805,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
||||||
ChainHash: &msg.chainHash,
|
ChainHash: &msg.chainHash,
|
||||||
NodeID: peerKey,
|
NodeID: peerKey,
|
||||||
NodeAddr: msg.peer.Address(),
|
NodeAddr: msg.peer.Address(),
|
||||||
|
SubtractFees: msg.subtractFees,
|
||||||
LocalFundingAmt: localAmt,
|
LocalFundingAmt: localAmt,
|
||||||
RemoteFundingAmt: 0,
|
RemoteFundingAmt: 0,
|
||||||
CommitFeePerKw: commitFeePerKw,
|
CommitFeePerKw: commitFeePerKw,
|
||||||
|
@ -2801,6 +2821,12 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now that we have successfully reserved funds for this channel in the
|
||||||
|
// wallet, we can fetch the final channel capacity. This is done at
|
||||||
|
// this point since the final capacity might change in case of
|
||||||
|
// SubtractFees=true.
|
||||||
|
capacity := reservation.Capacity()
|
||||||
|
|
||||||
// Obtain a new pending channel ID which is used to track this
|
// Obtain a new pending channel ID which is used to track this
|
||||||
// reservation throughout its lifetime.
|
// reservation throughout its lifetime.
|
||||||
chanID := f.nextPendingChanID()
|
chanID := f.nextPendingChanID()
|
||||||
|
|
|
@ -515,6 +515,13 @@ func (r *ChannelReservation) FundingOutpoint() *wire.OutPoint {
|
||||||
return &r.partialState.FundingOutpoint
|
return &r.partialState.FundingOutpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Capacity returns the channel capacity for this reservation.
|
||||||
|
func (r *ChannelReservation) Capacity() btcutil.Amount {
|
||||||
|
r.RLock()
|
||||||
|
defer r.RUnlock()
|
||||||
|
return r.partialState.Capacity
|
||||||
|
}
|
||||||
|
|
||||||
// Cancel abandons this channel reservation. This method should be called in
|
// Cancel abandons this channel reservation. This method should be called in
|
||||||
// the scenario that communications with the counterparty break down. Upon
|
// the scenario that communications with the counterparty break down. Upon
|
||||||
// cancellation, all resources previously reserved for this pending payment
|
// cancellation, all resources previously reserved for this pending payment
|
||||||
|
|
Loading…
Reference in New Issue
Block a user