Skip to content

Commit 1881cb8

Browse files
committed
channeldb: add BalanceAboveReserve helper
We add this helper which will be used in a following commit. For the noop htlcs that we are going to add we need to know whether the "potential" receiver's balance is above reserve, so we add this specific helper that helps us safely perform this check. To account for entries that have already been processed, and to avoid bursts of HTLC going way over the reserve, we also accept the delta parameter which keeps track of amounts that will be credited to the receiver.
1 parent 33e6f28 commit 1881cb8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

channeldb/channel.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,28 @@ func (c *OpenChannel) clearChanStatus(status ChannelStatus) error {
21272127
return nil
21282128
}
21292129

2130+
// BalanceAboveReserve checks if the balance for the provided party is above the
2131+
// configured reserve. It also uses the balance delta for the party, to account
2132+
// for entry amounts that have been processed already.
2133+
func (c *OpenChannel) BalanceAboveReserve(party lntypes.ChannelParty,
2134+
delta btcutil.Amount) bool {
2135+
2136+
c.RLock()
2137+
defer c.RUnlock()
2138+
2139+
switch {
2140+
case party.IsLocal():
2141+
return c.LocalCommitment.LocalBalance.ToSatoshis()+delta >
2142+
c.LocalChanCfg.ChanReserve
2143+
2144+
case party.IsRemote():
2145+
return c.RemoteCommitment.RemoteBalance.ToSatoshis()+delta >
2146+
c.RemoteChanCfg.ChanReserve
2147+
}
2148+
2149+
return false
2150+
}
2151+
21302152
// putOpenChannel serializes, and stores the current state of the channel in its
21312153
// entirety.
21322154
func putOpenChannel(chanBucket kvdb.RwBucket, channel *OpenChannel) error {

0 commit comments

Comments
 (0)