htlcswitch: Remove obsolete fields from htlcPacket.

This commit is contained in:
Jim Posen 2017-10-30 12:21:07 -07:00 committed by Olaoluwa Osuntokun
parent 40fb0ddcfc
commit 6ea533275c
6 changed files with 22 additions and 40 deletions

@ -701,7 +701,6 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
failPkt := &htlcPacket{
incomingChanID: pkt.incomingChanID,
incomingHTLCID: pkt.incomingHTLCID,
payHash: htlc.PaymentHash,
amount: htlc.Amount,
isObfuscated: isObfuscated,
htlc: &lnwire.UpdateFailHTLC{
@ -1192,7 +1191,6 @@ func (l *channelLink) processLockedInHtlcs(
settlePacket := &htlcPacket{
outgoingChanID: l.ShortChanID(),
outgoingHTLCID: pd.ParentIndex,
payHash: pd.RHash,
amount: pd.Amount,
htlc: &lnwire.UpdateFufillHTLC{
PaymentPreimage: pd.RPreimage,
@ -1215,7 +1213,6 @@ func (l *channelLink) processLockedInHtlcs(
failPacket := &htlcPacket{
outgoingChanID: l.ShortChanID(),
outgoingHTLCID: pd.ParentIndex,
payHash: pd.RHash,
amount: pd.Amount,
isObfuscated: false,
htlc: &lnwire.UpdateFailHTLC{
@ -1588,6 +1585,7 @@ func (l *channelLink) processLockedInHtlcs(
incomingChanID: l.ShortChanID(),
incomingHTLCID: pd.HtlcIndex,
outgoingChanID: fwdInfo.NextHop,
amount: addMsg.Amount,
htlc: addMsg,
obfuscator: obfuscator,
}

@ -1620,7 +1620,6 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
htlc: &lnwire.UpdateFailHTLC{
ID: 3,
},
payHash: htlc.PaymentHash,
}
aliceLink.HandleSwitchPacket(&failPkt)
time.Sleep(time.Millisecond * 100)
@ -1662,11 +1661,10 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) {
if err != nil {
t.Fatalf("unable to create payment: %v", err)
}
addPkt := htlcPacket{
aliceLink.HandleSwitchPacket(&htlcPacket{
htlc: htlc,
amount: amt,
}
aliceLink.HandleSwitchPacket(&addPkt)
})
return invoice.Terms.PaymentPreimage
}

@ -1,8 +1,6 @@
package htlcswitch
import (
"crypto/sha256"
"github.com/lightningnetwork/lnd/lnwire"
)
@ -13,12 +11,6 @@ type htlcPacket struct {
// message.
destNode [33]byte
// payHash is the payment hash of the HTLC which was modified by either
// a settle or fail action.
//
// NOTE: This fields is initialized only in settle and fail packets.
payHash [sha256.Size]byte
// incomingChanID is the ID of the channel that we have received an incoming
// HTLC on.
incomingChanID lnwire.ShortChannelID

@ -20,12 +20,12 @@ func TestWaitingQueueThreadSafety(t *testing.T) {
q.Start()
defer q.Stop()
a := make([]lnwire.MilliSatoshi, numPkts)
a := make([]uint64, numPkts)
for i := 0; i < numPkts; i++ {
a[i] = lnwire.MilliSatoshi(i)
a[i] = uint64(i)
q.AddPkt(&htlcPacket{
amount: lnwire.MilliSatoshi(i),
htlc: &lnwire.UpdateAddHTLC{},
incomingHTLCID: a[i],
htlc: &lnwire.UpdateAddHTLC{},
})
}
@ -37,13 +37,13 @@ func TestWaitingQueueThreadSafety(t *testing.T) {
queueLength)
}
var b []lnwire.MilliSatoshi
var b []uint64
for i := 0; i < numPkts; i++ {
q.SignalFreeSlot()
select {
case packet := <-q.outgoingPkts:
b = append(b, packet.amount)
b = append(b, packet.incomingHTLCID)
case <-time.After(2 * time.Second):
t.Fatal("timeout")

@ -503,7 +503,6 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
source.HandleSwitchPacket(&htlcPacket{
incomingChanID: packet.incomingChanID,
incomingHTLCID: packet.incomingHTLCID,
payHash: htlc.PaymentHash,
isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{
Reason: reason,
@ -552,7 +551,6 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
source.HandleSwitchPacket(&htlcPacket{
incomingChanID: packet.incomingChanID,
incomingHTLCID: packet.incomingHTLCID,
payHash: htlc.PaymentHash,
isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{
Reason: reason,
@ -581,9 +579,8 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
packet.outgoingHTLCID)
if circuit == nil {
err := errors.Errorf("Unable to find target channel for HTLC "+
"settle/fail: channel ID = %s, HTLC ID = %d, "+
"payment hash = %x", packet.outgoingChanID,
packet.outgoingHTLCID, packet.payHash[:])
"settle/fail: channel ID = %s, HTLC ID = %d",
packet.outgoingChanID, packet.outgoingHTLCID)
log.Error(err)
return err
}
@ -593,12 +590,14 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
packet.outgoingHTLCID)
if err != nil {
log.Warnf("Failed to close completed onion circuit for %x: "+
"%s<->%s", packet.payHash[:], circuit.IncomingChanID,
circuit.OutgoingChanID)
"(%s, %d) <-> (%s, %d)", circuit.PaymentHash,
circuit.IncomingChanID, circuit.IncomingHTLCID,
circuit.OutgoingChanID, circuit.OutgoingHTLCID)
} else {
log.Debugf("Closed completed onion circuit for %x: %s<->%s",
packet.payHash[:], circuit.IncomingChanID,
circuit.OutgoingChanID)
log.Debugf("Closed completed onion circuit for %x: "+
"(%s, %d) <-> (%s, %d)", circuit.PaymentHash,
circuit.IncomingChanID, circuit.IncomingHTLCID,
circuit.OutgoingChanID, circuit.OutgoingHTLCID)
}
packet.incomingChanID = circuit.IncomingChanID

@ -72,7 +72,7 @@ func TestSwitchForward(t *testing.T) {
}
s.addCircuit(&PaymentCircuit{
PaymentHash: packet.payHash,
PaymentHash: rhash,
IncomingChanID: packet.incomingChanID,
IncomingHTLCID: packet.incomingHTLCID,
OutgoingChanID: packet.outgoingChanID,
@ -97,7 +97,6 @@ func TestSwitchForward(t *testing.T) {
packet = &htlcPacket{
outgoingChanID: bobChannelLink.ShortChanID(),
outgoingHTLCID: 0,
payHash: rhash,
amount: 1,
htlc: &lnwire.UpdateFufillHTLC{
PaymentPreimage: preimage,
@ -261,7 +260,7 @@ func TestSwitchCancel(t *testing.T) {
}
s.addCircuit(&PaymentCircuit{
PaymentHash: request.payHash,
PaymentHash: rhash,
IncomingChanID: request.incomingChanID,
IncomingHTLCID: request.incomingHTLCID,
OutgoingChanID: request.outgoingChanID,
@ -286,7 +285,6 @@ func TestSwitchCancel(t *testing.T) {
request = &htlcPacket{
outgoingChanID: bobChannelLink.ShortChanID(),
outgoingHTLCID: 0,
payHash: rhash,
amount: 1,
isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{},
@ -354,7 +352,7 @@ func TestSwitchAddSamePayment(t *testing.T) {
}
s.addCircuit(&PaymentCircuit{
PaymentHash: request.payHash,
PaymentHash: rhash,
IncomingChanID: request.incomingChanID,
IncomingHTLCID: request.incomingHTLCID,
OutgoingChanID: request.outgoingChanID,
@ -390,7 +388,7 @@ func TestSwitchAddSamePayment(t *testing.T) {
}
s.addCircuit(&PaymentCircuit{
PaymentHash: request.payHash,
PaymentHash: rhash,
IncomingChanID: request.incomingChanID,
IncomingHTLCID: request.incomingHTLCID,
OutgoingChanID: request.outgoingChanID,
@ -408,7 +406,6 @@ func TestSwitchAddSamePayment(t *testing.T) {
request = &htlcPacket{
outgoingChanID: bobChannelLink.ShortChanID(),
outgoingHTLCID: 0,
payHash: rhash,
amount: 1,
isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{},
@ -433,7 +430,6 @@ func TestSwitchAddSamePayment(t *testing.T) {
request = &htlcPacket{
outgoingChanID: bobChannelLink.ShortChanID(),
outgoingHTLCID: 1,
payHash: rhash,
amount: 1,
isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{},
@ -536,7 +532,6 @@ func TestSwitchSendPayment(t *testing.T) {
packet := &htlcPacket{
outgoingChanID: aliceChannelLink.ShortChanID(),
outgoingHTLCID: 0,
payHash: rhash,
amount: 1,
isObfuscated: true,
htlc: &lnwire.UpdateFailHTLC{