diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 9e17a597..8e6ec7f7 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -2344,6 +2344,20 @@ func (lc *LightningChannel) createCommitmentTx(c *commitment, if err := blockchain.CheckTransactionSanity(uTx); err != nil { return err } + + // Finally, we'll assert that were not attempting to draw more out of + // the channel that was originally placed within it. + var totalOut btcutil.Amount + for _, txOut := range commitTx.TxOut { + totalOut += btcutil.Amount(txOut.Value) + } + if totalOut > lc.channelState.Capacity { + return fmt.Errorf("height=%v, for ChannelPoint(%v) attempts "+ + "to consume %v while channel capacity is %v", + c.height, lc.channelState.FundingOutpoint, + totalOut, lc.channelState.Capacity) + } + c.txn = commitTx c.fee = commitFee c.ourBalance = ourBalance diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index f01169c3..1d88e7d1 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -685,7 +685,7 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) { return } - // Grab the mutex on the ChannelReservation to ensure thead-safety + // Grab the mutex on the ChannelReservation to ensure thread-safety pendingReservation.Lock() defer pendingReservation.Unlock()