From 278e10a2fd4d0ba6e59d27b5a27c61bc09a2df87 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 4 Sep 2019 08:39:22 -0700 Subject: [PATCH] routing/route/route: omit next_hop_id for final hop BOLT04 says to omit this field for final hops, but must be present on all other hops. --- routing/route/route.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/routing/route/route.go b/routing/route/route.go index 13eddfeb8..e9e159f65 100644 --- a/routing/route/route.go +++ b/routing/route/route.go @@ -108,9 +108,18 @@ func (h *Hop) PackHopPayload(w io.Writer, nextChanID uint64) error { combinedRecords := append(h.TLVRecords, record.NewAmtToFwdRecord(&amt), record.NewLockTimeRecord(&h.OutgoingTimeLock), - record.NewNextHopIDRecord(&nextChanID), ) + // BOLT 04 says the next_hop_id should be omitted for the final hop, + // but present for all others. + // + // TODO(conner): test using hop.Exit once available + if nextChanID != 0 { + combinedRecords = append(combinedRecords, + record.NewNextHopIDRecord(&nextChanID), + ) + } + // To ensure we produce a canonical stream, we'll sort the records // before encoding them as a stream in the hop payload. tlv.SortRecords(combinedRecords)