Skip to content

Commit 43409c7

Browse files
committed
rpcserver: use HtlcIndex as the unique key
1 parent 70dec8e commit 43409c7

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

rpcserver.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4841,12 +4841,17 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
48414841
)
48424842
}
48434843

4844-
// Create a set of the HTLCs found in the remote commitment, which is
4844+
// Create two sets of the HTLCs found in the remote commitment, which is
48454845
// used to decide whether the HTLCs from the local commitment has been
48464846
// locked in or not.
4847-
remoteHTLCs := fn.NewSet[[32]byte]()
4847+
remoteIncomingHTLCs := fn.NewSet[uint64]()
4848+
remoteOutgoingHTLCs := fn.NewSet[uint64]()
48484849
for _, htlc := range dbChannel.RemoteCommitment.Htlcs {
4849-
remoteHTLCs.Add(htlc.RHash)
4850+
if htlc.Incoming {
4851+
remoteIncomingHTLCs.Add(htlc.HtlcIndex)
4852+
} else {
4853+
remoteOutgoingHTLCs.Add(htlc.HtlcIndex)
4854+
}
48504855
}
48514856

48524857
for i, htlc := range localCommit.Htlcs {
@@ -4855,7 +4860,10 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
48554860

48564861
circuitMap := r.server.htlcSwitch.CircuitLookup()
48574862

4858-
var forwardingChannel, forwardingHtlcIndex uint64
4863+
var (
4864+
forwardingChannel, forwardingHtlcIndex uint64
4865+
lockedIn bool
4866+
)
48594867
switch {
48604868
case htlc.Incoming:
48614869
circuit := circuitMap.LookupCircuit(
@@ -4871,6 +4879,8 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
48714879
forwardingHtlcIndex = circuit.Outgoing.HtlcID
48724880
}
48734881

4882+
lockedIn = remoteIncomingHTLCs.Contains(htlc.HtlcIndex)
4883+
48744884
case !htlc.Incoming:
48754885
circuit := circuitMap.LookupOpenCircuit(
48764886
htlcswitch.CircuitKey{
@@ -4890,6 +4900,8 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
48904900

48914901
forwardingHtlcIndex = circuit.Incoming.HtlcID
48924902
}
4903+
4904+
lockedIn = remoteOutgoingHTLCs.Contains(htlc.HtlcIndex)
48934905
}
48944906

48954907
channel.PendingHtlcs[i] = &lnrpc.HTLC{
@@ -4900,7 +4912,7 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
49004912
HtlcIndex: htlc.HtlcIndex,
49014913
ForwardingChannel: forwardingChannel,
49024914
ForwardingHtlcIndex: forwardingHtlcIndex,
4903-
LockedIn: remoteHTLCs.Contains(rHash),
4915+
LockedIn: lockedIn,
49044916
}
49054917

49064918
// Add the Pending Htlc Amount to UnsettledBalance field.

0 commit comments

Comments
 (0)