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

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

@ -1,8 +1,6 @@
package htlcswitch package htlcswitch
import ( import (
"crypto/sha256"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
) )
@ -13,12 +11,6 @@ type htlcPacket struct {
// message. // message.
destNode [33]byte 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 // incomingChanID is the ID of the channel that we have received an incoming
// HTLC on. // HTLC on.
incomingChanID lnwire.ShortChannelID incomingChanID lnwire.ShortChannelID

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

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

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