Merge pull request #100 from TheBlueMatt/2018-07-htlc-balance-calc
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Tue, 31 Jul 2018 04:59:31 +0000 (00:59 -0400)
committerGitHub <noreply@github.com>
Tue, 31 Jul 2018 04:59:31 +0000 (00:59 -0400)
Fix non-HTLC-inclusion balance calculation (mark II)

src/ln/channel.rs

index acee06409c3f8479137b1561ac1b2d636cf6c9e2..188af477dded2049771aa6d800ffe3cc3421407e 100644 (file)
@@ -136,7 +136,7 @@ enum HTLCState {
        /// anyway).
        LocalRemoved,
        /// Removed by us, sent a new commitment_signed and got a revoke_and_ack. Just waiting on an
-       /// updated local commitment transaction.
+       /// updated local commitment transaction. Implies local_removed_fulfilled.
        LocalRemovedAwaitingCommitment,
 }
 
@@ -663,7 +663,7 @@ impl Channel {
                        } else {
                                match htlc.state {
                                        HTLCState::AwaitingRemoteRevokeToRemove|HTLCState::AwaitingRemovedRemoteRevoke => {
-                                               if generated_by_local && htlc.fail_reason.is_none() {
+                                               if htlc.fail_reason.is_none() {
                                                        value_to_self_msat_offset -= htlc.amount_msat as i64;
                                                }
                                        },
@@ -678,6 +678,7 @@ impl Channel {
                                                }
                                        },
                                        HTLCState::LocalRemovedAwaitingCommitment => {
+                                               assert!(htlc.local_removed_fulfilled);
                                                value_to_self_msat_offset += htlc.amount_msat as i64;
                                        },
                                        _ => {},