htlcswitch: modify Bandwidth() method on links to use more accurate accoutning

In this commit, we modify the existing implementation of the
Bandwidth() method on the default ChannelLink implementation to use
much tighter accounting. Before this commit, there was a bug wherein if
the link restarted with pending un-settled HTLC’s, and one of them was
settled, then the bandwidth wouldn’t properly be updated to reflect
this fact.

To fix this, we’ve done away with the manual accounting and instead
grab the current balances from two sources: the set of active HTLC’s
within the overflow queue, and the report from the link itself which
includes the pending HTLC’s and factors in the amount we’d need to (or
not need to) pay in fees for each HTLC.
This commit is contained in:
Olaoluwa Osuntokun
2017-11-10 14:52:27 -08:00
parent 70ed50738a
commit de3af9b0c0
3 changed files with 29 additions and 48 deletions

View File

@@ -51,6 +51,7 @@ type htlcPacket struct {
func newInitPacket(destNode [33]byte, htlc *lnwire.UpdateAddHTLC) *htlcPacket {
return &htlcPacket{
destNode: destNode,
amount: htlc.Amount,
htlc: htlc,
}
}
@@ -61,6 +62,7 @@ func newAddPacket(src, dest lnwire.ShortChannelID,
htlc *lnwire.UpdateAddHTLC, e ErrorEncrypter) *htlcPacket {
return &htlcPacket{
amount: htlc.Amount,
dest: dest,
src: src,
htlc: htlc,