htlcswitch: Change circuit map keys to (channel ID, HTLC ID).
This changes the circuit map internals and API to reference circuits by a primary key of (channel ID, HTLC ID) instead of paymnet hash. This is because each circuit has a unique offered HTLC, but there may be multiple circuits for a payment hash with different source or destination channels.
This commit is contained in:
1 parent
bc8d674958
commit
1328e61c00
6 files changed
+274
-151
No files matched your search
@@ -700,6 +700,8 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
|
||||
|
||||
failPkt := &htlcPacket{
|
||||
src: l.ShortChanID(),
|
||||
dest: pkt.src,
|
||||
destID: pkt.srcID,
|
||||
payHash: htlc.PaymentHash,
|
||||
amount: htlc.Amount,
|
||||
isObfuscated: isObfuscated,
|
||||
@@ -720,6 +722,20 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
|
||||
"local_log_index=%v, batch_size=%v",
|
||||
htlc.PaymentHash[:], index, l.batchCounter+1)
|
||||
|
||||
// If packet was forwarded from another channel link then we should
|
||||
// create circuit (remember the path) in order to forward settle/fail
|
||||
// packet back.
|
||||
if pkt.src != (lnwire.ShortChannelID{}) {
|
||||
l.cfg.Switch.addCircuit(&PaymentCircuit{
|
||||
PaymentHash: htlc.PaymentHash,
|
||||
IncomingChanID: pkt.src,
|
||||
IncomingHTLCID: pkt.srcID,
|
||||
OutgoingChanID: pkt.dest,
|
||||
OutgoingHTLCID: index,
|
||||
ErrorEncrypter: pkt.obfuscator,
|
||||
})
|
||||
}
|
||||
|
||||
htlc.ID = index
|
||||
l.cfg.Peer.SendMessage(htlc)
|
||||
|
||||
@@ -1180,6 +1196,7 @@ func (l *channelLink) processLockedInHtlcs(
|
||||
case lnwallet.Settle:
|
||||
settlePacket := &htlcPacket{
|
||||
src: l.ShortChanID(),
|
||||
srcID: pd.ParentIndex,
|
||||
payHash: pd.RHash,
|
||||
amount: pd.Amount,
|
||||
htlc: &lnwire.UpdateFufillHTLC{
|
||||
@@ -1202,6 +1219,7 @@ func (l *channelLink) processLockedInHtlcs(
|
||||
// continue to propagate it.
|
||||
failPacket := &htlcPacket{
|
||||
src: l.ShortChanID(),
|
||||
srcID: pd.HtlcIndex,
|
||||
payHash: pd.RHash,
|
||||
amount: pd.Amount,
|
||||
isObfuscated: false,
|
||||
@@ -1573,6 +1591,7 @@ func (l *channelLink) processLockedInHtlcs(
|
||||
|
||||
updatePacket := &htlcPacket{
|
||||
src: l.ShortChanID(),
|
||||
srcID: pd.HtlcIndex,
|
||||
dest: fwdInfo.NextHop,
|
||||
htlc: addMsg,
|
||||
obfuscator: obfuscator,
|
||||
|
||||
Reference in new issue
Block a user