From cae1d468e7179ddacbf6278a9d2cf6d7e8eb207f Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Mon, 23 Apr 2018 22:08:03 -0700 Subject: [PATCH] lnwallet/channel: expose NextLocalHtlcIndex --- lnwallet/channel.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index d5fd4bb8..34039db0 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -5885,12 +5885,15 @@ func (lc *LightningChannel) LocalChanReserve() btcutil.Amount { return lc.localChanCfg.ChanReserve } -// LocalHtlcIndex returns the next local htlc index to be allocated. -func (lc *LightningChannel) LocalHtlcIndex() uint64 { +// NextLocalHtlcIndex returns the next unallocated local htlc index. To ensure +// this always returns the next index that has been not been allocated, this +// will first try to examine any pending commitments, before falling back to the +// last locked-in local commitment. +func (lc *LightningChannel) NextLocalHtlcIndex() (uint64, error) { lc.RLock() defer lc.RUnlock() - return lc.channelState.LocalCommitment.LocalHtlcIndex + return lc.channelState.NextLocalHtlcIndex() } // RemoteCommitHeight returns the commitment height of the remote chain.