lnwallet: add assertion in createCommitmentTx to detect overdraw attempts
In this commit, we add a precautionary assertion at the end of createCommitmentTx. This assertion is meant to ensure that we don't accept or propose a commitment transaction that attempts to send out more than it was funded with.
This commit is contained in:
parent
c7afb867bc
commit
95293f5102
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user