From de2b7b78dea226013811e9784e67d7ca3a57e1bf Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Thu, 12 Dec 2019 14:47:46 +0100 Subject: [PATCH] channeldb: custom records sanity check --- channeldb/payments.go | 9 +++++++++ channeldb/payments_test.go | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/channeldb/payments.go b/channeldb/payments.go index 0e2b865df..c3c093269 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -607,6 +607,15 @@ func serializeHop(w io.Writer, h *route.Hop) error { records = append(records, h.MPP.Record()) } + // Final sanity check to absolutely rule out custom records that are not + // custom and write into the standard range. + if err := h.CustomRecords.Validate(); err != nil { + return err + } + + // Convert custom records to tlv and add to the record list. + // MapToRecords sorts the list, so adding it here will keep the list + // canonical. tlvRecords := tlv.MapToRecords(h.CustomRecords) records = append(records, tlvRecords...) diff --git a/channeldb/payments_test.go b/channeldb/payments_test.go index 8eba5e5ac..16e952df4 100644 --- a/channeldb/payments_test.go +++ b/channeldb/payments_test.go @@ -28,8 +28,8 @@ var ( OutgoingTimeLock: 111, AmtToForward: 555, CustomRecords: record.CustomSet{ - 1: []byte{}, - 2: []byte{}, + 65536: []byte{}, + 80001: []byte{}, }, MPP: record.NewMPP(32, [32]byte{0x42}), }