htlcswitch: Rename htlcPacket fields for clarity.

The src/dest terminology for routing packets is kind of confusing
because the source HTLC may not be the source of the packet for
settles/fails traversing the circuit in the opposite direction. This
changes the nomenclature to incoming/outgoing and always references
the HTLCs themselves.
This commit is contained in:
Jim Posen 2017-10-30 11:56:51 -07:00 committed by Olaoluwa Osuntokun
parent 66e654bb42
commit 4a29fbdab2
6 changed files with 149 additions and 145 deletions

@ -31,36 +31,36 @@ func TestCircuitMap(t *testing.T) {
// Add multiple circuits with same destination channel but different HTLC // Add multiple circuits with same destination channel but different HTLC
// IDs and payment hashes. // IDs and payment hashes.
circuitMap.Add(&htlcswitch.PaymentCircuit{ circuitMap.Add(&htlcswitch.PaymentCircuit{
PaymentHash: hash1, PaymentHash: hash1,
SrcChanID: chan2, IncomingChanID: chan2,
SrcHTLCID: 1, IncomingHTLCID: 1,
DestChanID: chan1, OutgoingChanID: chan1,
DestHTLCID: 0, OutgoingHTLCID: 0,
}) })
circuitMap.Add(&htlcswitch.PaymentCircuit{ circuitMap.Add(&htlcswitch.PaymentCircuit{
PaymentHash: hash2, PaymentHash: hash2,
SrcChanID: chan2, IncomingChanID: chan2,
SrcHTLCID: 2, IncomingHTLCID: 2,
DestChanID: chan1, OutgoingChanID: chan1,
DestHTLCID: 1, OutgoingHTLCID: 1,
}) })
// Add another circuit with an already-used HTLC ID but different // Add another circuit with an already-used HTLC ID but different
// destination channel. // destination channel.
circuitMap.Add(&htlcswitch.PaymentCircuit{ circuitMap.Add(&htlcswitch.PaymentCircuit{
PaymentHash: hash3, PaymentHash: hash3,
SrcChanID: chan1, IncomingChanID: chan1,
SrcHTLCID: 2, IncomingHTLCID: 2,
DestChanID: chan2, OutgoingChanID: chan2,
DestHTLCID: 0, OutgoingHTLCID: 0,
}) })
circuit = circuitMap.LookupByHTLC(chan1, 0) circuit = circuitMap.LookupByHTLC(chan1, 0)
if circuit == nil { if circuit == nil {
t.Fatal("LookupByHTLC failed to find circuit") t.Fatal("LookupByHTLC failed to find circuit")
} }
if circuit.PaymentHash != hash1 || circuit.SrcHTLCID != 1 { if circuit.PaymentHash != hash1 || circuit.IncomingHTLCID != 1 {
t.Fatalf("LookupByHTLC found unexpected circuit: %v", circuit) t.Fatalf("LookupByHTLC found unexpected circuit: %v", circuit)
} }
@ -68,7 +68,7 @@ func TestCircuitMap(t *testing.T) {
if circuit == nil { if circuit == nil {
t.Fatal("LookupByHTLC failed to find circuit") t.Fatal("LookupByHTLC failed to find circuit")
} }
if circuit.PaymentHash != hash2 || circuit.SrcHTLCID != 2 { if circuit.PaymentHash != hash2 || circuit.IncomingHTLCID != 2 {
t.Fatalf("LookupByHTLC found unexpected circuit: %v", circuit) t.Fatalf("LookupByHTLC found unexpected circuit: %v", circuit)
} }
@ -76,7 +76,7 @@ func TestCircuitMap(t *testing.T) {
if circuit == nil { if circuit == nil {
t.Fatal("LookupByHTLC failed to find circuit") t.Fatal("LookupByHTLC failed to find circuit")
} }
if circuit.PaymentHash != hash3 || circuit.SrcHTLCID != 2 { if circuit.PaymentHash != hash3 || circuit.IncomingHTLCID != 2 {
t.Fatalf("LookupByHTLC found unexpected circuit: %v", circuit) t.Fatalf("LookupByHTLC found unexpected circuit: %v", circuit)
} }
@ -91,18 +91,18 @@ func TestCircuitMap(t *testing.T) {
// Add a circuit with a destination channel and payment hash that are // Add a circuit with a destination channel and payment hash that are
// already added but a different HTLC ID. // already added but a different HTLC ID.
circuitMap.Add(&htlcswitch.PaymentCircuit{ circuitMap.Add(&htlcswitch.PaymentCircuit{
PaymentHash: hash1, PaymentHash: hash1,
SrcChanID: chan2, IncomingChanID: chan2,
SrcHTLCID: 3, IncomingHTLCID: 3,
DestChanID: chan1, OutgoingChanID: chan1,
DestHTLCID: 3, OutgoingHTLCID: 3,
}) })
circuit = circuitMap.LookupByHTLC(chan1, 3) circuit = circuitMap.LookupByHTLC(chan1, 3)
if circuit == nil { if circuit == nil {
t.Fatal("LookupByHTLC failed to find circuit") t.Fatal("LookupByHTLC failed to find circuit")
} }
if circuit.PaymentHash != hash1 || circuit.SrcHTLCID != 3 { if circuit.PaymentHash != hash1 || circuit.IncomingHTLCID != 3 {
t.Fatalf("LookupByHTLC found unexpected circuit: %v", circuit) t.Fatalf("LookupByHTLC found unexpected circuit: %v", circuit)
} }
@ -130,7 +130,7 @@ func TestCircuitMap(t *testing.T) {
t.Fatalf("LookupByPaymentHash returned wrong number of circuits for "+ t.Fatalf("LookupByPaymentHash returned wrong number of circuits for "+
"hash1: expecected %d, got %d", 1, len(circuits)) "hash1: expecected %d, got %d", 1, len(circuits))
} }
if circuits[0].DestHTLCID != 3 { if circuits[0].OutgoingHTLCID != 3 {
t.Fatalf("LookupByPaymentHash returned wrong circuit for hash1: %v", t.Fatalf("LookupByPaymentHash returned wrong circuit for hash1: %v",
circuits[0]) circuits[0])
} }

@ -699,12 +699,11 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
} }
failPkt := &htlcPacket{ failPkt := &htlcPacket{
src: l.ShortChanID(), incomingChanID: pkt.incomingChanID,
dest: pkt.src, incomingHTLCID: pkt.incomingHTLCID,
destID: pkt.srcID, payHash: htlc.PaymentHash,
payHash: htlc.PaymentHash, amount: htlc.Amount,
amount: htlc.Amount, isObfuscated: isObfuscated,
isObfuscated: isObfuscated,
htlc: &lnwire.UpdateFailHTLC{ htlc: &lnwire.UpdateFailHTLC{
Reason: reason, Reason: reason,
}, },
@ -725,12 +724,12 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
// If packet was forwarded from another channel link then we should // If packet was forwarded from another channel link then we should
// create circuit (remember the path) in order to forward settle/fail // create circuit (remember the path) in order to forward settle/fail
// packet back. // packet back.
if pkt.src != (lnwire.ShortChannelID{}) { if pkt.incomingChanID != (lnwire.ShortChannelID{}) {
l.cfg.Switch.addCircuit(&PaymentCircuit{ l.cfg.Switch.addCircuit(&PaymentCircuit{
PaymentHash: htlc.PaymentHash, PaymentHash: htlc.PaymentHash,
IncomingChanID: pkt.src, IncomingChanID: pkt.incomingChanID,
IncomingHTLCID: pkt.srcID, IncomingHTLCID: pkt.incomingHTLCID,
OutgoingChanID: pkt.dest, OutgoingChanID: l.ShortChanID(),
OutgoingHTLCID: index, OutgoingHTLCID: index,
ErrorEncrypter: pkt.obfuscator, ErrorEncrypter: pkt.obfuscator,
}) })
@ -743,7 +742,7 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
// An HTLC we forward to the switch has just settled somewhere // An HTLC we forward to the switch has just settled somewhere
// upstream. Therefore we settle the HTLC within the our local // upstream. Therefore we settle the HTLC within the our local
// state machine. // state machine.
err := l.channel.SettleHTLC(htlc.PaymentPreimage, pkt.destID) err := l.channel.SettleHTLC(htlc.PaymentPreimage, pkt.incomingHTLCID)
if err != nil { if err != nil {
// TODO(roasbeef): broadcast on-chain // TODO(roasbeef): broadcast on-chain
l.fail("unable to settle incoming HTLC: %v", err) l.fail("unable to settle incoming HTLC: %v", err)
@ -754,7 +753,7 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
// message to target the specific channel and HTLC to be // message to target the specific channel and HTLC to be
// cancelled. // cancelled.
htlc.ChanID = l.ChanID() htlc.ChanID = l.ChanID()
htlc.ID = pkt.destID htlc.ID = pkt.incomingHTLCID
// Then we send the HTLC settle message to the connected peer // Then we send the HTLC settle message to the connected peer
// so we can continue the propagation of the settle message. // so we can continue the propagation of the settle message.
@ -764,7 +763,7 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
case *lnwire.UpdateFailHTLC: case *lnwire.UpdateFailHTLC:
// An HTLC cancellation has been triggered somewhere upstream, // An HTLC cancellation has been triggered somewhere upstream,
// we'll remove then HTLC from our local state machine. // we'll remove then HTLC from our local state machine.
err := l.channel.FailHTLC(pkt.destID, htlc.Reason) err := l.channel.FailHTLC(pkt.incomingHTLCID, htlc.Reason)
if err != nil { if err != nil {
log.Errorf("unable to cancel HTLC: %v", err) log.Errorf("unable to cancel HTLC: %v", err)
return return
@ -775,7 +774,7 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
// cancelled. The "Reason" field will have already been set // cancelled. The "Reason" field will have already been set
// within the switch. // within the switch.
htlc.ChanID = l.ChanID() htlc.ChanID = l.ChanID()
htlc.ID = pkt.destID htlc.ID = pkt.incomingHTLCID
// Finally, we send the HTLC message to the peer which // Finally, we send the HTLC message to the peer which
// initially created the HTLC. // initially created the HTLC.
@ -1194,10 +1193,10 @@ func (l *channelLink) processLockedInHtlcs(
// will handle propagating the settle to the prior hop. // will handle propagating the settle to the prior hop.
case lnwallet.Settle: case lnwallet.Settle:
settlePacket := &htlcPacket{ settlePacket := &htlcPacket{
src: l.ShortChanID(), outgoingChanID: l.ShortChanID(),
srcID: pd.ParentIndex, outgoingHTLCID: pd.ParentIndex,
payHash: pd.RHash, payHash: pd.RHash,
amount: pd.Amount, amount: pd.Amount,
htlc: &lnwire.UpdateFufillHTLC{ htlc: &lnwire.UpdateFufillHTLC{
PaymentPreimage: pd.RPreimage, PaymentPreimage: pd.RPreimage,
}, },
@ -1217,11 +1216,11 @@ func (l *channelLink) processLockedInHtlcs(
// Fetch the reason the HTLC was cancelled so we can // Fetch the reason the HTLC was cancelled so we can
// continue to propagate it. // continue to propagate it.
failPacket := &htlcPacket{ failPacket := &htlcPacket{
src: l.ShortChanID(), outgoingChanID: l.ShortChanID(),
srcID: pd.ParentIndex, outgoingHTLCID: pd.ParentIndex,
payHash: pd.RHash, payHash: pd.RHash,
amount: pd.Amount, amount: pd.Amount,
isObfuscated: false, isObfuscated: false,
htlc: &lnwire.UpdateFailHTLC{ htlc: &lnwire.UpdateFailHTLC{
Reason: lnwire.OpaqueReason(pd.FailReason), Reason: lnwire.OpaqueReason(pd.FailReason),
}, },
@ -1589,11 +1588,11 @@ func (l *channelLink) processLockedInHtlcs(
} }
updatePacket := &htlcPacket{ updatePacket := &htlcPacket{
src: l.ShortChanID(), incomingChanID: l.ShortChanID(),
srcID: pd.HtlcIndex, incomingHTLCID: pd.HtlcIndex,
dest: fwdInfo.NextHop, outgoingChanID: fwdInfo.NextHop,
htlc: addMsg, htlc: addMsg,
obfuscator: obfuscator, obfuscator: obfuscator,
} }
packetsToForward = append(packetsToForward, updatePacket) packetsToForward = append(packetsToForward, updatePacket)
} }

@ -30,10 +30,10 @@ func TestMailBoxCouriers(t *testing.T) {
sentPackets := make([]*htlcPacket, numPackets) sentPackets := make([]*htlcPacket, numPackets)
for i := 0; i < numPackets; i++ { for i := 0; i < numPackets; i++ {
pkt := &htlcPacket{ pkt := &htlcPacket{
dest: lnwire.NewShortChanIDFromInt(uint64(prand.Int63())), outgoingChanID: lnwire.NewShortChanIDFromInt(uint64(prand.Int63())),
src: lnwire.NewShortChanIDFromInt(uint64(prand.Int63())), incomingChanID: lnwire.NewShortChanIDFromInt(uint64(prand.Int63())),
amount: lnwire.MilliSatoshi(prand.Int63()), amount: lnwire.MilliSatoshi(prand.Int63()),
isObfuscated: i%2 == 0, isObfuscated: i%2 == 0,
} }
sentPackets[i] = pkt sentPackets[i] = pkt

@ -19,21 +19,21 @@ type htlcPacket struct {
// NOTE: This fields is initialized only in settle and fail packets. // NOTE: This fields is initialized only in settle and fail packets.
payHash [sha256.Size]byte payHash [sha256.Size]byte
// dest is the destination of this packet identified by the short // incomingChanID is the ID of the channel that we have received an incoming
// channel ID of the target link. // HTLC on.
dest lnwire.ShortChannelID incomingChanID lnwire.ShortChannelID
// src is the source of this packet identified by the short channel ID // outgoingChanID is the ID of the channel that we have offered or will
// of the target link. // offer an outgoing HTLC on.
src lnwire.ShortChannelID outgoingChanID lnwire.ShortChannelID
// destID is the ID of the HTLC in the destination channel. This will be set // incomingHTLCID is the ID of the HTLC that we have received from the peer
// when forwarding a settle or fail update back to the original source. // on the incoming channel.
destID uint64 incomingHTLCID uint64
// srcID is the ID of the HTLC in the source channel. This will be set when // outgoingHTLCID is the ID of the HTLC that we offered to the peer on the
// forwarding any HTLC update message. // outgoing channel.
srcID uint64 outgoingHTLCID uint64
// amount is the value of the HTLC that is being created or modified. // amount is the value of the HTLC that is being created or modified.
amount lnwire.MilliSatoshi amount lnwire.MilliSatoshi

@ -458,15 +458,15 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
// payment circuit within our internal state so we can properly forward // payment circuit within our internal state so we can properly forward
// the ultimate settle message back latter. // the ultimate settle message back latter.
case *lnwire.UpdateAddHTLC: case *lnwire.UpdateAddHTLC:
source, err := s.getLinkByShortID(packet.src) source, err := s.getLinkByShortID(packet.incomingChanID)
if err != nil { if err != nil {
err := errors.Errorf("unable to find channel link "+ err := errors.Errorf("unable to find channel link "+
"by channel point (%v): %v", packet.src, err) "by channel point (%v): %v", packet.incomingChanID, err)
log.Error(err) log.Error(err)
return err return err
} }
targetLink, err := s.getLinkByShortID(packet.dest) targetLink, err := s.getLinkByShortID(packet.outgoingChanID)
if err != nil { if err != nil {
// If packet was forwarded from another channel link // If packet was forwarded from another channel link
// than we should notify this link that some error // than we should notify this link that some error
@ -481,16 +481,16 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
} }
source.HandleSwitchPacket(&htlcPacket{ source.HandleSwitchPacket(&htlcPacket{
dest: packet.src, incomingChanID: packet.incomingChanID,
destID: packet.srcID, incomingHTLCID: packet.incomingHTLCID,
payHash: htlc.PaymentHash, payHash: htlc.PaymentHash,
isObfuscated: true, isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{ htlc: &lnwire.UpdateFailHTLC{
Reason: reason, Reason: reason,
}, },
}) })
err = errors.Errorf("unable to find link with "+ err = errors.Errorf("unable to find link with "+
"destination %v", packet.dest) "destination %v", packet.outgoingChanID)
log.Error(err) log.Error(err)
return err return err
} }
@ -530,10 +530,10 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
} }
source.HandleSwitchPacket(&htlcPacket{ source.HandleSwitchPacket(&htlcPacket{
dest: packet.src, incomingChanID: packet.incomingChanID,
destID: packet.srcID, incomingHTLCID: packet.incomingHTLCID,
payHash: htlc.PaymentHash, payHash: htlc.PaymentHash,
isObfuscated: true, isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{ htlc: &lnwire.UpdateFailHTLC{
Reason: reason, Reason: reason,
}, },
@ -555,20 +555,22 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
// payment circuit by forwarding the settle msg to the channel from // payment circuit by forwarding the settle msg to the channel from
// which htlc add packet was initially received. // which htlc add packet was initially received.
case *lnwire.UpdateFufillHTLC, *lnwire.UpdateFailHTLC: case *lnwire.UpdateFufillHTLC, *lnwire.UpdateFailHTLC:
if packet.dest == (lnwire.ShortChannelID{}) { if packet.incomingChanID == (lnwire.ShortChannelID{}) {
// Use circuit map to find the link to forward settle/fail to. // Use circuit map to find the link to forward settle/fail to.
circuit := s.circuits.LookupByHTLC(packet.src, packet.srcID) circuit := s.circuits.LookupByHTLC(packet.outgoingChanID,
packet.outgoingHTLCID)
if circuit == nil { if circuit == nil {
err := errors.Errorf("Unable to find source channel for HTLC "+ err := errors.Errorf("Unable to find target channel for HTLC "+
"settle/fail: channel ID = %s, HTLC ID = %d, "+ "settle/fail: channel ID = %s, HTLC ID = %d, "+
"payment hash = %x", packet.src, packet.srcID, "payment hash = %x", packet.outgoingChanID,
packet.payHash[:]) packet.outgoingHTLCID, packet.payHash[:])
log.Error(err) log.Error(err)
return err return err
} }
// Remove circuit since we are about to complete the HTLC. // Remove circuit since we are about to complete the HTLC.
err := s.circuits.Remove(packet.src, packet.srcID) err := s.circuits.Remove(packet.outgoingChanID,
packet.outgoingHTLCID)
if err != nil { if err != nil {
log.Warnf("Failed to close completed onion circuit for %x: "+ log.Warnf("Failed to close completed onion circuit for %x: "+
"%s<->%s", packet.payHash[:], circuit.IncomingChanID, "%s<->%s", packet.payHash[:], circuit.IncomingChanID,
@ -586,11 +588,11 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
htlc.Reason) htlc.Reason)
} }
packet.dest = circuit.IncomingChanID packet.incomingChanID = circuit.IncomingChanID
packet.destID = circuit.IncomingHTLCID packet.incomingHTLCID = circuit.IncomingHTLCID
} }
source, err := s.getLinkByShortID(packet.dest) source, err := s.getLinkByShortID(packet.incomingChanID)
if err != nil { if err != nil {
err := errors.Errorf("Unable to get source channel link to "+ err := errors.Errorf("Unable to get source channel link to "+
"forward HTLC settle/fail: %v", err) "forward HTLC settle/fail: %v", err)

@ -56,10 +56,10 @@ func TestSwitchForward(t *testing.T) {
preimage := [sha256.Size]byte{1} preimage := [sha256.Size]byte{1}
rhash := fastsha256.Sum256(preimage[:]) rhash := fastsha256.Sum256(preimage[:])
packet := &htlcPacket{ packet := &htlcPacket{
src: aliceChannelLink.ShortChanID(), incomingChanID: aliceChannelLink.ShortChanID(),
srcID: 0, incomingHTLCID: 0,
dest: bobChannelLink.ShortChanID(), outgoingChanID: bobChannelLink.ShortChanID(),
obfuscator: newMockObfuscator(), obfuscator: newMockObfuscator(),
htlc: &lnwire.UpdateAddHTLC{ htlc: &lnwire.UpdateAddHTLC{
PaymentHash: rhash, PaymentHash: rhash,
Amount: 1, Amount: 1,
@ -73,9 +73,9 @@ func TestSwitchForward(t *testing.T) {
s.addCircuit(&PaymentCircuit{ s.addCircuit(&PaymentCircuit{
PaymentHash: packet.payHash, PaymentHash: packet.payHash,
IncomingChanID: packet.src, IncomingChanID: packet.incomingChanID,
IncomingHTLCID: 0, IncomingHTLCID: packet.incomingHTLCID,
OutgoingChanID: packet.dest, OutgoingChanID: packet.outgoingChanID,
OutgoingHTLCID: 0, OutgoingHTLCID: 0,
ErrorEncrypter: packet.obfuscator, ErrorEncrypter: packet.obfuscator,
}) })
@ -95,9 +95,10 @@ func TestSwitchForward(t *testing.T) {
// request and sent the htlc settle request back. This request should // request and sent the htlc settle request back. This request should
// be forwarder back to Alice link. // be forwarder back to Alice link.
packet = &htlcPacket{ packet = &htlcPacket{
src: bobChannelLink.ShortChanID(), outgoingChanID: bobChannelLink.ShortChanID(),
payHash: rhash, outgoingHTLCID: 0,
amount: 1, payHash: rhash,
amount: 1,
htlc: &lnwire.UpdateFufillHTLC{ htlc: &lnwire.UpdateFufillHTLC{
PaymentPreimage: preimage, PaymentPreimage: preimage,
}, },
@ -155,9 +156,9 @@ func TestSkipIneligibleLinksMultiHopForward(t *testing.T) {
preimage := [sha256.Size]byte{1} preimage := [sha256.Size]byte{1}
rhash := fastsha256.Sum256(preimage[:]) rhash := fastsha256.Sum256(preimage[:])
packet = &htlcPacket{ packet = &htlcPacket{
src: aliceChannelLink.ShortChanID(), incomingChanID: aliceChannelLink.ShortChanID(),
srcID: 0, incomingHTLCID: 0,
dest: bobChannelLink.ShortChanID(), outgoingChanID: bobChannelLink.ShortChanID(),
htlc: &lnwire.UpdateAddHTLC{ htlc: &lnwire.UpdateAddHTLC{
PaymentHash: rhash, PaymentHash: rhash,
Amount: 1, Amount: 1,
@ -244,10 +245,10 @@ func TestSwitchCancel(t *testing.T) {
preimage := [sha256.Size]byte{1} preimage := [sha256.Size]byte{1}
rhash := fastsha256.Sum256(preimage[:]) rhash := fastsha256.Sum256(preimage[:])
request := &htlcPacket{ request := &htlcPacket{
src: aliceChannelLink.ShortChanID(), incomingChanID: aliceChannelLink.ShortChanID(),
srcID: 0, incomingHTLCID: 0,
dest: bobChannelLink.ShortChanID(), outgoingChanID: bobChannelLink.ShortChanID(),
obfuscator: newMockObfuscator(), obfuscator: newMockObfuscator(),
htlc: &lnwire.UpdateAddHTLC{ htlc: &lnwire.UpdateAddHTLC{
PaymentHash: rhash, PaymentHash: rhash,
Amount: 1, Amount: 1,
@ -261,9 +262,9 @@ func TestSwitchCancel(t *testing.T) {
s.addCircuit(&PaymentCircuit{ s.addCircuit(&PaymentCircuit{
PaymentHash: request.payHash, PaymentHash: request.payHash,
IncomingChanID: request.src, IncomingChanID: request.incomingChanID,
IncomingHTLCID: 0, IncomingHTLCID: request.incomingHTLCID,
OutgoingChanID: request.dest, OutgoingChanID: request.outgoingChanID,
OutgoingHTLCID: 0, OutgoingHTLCID: 0,
ErrorEncrypter: request.obfuscator, ErrorEncrypter: request.obfuscator,
}) })
@ -283,12 +284,12 @@ func TestSwitchCancel(t *testing.T) {
// the add htlc request and sent the htlc settle request back. This // the add htlc request and sent the htlc settle request back. This
// request should be forwarder back to alice channel link. // request should be forwarder back to alice channel link.
request = &htlcPacket{ request = &htlcPacket{
src: bobChannelLink.ShortChanID(), outgoingChanID: bobChannelLink.ShortChanID(),
srcID: 0, outgoingHTLCID: 0,
payHash: rhash, payHash: rhash,
amount: 1, amount: 1,
isObfuscated: true, isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{}, htlc: &lnwire.UpdateFailHTLC{},
} }
// Handle the request and checks that payment circuit works properly. // Handle the request and checks that payment circuit works properly.
@ -337,10 +338,10 @@ func TestSwitchAddSamePayment(t *testing.T) {
preimage := [sha256.Size]byte{1} preimage := [sha256.Size]byte{1}
rhash := fastsha256.Sum256(preimage[:]) rhash := fastsha256.Sum256(preimage[:])
request := &htlcPacket{ request := &htlcPacket{
src: aliceChannelLink.ShortChanID(), incomingChanID: aliceChannelLink.ShortChanID(),
srcID: 0, incomingHTLCID: 0,
dest: bobChannelLink.ShortChanID(), outgoingChanID: bobChannelLink.ShortChanID(),
obfuscator: newMockObfuscator(), obfuscator: newMockObfuscator(),
htlc: &lnwire.UpdateAddHTLC{ htlc: &lnwire.UpdateAddHTLC{
PaymentHash: rhash, PaymentHash: rhash,
Amount: 1, Amount: 1,
@ -354,9 +355,9 @@ func TestSwitchAddSamePayment(t *testing.T) {
s.addCircuit(&PaymentCircuit{ s.addCircuit(&PaymentCircuit{
PaymentHash: request.payHash, PaymentHash: request.payHash,
IncomingChanID: request.src, IncomingChanID: request.incomingChanID,
IncomingHTLCID: 0, IncomingHTLCID: request.incomingHTLCID,
OutgoingChanID: request.dest, OutgoingChanID: request.outgoingChanID,
OutgoingHTLCID: 0, OutgoingHTLCID: 0,
ErrorEncrypter: request.obfuscator, ErrorEncrypter: request.obfuscator,
}) })
@ -373,10 +374,10 @@ func TestSwitchAddSamePayment(t *testing.T) {
} }
request = &htlcPacket{ request = &htlcPacket{
src: aliceChannelLink.ShortChanID(), incomingChanID: aliceChannelLink.ShortChanID(),
srcID: 1, incomingHTLCID: 1,
dest: bobChannelLink.ShortChanID(), outgoingChanID: bobChannelLink.ShortChanID(),
obfuscator: newMockObfuscator(), obfuscator: newMockObfuscator(),
htlc: &lnwire.UpdateAddHTLC{ htlc: &lnwire.UpdateAddHTLC{
PaymentHash: rhash, PaymentHash: rhash,
Amount: 1, Amount: 1,
@ -390,9 +391,9 @@ func TestSwitchAddSamePayment(t *testing.T) {
s.addCircuit(&PaymentCircuit{ s.addCircuit(&PaymentCircuit{
PaymentHash: request.payHash, PaymentHash: request.payHash,
IncomingChanID: request.src, IncomingChanID: request.incomingChanID,
IncomingHTLCID: 1, IncomingHTLCID: request.incomingHTLCID,
OutgoingChanID: request.dest, OutgoingChanID: request.outgoingChanID,
OutgoingHTLCID: 1, OutgoingHTLCID: 1,
ErrorEncrypter: request.obfuscator, ErrorEncrypter: request.obfuscator,
}) })
@ -405,11 +406,12 @@ func TestSwitchAddSamePayment(t *testing.T) {
// the add htlc request and sent the htlc settle request back. This // the add htlc request and sent the htlc settle request back. This
// request should be forwarder back to alice channel link. // request should be forwarder back to alice channel link.
request = &htlcPacket{ request = &htlcPacket{
src: bobChannelLink.ShortChanID(), outgoingChanID: bobChannelLink.ShortChanID(),
payHash: rhash, outgoingHTLCID: 0,
amount: 1, payHash: rhash,
isObfuscated: true, amount: 1,
htlc: &lnwire.UpdateFailHTLC{}, isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{},
} }
// Handle the request and checks that payment circuit works properly. // Handle the request and checks that payment circuit works properly.
@ -429,12 +431,12 @@ func TestSwitchAddSamePayment(t *testing.T) {
} }
request = &htlcPacket{ request = &htlcPacket{
src: bobChannelLink.ShortChanID(), outgoingChanID: bobChannelLink.ShortChanID(),
srcID: 1, outgoingHTLCID: 1,
payHash: rhash, payHash: rhash,
amount: 1, amount: 1,
isObfuscated: true, isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{}, htlc: &lnwire.UpdateFailHTLC{},
} }
// Handle the request and checks that payment circuit works properly. // Handle the request and checks that payment circuit works properly.
@ -532,10 +534,11 @@ func TestSwitchSendPayment(t *testing.T) {
} }
packet := &htlcPacket{ packet := &htlcPacket{
src: aliceChannelLink.ShortChanID(), outgoingChanID: aliceChannelLink.ShortChanID(),
payHash: rhash, outgoingHTLCID: 0,
amount: 1, payHash: rhash,
isObfuscated: true, amount: 1,
isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{ htlc: &lnwire.UpdateFailHTLC{
Reason: reason, Reason: reason,
ID: 1, ID: 1,