Skip to content

Commit d7f6f35

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.
1 parent 93a6ab8 commit d7f6f35

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.
2132+
func (c *OpenChannel) BalanceAboveReserve(
2133+
party lntypes.ChannelParty) bool {
2134+
2135+
c.Lock()
2136+
defer c.Unlock()
2137+
2138+
switch {
2139+
case party.IsLocal():
2140+
return c.LocalCommitment.LocalBalance.ToSatoshis() >
2141+
c.LocalChanCfg.ChanReserve
2142+
2143+
case party.IsRemote():
2144+
return c.RemoteCommitment.RemoteBalance.ToSatoshis() >
2145+
c.RemoteChanCfg.ChanReserve
2146+
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)