From ec6c0689ef6d61c060f912781b1d1423f7ba6e7f Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Fri, 3 Jan 2020 15:53:24 +0100 Subject: [PATCH] channeldb: fix channeldb.InvoiceHTLC deep copy This commit fixes deep copy of chaneldb.InvoiceHTLC, where previously the map holding the custom record set wasn't properly copied. --- channeldb/invoices.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/channeldb/invoices.go b/channeldb/invoices.go index ff916a0ab..62c767a43 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -1327,6 +1327,19 @@ func copySlice(src []byte) []byte { return dest } +// copyInvoiceHTLC makes a deep copy of the supplied invoice HTLC. +func copyInvoiceHTLC(src *InvoiceHTLC) *InvoiceHTLC { + result := *src + + // Make a copy of the CustomSet map. + result.CustomRecords = make(record.CustomSet) + for k, v := range src.CustomRecords { + result.CustomRecords[k] = v + } + + return &result +} + // copyInvoice makes a deep copy of the supplied invoice. func copyInvoice(src *Invoice) *Invoice { dest := Invoice{ @@ -1347,7 +1360,7 @@ func copyInvoice(src *Invoice) *Invoice { dest.Terms.Features = src.Terms.Features.Clone() for k, v := range src.Htlcs { - dest.Htlcs[k] = v + dest.Htlcs[k] = copyInvoiceHTLC(v) } return &dest