lnwallet: call valdiateCommitmentSanity in ReceiveHTLC
This commit checks the commitment sanity when receiving an HTLC so that if a commitment transaction will overflow from an ADD, it is caught earlier rather than in ReceiveNewCommitment.
This commit is contained in:
parent
b75259a3e2
commit
56c07a52d8
@ -3084,12 +3084,16 @@ func (lc *LightningChannel) validateCommitmentSanity(theirLogCounter,
|
|||||||
view := lc.fetchHTLCView(theirLogCounter, ourLogCounter)
|
view := lc.fetchHTLCView(theirLogCounter, ourLogCounter)
|
||||||
|
|
||||||
// If we are checking if we can add a new HTLC, we add this to the
|
// If we are checking if we can add a new HTLC, we add this to the
|
||||||
// update log, in order to validate the sanity of the commitment
|
// appropriate update log, in order to validate the sanity of the
|
||||||
// resulting from _actually adding_ this HTLC to the state.
|
// commitment resulting from _actually adding_ this HTLC to the state.
|
||||||
if predictAdded != nil {
|
if predictAdded != nil {
|
||||||
// If we are adding an HTLC, this will be an Add to the local
|
// If the remoteChain bool is true, add to ourUpdates.
|
||||||
// update log.
|
if remoteChain {
|
||||||
view.ourUpdates = append(view.ourUpdates, predictAdded)
|
view.ourUpdates = append(view.ourUpdates, predictAdded)
|
||||||
|
} else {
|
||||||
|
// Else add to theirUpdates.
|
||||||
|
view.theirUpdates = append(view.theirUpdates, predictAdded)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commitChain := lc.localCommitChain
|
commitChain := lc.localCommitChain
|
||||||
@ -4640,6 +4644,17 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, err
|
|||||||
OnionBlob: htlc.OnionBlob[:],
|
OnionBlob: htlc.OnionBlob[:],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localACKedIndex := lc.remoteCommitChain.tail().ourMessageIndex
|
||||||
|
|
||||||
|
// Clamp down on the number of HTLC's we can receive by checking the
|
||||||
|
// commitment sanity.
|
||||||
|
err := lc.validateCommitmentSanity(
|
||||||
|
lc.remoteUpdateLog.logIndex, localACKedIndex, false, pd,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
lc.remoteUpdateLog.appendHtlc(pd)
|
lc.remoteUpdateLog.appendHtlc(pd)
|
||||||
|
|
||||||
return pd.HtlcIndex, nil
|
return pd.HtlcIndex, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user