lnwallet: ensure that total satoshi sent/received aren't counted twice

This commit fixes a bug in the LightingChannel commitment state machine
which could occasionally result in the total number of satoshis sent or
received being counted twice if a redundant state transition were
initiated.

To fix this bug, we now only increment the number of satoshi
sent/recv’d iff it’s the first time the HTLC has been processed.
This commit is contained in:
Olaoluwa Osuntokun committed 2017-02-21 01:43:07 -08:00
1 parent fb9bf054cc
commit a9416300e5
1 file changed
+13 -2
+13 -2
View File
@@ -1037,7 +1037,12 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
if entry.EntryType == Add {
continue
}
if entry.EntryType == Settle && !remoteChain {
// If we're settling in inbound HTLC, and it hasn't been
// processed, yet, the increment our state tracking the total
// number of satoshis we've received within the channel.
if entry.EntryType == Settle && !remoteChain &&
entry.removeCommitHeightLocal == 0 {
lc.channelState.TotalSatoshisReceived += uint64(entry.Amount)
}
@@ -1051,7 +1056,13 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
if entry.EntryType == Add {
continue
}
if entry.EntryType == Settle && !remoteChain {
// If the remote party is settling one of our outbound HTLC's,
// and it hasn't been processed, yet, the increment our state
// tracking the total number of satoshis we've sent within the
// channel.
if entry.EntryType == Settle && !remoteChain &&
entry.removeCommitHeightLocal == 0 {
lc.channelState.TotalSatoshisSent += uint64(entry.Amount)
}