Skip to content

Commit e693f89

Browse files
committed
lnwallet/channel: locked in settle/fail
1 parent 9f358db commit e693f89

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lnwallet/channel.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4071,6 +4071,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
40714071
remoteChainTail := lc.remoteCommitChain.tail().height + 1
40724072
localChainTail := lc.localCommitChain.tail().height
40734073

4074+
source := lc.ShortChanID()
40744075
chanID := lnwire.NewChanIDFromOutPoint(&lc.channelState.FundingOutpoint)
40754076

40764077
// Determine the set of htlcs that can be forwarded as a result of
@@ -4093,19 +4094,22 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
40934094
continue
40944095
}
40954096

4096-
uncommitted := (pd.addCommitHeightRemote == 0 ||
4097-
pd.addCommitHeightLocal == 0)
4098-
if pd.EntryType == Add && uncommitted {
4099-
continue
4100-
}
4097+
// For each type of HTLC, we will only consider forwarding it if
4098+
// both of the remote and local heights are non-zero. If either
4099+
// of these values is zero, it has yet to be committed in both
4100+
// the local and remote chains.
4101+
committedAdd := pd.addCommitHeightRemote > 0 &&
4102+
pd.addCommitHeightLocal > 0
4103+
committedRmv := pd.removeCommitHeightRemote > 0 &&
4104+
pd.removeCommitHeightLocal > 0
41014105

41024106
// Using the height of the remote and local commitments,
41034107
// preemptively compute whether or not to forward this HTLC for
41044108
// the case in which this in an Add HTLC, or if this is a
41054109
// Settle, Fail, or MalformedFail.
41064110
shouldFwdAdd := remoteChainTail == pd.addCommitHeightRemote &&
41074111
localChainTail >= pd.addCommitHeightLocal
4108-
shouldFwdRmv := remoteChainTail >= pd.removeCommitHeightRemote &&
4112+
shouldFwdRmv := remoteChainTail == pd.removeCommitHeightRemote &&
41094113
localChainTail >= pd.removeCommitHeightLocal
41104114

41114115
// We'll only forward any new HTLC additions iff, it's "freshly
@@ -4114,8 +4118,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
41144118
// don't re-forward any already processed HTLC's after a
41154119
// restart.
41164120
switch {
4117-
case pd.EntryType == Add && shouldFwdAdd:
4118-
4121+
case pd.EntryType == Add && committedAdd && shouldFwdAdd:
41194122
// Construct a reference specifying the location that
41204123
// this forwarded Add will be written in the forwarding
41214124
// package constructed at this remote height.
@@ -4128,13 +4131,12 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
41284131
pd.isForwarded = true
41294132
addsToForward = append(addsToForward, pd)
41304133

4131-
case pd.EntryType != Add && shouldFwdRmv:
4132-
4134+
case pd.EntryType != Add && committedRmv && shouldFwdRmv:
41334135
// Construct a reference specifying the location that
41344136
// this forwarded Settle/Fail will be written in the
41354137
// forwarding package constructed at this remote height.
41364138
pd.DestRef = &channeldb.SettleFailRef{
4137-
Source: lc.ShortChanID(),
4139+
Source: source,
41384140
Height: remoteChainTail,
41394141
Index: settleFailIndex,
41404142
}
@@ -4199,8 +4201,6 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
41994201
}
42004202
}
42014203

4202-
source := lc.ShortChanID()
4203-
42044204
// Now that we have gathered the set of HTLCs to forward, separated by
42054205
// type, construct a forwarding package using the height that the remote
42064206
// commitment chain will be extended after persisting the revocation.

0 commit comments

Comments
 (0)