htlcswitch: eliminate unnecessary indentation in processRemoteAdds

In this commit, we remove a ton of unnecessary indentation in the
processRemoteAdds method. Before this commit, we had a switch statement
on the type of the entry. This was required before when the method was
generic, but now since we already know that it’s an Add, we no longer
require such a statement.
This commit is contained in:
Olaoluwa Osuntokun 2018-03-12 18:55:04 -07:00
parent 069311c47f
commit 8988a07bce
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 430 additions and 443 deletions

View File

@ -1812,30 +1812,25 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
continue continue
} }
// TODO(roasbeef): rework log entries to a shared
// interface.
switch pd.EntryType {
// An incoming HTLC add has been full-locked in. As a result we // An incoming HTLC add has been full-locked in. As a result we
// can now examine the forwarding details of the HTLC, and the // can now examine the forwarding details of the HTLC, and the
// HTLC itself to decide if: we should forward it, cancel it, // HTLC itself to decide if: we should forward it, cancel it,
// or are able to settle it (and it adheres to our fee related // or are able to settle it (and it adheres to our fee related
// constraints). // constraints).
case lnwallet.Add:
// Fetch the onion blob that was included within this // Fetch the onion blob that was included within this processed
// processed payment descriptor. // payment descriptor.
var onionBlob [lnwire.OnionPacketSize]byte var onionBlob [lnwire.OnionPacketSize]byte
copy(onionBlob[:], pd.OnionBlob) copy(onionBlob[:], pd.OnionBlob)
// Before adding the new htlc to the state machine, // Before adding the new htlc to the state machine, parse the
// parse the onion object in order to obtain the // onion object in order to obtain the routing information with
// routing information with DecodeHopIterator function // DecodeHopIterator function which process the Sphinx packet.
// which process the Sphinx packet.
chanIterator, failureCode := decodeResps[i].Result() chanIterator, failureCode := decodeResps[i].Result()
if failureCode != lnwire.CodeNone { if failureCode != lnwire.CodeNone {
// If we're unable to process the onion blob // If we're unable to process the onion blob than we
// than we should send the malformed htlc error // should send the malformed htlc error to payment
// to payment sender. // sender.
l.sendMalformedHTLCError(pd.HtlcIndex, failureCode, l.sendMalformedHTLCError(pd.HtlcIndex, failureCode,
onionBlob[:], pd.SourceRef) onionBlob[:], pd.SourceRef)
needUpdate = true needUpdate = true
@ -1845,16 +1840,15 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
continue continue
} }
// Retrieve onion obfuscator from onion blob in order // Retrieve onion obfuscator from onion blob in order to
// to produce initial obfuscation of the onion // produce initial obfuscation of the onion failureCode.
// failureCode.
obfuscator, failureCode := chanIterator.ExtractErrorEncrypter( obfuscator, failureCode := chanIterator.ExtractErrorEncrypter(
l.cfg.DecodeOnionObfuscator, l.cfg.DecodeOnionObfuscator,
) )
if failureCode != lnwire.CodeNone { if failureCode != lnwire.CodeNone {
// If we're unable to process the onion blob // If we're unable to process the onion blob than we
// than we should send the malformed htlc error // should send the malformed htlc error to payment
// to payment sender. // sender.
l.sendMalformedHTLCError(pd.HtlcIndex, failureCode, l.sendMalformedHTLCError(pd.HtlcIndex, failureCode,
onionBlob[:], pd.SourceRef) onionBlob[:], pd.SourceRef)
needUpdate = true needUpdate = true
@ -1869,132 +1863,129 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
fwdInfo := chanIterator.ForwardingInstructions() fwdInfo := chanIterator.ForwardingInstructions()
switch fwdInfo.NextHop { switch fwdInfo.NextHop {
case exitHop: case exitHop:
if l.cfg.DebugHTLC && l.cfg.HodlHTLC { if l.cfg.DebugHTLC && l.cfg.HodlHTLC {
log.Warnf("hodl HTLC mode enabled, " + log.Warnf("hodl HTLC mode enabled, will not " +
"will not attempt to settle " + "attempt to settle HTLC with sender")
"HTLC with sender")
continue continue
} }
// First, we'll check the expiry of the HTLC // First, we'll check the expiry of the HTLC itself
// itself against, the current block height. If // against, the current block height. If the timeout is
// the timeout is too soon, then we'll reject // too soon, then we'll reject the HTLC.
// the HTLC.
if pd.Timeout-expiryGraceDelta <= heightNow { if pd.Timeout-expiryGraceDelta <= heightNow {
log.Errorf("htlc(%x) has an expiry "+ log.Errorf("htlc(%x) has an expiry that's too "+
"that's too soon: expiry=%v, "+ "soon: expiry=%v, best_height=%v",
"best_height=%v", pd.RHash[:], pd.RHash[:], pd.Timeout, heightNow)
pd.Timeout, heightNow)
failure := lnwire.FailFinalIncorrectCltvExpiry{} failure := lnwire.FailFinalIncorrectCltvExpiry{}
l.sendHTLCError(pd.HtlcIndex, &failure, l.sendHTLCError(
obfuscator, pd.SourceRef) pd.HtlcIndex, &failure, obfuscator, pd.SourceRef,
)
needUpdate = true needUpdate = true
continue continue
} }
// We're the designated payment destination. // We're the designated payment destination. Therefore
// Therefore we attempt to see if we have an // we attempt to see if we have an invoice locally
// invoice locally which'll allow us to settle // which'll allow us to settle this htlc.
// this htlc.
invoiceHash := chainhash.Hash(pd.RHash) invoiceHash := chainhash.Hash(pd.RHash)
invoice, err := l.cfg.Registry.LookupInvoice(invoiceHash) invoice, err := l.cfg.Registry.LookupInvoice(invoiceHash)
if err != nil { if err != nil {
log.Errorf("unable to query invoice registry: "+ log.Errorf("unable to query invoice registry: "+
" %v", err) " %v", err)
failure := lnwire.FailUnknownPaymentHash{} failure := lnwire.FailUnknownPaymentHash{}
l.sendHTLCError(pd.HtlcIndex, failure, l.sendHTLCError(
obfuscator, pd.SourceRef) pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
)
needUpdate = true needUpdate = true
continue continue
} }
// If the invoice is already settled, we choose // If the invoice is already settled, we choose to
// to accept the payment to simplify failure // accept the payment to simplify failure recovery.
// recovery.
// //
// NOTE: Though our recovery and forwarding logic is // NOTE: Though our recovery and forwarding logic is
// predominately batched, settling invoices // predominately batched, settling invoices happens
// happens iteratively. We may reject one of of // iteratively. We may reject one of of two payments
// two payments for the same rhash at first, but // for the same rhash at first, but then restart and
// then restart and reject both after seeing // reject both after seeing that the invoice has been
// that the invoice has been settled. Without // settled. Without any record of which one settles
// any record of which one settles first, it is // first, it is ambiguous as to which one actually
// ambiguous as to which one actually settled // settled the invoice. Thus, by accepting all
// the invoice. Thus, by accepting all payments, // payments, we eliminate the race condition that can
// we eliminate the race condition that can lead // lead to this inconsistency.
// to this inconsistency.
// //
// TODO(conner): track ownership of settlements // TODO(conner): track ownership of settlements to
// to properly recover from failures? or add // properly recover from failures? or add batch invoice
// batch invoice settlement // settlement
if invoice.Terms.Settled { if invoice.Terms.Settled {
log.Warnf("Accepting duplicate "+ log.Warnf("Accepting duplicate payment for "+
"payment for hash=%x", pd.RHash[:]) "hash=%x", pd.RHash[:])
} }
// If we're not currently in debug mode, and // If we're not currently in debug mode, and the
// the extended htlc doesn't meet the value // extended htlc doesn't meet the value requested, then
// requested, then we'll fail the htlc. // we'll fail the htlc. Otherwise, we settle this htlc
// Otherwise, we settle this htlc within our // within our local state update log, then send the
// local state update log, then send the update // update entry to the remote party.
// entry to the remote party.
// //
// NOTE: We make an exception when the value // NOTE: We make an exception when the value requested
// requested by the invoice is zero. This means // by the invoice is zero. This means the invoice
// the invoice allows the payee to specify the // allows the payee to specify the amount of satoshis
// amount of satoshis they wish to send. // they wish to send. So since we expect the htlc to
// So since we expect the htlc to have a // have a different amount, we should not fail.
// different amount, we should not fail.
if !l.cfg.DebugHTLC && invoice.Terms.Value > 0 && if !l.cfg.DebugHTLC && invoice.Terms.Value > 0 &&
pd.Amount < invoice.Terms.Value { pd.Amount < invoice.Terms.Value {
log.Errorf("rejecting htlc due to incorrect "+ log.Errorf("rejecting htlc due to incorrect "+
"amount: expected %v, received %v", "amount: expected %v, received %v",
invoice.Terms.Value, pd.Amount) invoice.Terms.Value, pd.Amount)
failure := lnwire.FailIncorrectPaymentAmount{} failure := lnwire.FailIncorrectPaymentAmount{}
l.sendHTLCError(pd.HtlcIndex, failure, l.sendHTLCError(
obfuscator, pd.SourceRef) pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
)
needUpdate = true needUpdate = true
continue continue
} }
// As we're the exit hop, we'll double check // As we're the exit hop, we'll double check the
// the hop-payload included in the HTLC to // hop-payload included in the HTLC to ensure that it
// ensure that it was crafted correctly by the // was crafted correctly by the sender and matches the
// sender and matches the HTLC we were // HTLC we were extended.
// extended.
// //
// NOTE: We make an exception when the value // NOTE: We make an exception when the value requested
// requested by the invoice is zero. This means // by the invoice is zero. This means the invoice
// the invoice allows the payee to specify the // allows the payee to specify the amount of satoshis
// amount of satoshis they wish to send. // they wish to send. So since we expect the htlc to
// So since we expect the htlc to have a // have a different amount, we should not fail.
// different amount, we should not fail.
if !l.cfg.DebugHTLC && invoice.Terms.Value > 0 && if !l.cfg.DebugHTLC && invoice.Terms.Value > 0 &&
fwdInfo.AmountToForward != invoice.Terms.Value { fwdInfo.AmountToForward != invoice.Terms.Value {
log.Errorf("Onion payload of incoming "+ log.Errorf("Onion payload of incoming htlc(%x) "+
"htlc(%x) has incorrect value: "+ "has incorrect value: expected %v, "+
"expected %v, got %v", pd.RHash, "got %v", pd.RHash, invoice.Terms.Value,
invoice.Terms.Value,
fwdInfo.AmountToForward) fwdInfo.AmountToForward)
failure := lnwire.FailIncorrectPaymentAmount{} failure := lnwire.FailIncorrectPaymentAmount{}
l.sendHTLCError(pd.HtlcIndex, failure, l.sendHTLCError(
obfuscator, pd.SourceRef) pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
)
needUpdate = true needUpdate = true
continue continue
} }
// We'll also ensure that our time-lock value // We'll also ensure that our time-lock value has been
// has been computed correctly. // computed correctly.
// //
// TODO(roasbeef): also accept global default? // TODO(roasbeef): also accept global default?
expectedHeight := heightNow + l.cfg.FwrdingPolicy.TimeLockDelta expectedHeight := heightNow + l.cfg.FwrdingPolicy.TimeLockDelta
if !l.cfg.DebugHTLC {
switch { switch {
case fwdInfo.OutgoingCTLV < expectedHeight:
case !l.cfg.DebugHTLC && fwdInfo.OutgoingCTLV < expectedHeight:
log.Errorf("Onion payload of incoming "+ log.Errorf("Onion payload of incoming "+
"htlc(%x) has incorrect time-lock: "+ "htlc(%x) has incorrect time-lock: "+
"expected %v, got %v", "expected %v, got %v",
@ -2004,12 +1995,14 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
failure := lnwire.NewFinalIncorrectCltvExpiry( failure := lnwire.NewFinalIncorrectCltvExpiry(
fwdInfo.OutgoingCTLV, fwdInfo.OutgoingCTLV,
) )
l.sendHTLCError(pd.HtlcIndex, l.sendHTLCError(
failure, obfuscator, pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
pd.SourceRef) )
needUpdate = true needUpdate = true
continue continue
case pd.Timeout != fwdInfo.OutgoingCTLV:
case !l.cfg.DebugHTLC && pd.Timeout != fwdInfo.OutgoingCTLV:
log.Errorf("HTLC(%x) has incorrect "+ log.Errorf("HTLC(%x) has incorrect "+
"time-lock: expected %v, got %v", "time-lock: expected %v, got %v",
pd.RHash[:], pd.Timeout, pd.RHash[:], pd.Timeout,
@ -2018,13 +2011,13 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
failure := lnwire.NewFinalIncorrectCltvExpiry( failure := lnwire.NewFinalIncorrectCltvExpiry(
fwdInfo.OutgoingCTLV, fwdInfo.OutgoingCTLV,
) )
l.sendHTLCError(pd.HtlcIndex, l.sendHTLCError(
failure, obfuscator, pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
pd.SourceRef) )
needUpdate = true needUpdate = true
continue continue
} }
}
preimage := invoice.Terms.PaymentPreimage preimage := invoice.Terms.PaymentPreimage
err = l.channel.SettleHTLC(preimage, err = l.channel.SettleHTLC(preimage,
@ -2034,16 +2027,15 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
return false return false
} }
// Notify the invoiceRegistry of the invoices we // Notify the invoiceRegistry of the invoices we just
// just settled with this latest commitment // settled with this latest commitment update.
// update.
err = l.cfg.Registry.SettleInvoice(invoiceHash) err = l.cfg.Registry.SettleInvoice(invoiceHash)
if err != nil { if err != nil {
l.fail("unable to settle invoice: %v", err) l.fail("unable to settle invoice: %v", err)
return false return false
} }
l.infof("Settling %x as exit hop", pd.RHash) l.infof("settling %x as exit hop", pd.RHash)
// HTLC was successfully settled locally send // HTLC was successfully settled locally send
// notification about it remote peer. // notification about it remote peer.
@ -2054,26 +2046,24 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
}) })
needUpdate = true needUpdate = true
// There are additional channels left within this // There are additional channels left within this route. So
// route. So we'll verify that our forwarding // we'll verify that our forwarding constraints have been
// constraints have been properly met by by this // properly met by by this incoming HTLC.
// incoming HTLC.
default: default:
switch fwdPkg.State { switch fwdPkg.State {
case channeldb.FwdStateProcessed: case channeldb.FwdStateProcessed:
// This add was not forwarded on the previous
// processing phase, run it through our
// validation pipeline to reproduce an error.
// This may trigger a different error due to
// expiring timelocks, but we expect that an
// error will be reproduced.
if !fwdPkg.FwdFilter.Contains(idx) { if !fwdPkg.FwdFilter.Contains(idx) {
// This add was not forwarded on
// the previous processing
// phase, run it through our
// validation pipeline to
// reproduce an error. This may
// trigger a different error due
// to expiring timelocks, but we
// expect that an error will be
// reproduced.
break break
} }
// Otherwise, it was already processed, we can
// can collect it and continue.
addMsg := &lnwire.UpdateAddHTLC{ addMsg := &lnwire.UpdateAddHTLC{
Expiry: fwdInfo.OutgoingCTLV, Expiry: fwdInfo.OutgoingCTLV,
Amount: fwdInfo.AmountToForward, Amount: fwdInfo.AmountToForward,
@ -2106,10 +2096,10 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
continue continue
} }
// We want to avoid forwarding an HTLC which // We want to avoid forwarding an HTLC which will
// will expire in the near future, so we'll // expire in the near future, so we'll reject an HTLC
// reject an HTLC if its expiration time is too // if its expiration time is too close to the current
// close to the current height. // height.
timeDelta := l.cfg.FwrdingPolicy.TimeLockDelta timeDelta := l.cfg.FwrdingPolicy.TimeLockDelta
if pd.Timeout-timeDelta <= heightNow { if pd.Timeout-timeDelta <= heightNow {
log.Errorf("htlc(%x) has an expiry "+ log.Errorf("htlc(%x) has an expiry "+
@ -2125,14 +2115,15 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
failure = lnwire.NewExpiryTooSoon(*update) failure = lnwire.NewExpiryTooSoon(*update)
} }
l.sendHTLCError(pd.HtlcIndex, failure, l.sendHTLCError(
obfuscator, pd.SourceRef) pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
)
needUpdate = true needUpdate = true
continue continue
} }
// As our second sanity check, we'll ensure that // As our second sanity check, we'll ensure that the
// the passed HTLC isn't too small. If so, then // passed HTLC isn't too small. If so, then
// we'll cancel the HTLC directly. // we'll cancel the HTLC directly.
if pd.Amount < l.cfg.FwrdingPolicy.MinHTLC { if pd.Amount < l.cfg.FwrdingPolicy.MinHTLC {
log.Errorf("Incoming htlc(%x) is too "+ log.Errorf("Incoming htlc(%x) is too "+
@ -2140,10 +2131,9 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
pd.RHash[:], l.cfg.FwrdingPolicy.MinHTLC, pd.RHash[:], l.cfg.FwrdingPolicy.MinHTLC,
pd.Amount) pd.Amount)
// As part of the returned error, we'll // As part of the returned error, we'll send
// send our latest routing policy so // our latest routing policy so the sending
// the sending node obtains the most up // node obtains the most up to date data.
// to date data.
var failure lnwire.FailureMessage var failure lnwire.FailureMessage
update, err := l.cfg.GetLastChannelUpdate() update, err := l.cfg.GetLastChannelUpdate()
if err != nil { if err != nil {
@ -2153,43 +2143,40 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
pd.Amount, *update) pd.Amount, *update)
} }
l.sendHTLCError(pd.HtlcIndex, failure, l.sendHTLCError(
obfuscator, pd.SourceRef) pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
)
needUpdate = true needUpdate = true
continue continue
} }
// Next, using the amount of the incoming HTLC, // Next, using the amount of the incoming HTLC, we'll
// we'll calculate the expected fee this // calculate the expected fee this incoming HTLC must
// incoming HTLC must carry in order to be // carry in order to be accepted.
// accepted.
expectedFee := ExpectedFee( expectedFee := ExpectedFee(
l.cfg.FwrdingPolicy, l.cfg.FwrdingPolicy,
fwdInfo.AmountToForward, fwdInfo.AmountToForward,
) )
// If the actual fee is less than our expected // If the actual fee is less than our expected
// fee, then we'll reject this HTLC as it // fee, then we'll reject this HTLC as it didn't
// didn't provide a sufficient amount of fees, // provide a sufficient amount of fees, or the values
// or the values have been tampered with, or // have been tampered with, or the send used
// the send used incorrect/dated information to // incorrect/dated information to construct the
// construct the forwarding information for // forwarding information for this hop. In any case,
// this hop. In any case, we'll cancel this // we'll cancel this HTLC.
// HTLC.
actualFee := pd.Amount - fwdInfo.AmountToForward actualFee := pd.Amount - fwdInfo.AmountToForward
if pd.Amount < fwdInfo.AmountToForward || if pd.Amount < fwdInfo.AmountToForward ||
actualFee < expectedFee { actualFee < expectedFee {
log.Errorf("Incoming htlc(%x) has "+ log.Errorf("Incoming htlc(%x) has insufficient "+
"insufficient fee: expected "+ "fee: expected %v, got %v", pd.RHash[:],
"%v, got %v", pd.RHash[:],
int64(expectedFee), int64(expectedFee),
int64(pd.Amount-fwdInfo.AmountToForward)) int64(pd.Amount-fwdInfo.AmountToForward))
// As part of the returned error, we'll // As part of the returned error, we'll send
// send our latest routing policy so // our latest routing policy so the sending
// the sending node obtains the most up // node obtains the most up to date data.
// to date data.
var failure lnwire.FailureMessage var failure lnwire.FailureMessage
update, err := l.cfg.GetLastChannelUpdate() update, err := l.cfg.GetLastChannelUpdate()
if err != nil { if err != nil {
@ -2199,30 +2186,29 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
*update) *update)
} }
l.sendHTLCError(pd.HtlcIndex, failure, l.sendHTLCError(
obfuscator, pd.SourceRef) pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
)
needUpdate = true needUpdate = true
continue continue
} }
// Finally, we'll ensure that the time-lock on // Finally, we'll ensure that the time-lock on the
// the outgoing HTLC meets the following // outgoing HTLC meets the following constraint: the
// constraint: the incoming time-lock minus our // incoming time-lock minus our time-lock delta should
// time-lock delta should equal the outgoing // equal the outgoing time lock. Otherwise, whether the
// time lock. Otherwise, whether the sender // sender messed up, or an intermediate node tampered
// messed up, or an intermediate node tampered
// with the HTLC. // with the HTLC.
if pd.Timeout-timeDelta < fwdInfo.OutgoingCTLV { if pd.Timeout-timeDelta < fwdInfo.OutgoingCTLV {
log.Errorf("Incoming htlc(%x) has "+ log.Errorf("Incoming htlc(%x) has incorrect "+
"incorrect time-lock value: "+ "time-lock value: expected at least "+
"expected at least %v block delta, "+ "%v block delta, got %v block delta",
"got %v block delta", pd.RHash[:], pd.RHash[:], timeDelta,
timeDelta,
pd.Timeout-fwdInfo.OutgoingCTLV) pd.Timeout-fwdInfo.OutgoingCTLV)
// Grab the latest routing policy so // Grab the latest routing policy so the
// the sending node is up to date with // sending node is up to date with our current
// our current policy. // policy.
update, err := l.cfg.GetLastChannelUpdate() update, err := l.cfg.GetLastChannelUpdate()
if err != nil { if err != nil {
l.fail("unable to create channel update "+ l.fail("unable to create channel update "+
@ -2232,27 +2218,28 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
failure := lnwire.NewIncorrectCltvExpiry( failure := lnwire.NewIncorrectCltvExpiry(
pd.Timeout, *update) pd.Timeout, *update)
l.sendHTLCError(pd.HtlcIndex, failure, l.sendHTLCError(
obfuscator, pd.SourceRef) pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
)
needUpdate = true needUpdate = true
continue continue
} }
// TODO(roasbeef): also add max timeout value // TODO(roasbeef): also add max timeout value
// With all our forwarding constraints met, // With all our forwarding constraints met, we'll
// we'll create the outgoing HTLC using the // create the outgoing HTLC using the parameters as
// parameters as specified in the forwarding // specified in the forwarding info.
// info.
addMsg := &lnwire.UpdateAddHTLC{ addMsg := &lnwire.UpdateAddHTLC{
Expiry: fwdInfo.OutgoingCTLV, Expiry: fwdInfo.OutgoingCTLV,
Amount: fwdInfo.AmountToForward, Amount: fwdInfo.AmountToForward,
PaymentHash: pd.RHash, PaymentHash: pd.RHash,
} }
// Finally, we'll encode the onion packet for // Finally, we'll encode the onion packet for the
// the _next_ hop using the hop iterator // _next_ hop using the hop iterator decoded for the
// decoded for the current hop. // current hop.
buf := bytes.NewBuffer(addMsg.OnionBlob[0:0]) buf := bytes.NewBuffer(addMsg.OnionBlob[0:0])
err := chanIterator.EncodeNextHop(buf) err := chanIterator.EncodeNextHop(buf)
if err != nil { if err != nil {
@ -2260,21 +2247,22 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
"remaining route %v", err) "remaining route %v", err)
failure := lnwire.NewTemporaryChannelFailure(nil) failure := lnwire.NewTemporaryChannelFailure(nil)
l.sendHTLCError(pd.HtlcIndex, failure,
obfuscator, pd.SourceRef) l.sendHTLCError(
pd.HtlcIndex, failure, obfuscator, pd.SourceRef,
)
needUpdate = true needUpdate = true
continue continue
} }
// Now that this add has been reprocessed, only // Now that this add has been reprocessed, only append
// append it to our list of packets to forward // it to our list of packets to forward to the switch
// to the switch this is the first time // this is the first time processing the add. If the
// processing the add. If the fwd pkg has // fwd pkg has already been processed, then we entered
// already been processed, then we entered the // the above section to recreate a previous error. If
// above section to recreate a previous error. // the packet had previously been forwarded, it would
// If the packet had previously been forwarded, // have been added to switchPackets at the top of this
// it would have been added to switchPackets at // section.
// the top of this section.
if fwdPkg.State == channeldb.FwdStateLockedIn { if fwdPkg.State == channeldb.FwdStateLockedIn {
updatePacket := &htlcPacket{ updatePacket := &htlcPacket{
incomingChanID: l.ShortChanID(), incomingChanID: l.ShortChanID(),
@ -2293,7 +2281,6 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
} }
} }
} }
}
// Commit the htlcs we are intending to forward if this package has not // Commit the htlcs we are intending to forward if this package has not
// been fully processed. // been fully processed.