htlcswitch: properly update channel bandwidth after payment recv
This commit fixes an omission within the htlcSwitch. With this commit, a channels bandwidth is now properly updated once an incoming HTLC is settled. This also fixes a bug where if a node received a payment, it wouldn’t be able to then utilize the newly available bandwidth to send further payments.
This commit is contained in:
2 files changed
+52
-10
No files matched your search
@@ -240,6 +240,8 @@ out:
|
||||
h.handleRegisterLink(req)
|
||||
case *unregisterLinkMsg:
|
||||
h.handleUnregisterLink(req)
|
||||
case *linkInfoUpdateMsg:
|
||||
h.handleLinkUpdate(req)
|
||||
}
|
||||
case <-h.quit:
|
||||
break out
|
||||
@@ -333,6 +335,16 @@ func (h *htlcSwitch) handleCloseLink(req *closeLinkReq) {
|
||||
targetLink.peer.localCloseChanReqs <- req
|
||||
}
|
||||
|
||||
// handleLinkUpdate processes the link info update message by adjusting the
|
||||
// channels available bandwidth by the delta specified within the message.
|
||||
func (h *htlcSwitch) handleLinkUpdate(req *linkInfoUpdateMsg) {
|
||||
link := h.chanIndex[*req.targetLink]
|
||||
link.availableBandwidth += req.bandwidthDelta
|
||||
|
||||
hswcLog.Tracef("adjusting bandwidth of link %v by %v", req.targetLink,
|
||||
req.bandwidthDelta)
|
||||
}
|
||||
|
||||
// registerLinkMsg is message which requests a new link to be registered.
|
||||
type registerLinkMsg struct {
|
||||
peer *peer
|
||||
@@ -406,3 +418,19 @@ func (h *htlcSwitch) CloseLink(chanPoint *wire.OutPoint) (chan *closeLinkResp, c
|
||||
|
||||
return respChan, errChan
|
||||
}
|
||||
|
||||
// linkInfoUpdateMsg encapsulates a request for the htlc switch to update the
|
||||
// meta-data related to the target link.
|
||||
type linkInfoUpdateMsg struct {
|
||||
targetLink *wire.OutPoint
|
||||
|
||||
bandwidthDelta btcutil.Amount
|
||||
}
|
||||
|
||||
// UpdateLink sends a message to the switch to update the available bandwidth
|
||||
// within the link by the passed satoshi delta. This function may be used when
|
||||
// re-anchoring to boost the capacity of a channel, or once a peer settles an
|
||||
// HTLC invoice.
|
||||
func (h *htlcSwitch) UpdateLink(chanPoint *wire.OutPoint, bandwidthDelta btcutil.Amount) {
|
||||
h.linkControl <- &linkInfoUpdateMsg{chanPoint, bandwidthDelta}
|
||||
}
|
||||
Reference in new issue
Block a user