From 5d4ceca0383f279537776f7fbfcc2fda6202bb78 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 22 Nov 2019 12:10:04 +0100 Subject: [PATCH] tlv: remove unused error return value This commit also modifies a previous migration. Because the change is so limited, we don't consider this a significant risk. --- channeldb/migration_01_to_11/payments.go | 7 +------ channeldb/payments.go | 7 +------ lnrpc/routerrpc/router_backend.go | 11 ++--------- rpcserver.go | 8 +------- tlv/record.go | 4 ++-- tlv/record_test.go | 5 +---- 6 files changed, 8 insertions(+), 34 deletions(-) diff --git a/channeldb/migration_01_to_11/payments.go b/channeldb/migration_01_to_11/payments.go index d34cd6e9..1195ca82 100644 --- a/channeldb/migration_01_to_11/payments.go +++ b/channeldb/migration_01_to_11/payments.go @@ -562,12 +562,7 @@ func deserializeHop(r io.Reader) (*route.Hop, error) { tlvMap[tlvType] = rawRecordBytes } - tlvRecords, err := tlv.MapToRecords(tlvMap) - if err != nil { - return nil, err - } - - h.TLVRecords = tlvRecords + h.TLVRecords = tlv.MapToRecords(tlvMap) return h, nil } diff --git a/channeldb/payments.go b/channeldb/payments.go index ca9cf42f..3d8c6e34 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -710,12 +710,7 @@ func deserializeHop(r io.Reader) (*route.Hop, error) { h.MPP = mpp } - tlvRecords, err := tlv.MapToRecords(tlvMap) - if err != nil { - return nil, err - } - - h.TLVRecords = tlvRecords + h.TLVRecords = tlv.MapToRecords(tlvMap) return h, nil } diff --git a/lnrpc/routerrpc/router_backend.go b/lnrpc/routerrpc/router_backend.go index af1cb9fa..0ef7fe2a 100644 --- a/lnrpc/routerrpc/router_backend.go +++ b/lnrpc/routerrpc/router_backend.go @@ -233,10 +233,7 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context, // If we have any TLV records destined for the final hop, then we'll // attempt to decode them now into a form that the router can more // easily manipulate. - destTlvRecords, err := tlv.MapToRecords(destTLV) - if err != nil { - return nil, err - } + destTlvRecords := tlv.MapToRecords(destTLV) // Query the channel router for a possible path to the destination that // can carry `in.Amt` satoshis _including_ the total fee required on @@ -533,11 +530,7 @@ func (r *RouterBackend) extractIntentFromSendRequest( var destTLV map[uint64][]byte if len(destTLV) != 0 { - var err error - payIntent.FinalDestRecords, err = tlv.MapToRecords(destTLV) - if err != nil { - return nil, err - } + payIntent.FinalDestRecords = tlv.MapToRecords(destTLV) } payIntent.PayAttemptTimeout = time.Second * diff --git a/rpcserver.go b/rpcserver.go index 63d9d8f5..fcbe89bc 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3134,13 +3134,7 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme payIntent.cltvLimit = cltvLimit if len(rpcPayReq.DestTlv) != 0 { - var err error - payIntent.destTLV, err = tlv.MapToRecords( - rpcPayReq.DestTlv, - ) - if err != nil { - return payIntent, err - } + payIntent.destTLV = tlv.MapToRecords(rpcPayReq.DestTlv) } validateDest := func(dest route.Vertex) error { diff --git a/tlv/record.go b/tlv/record.go index b9e7980d..6159412c 100644 --- a/tlv/record.go +++ b/tlv/record.go @@ -219,7 +219,7 @@ func StubEncoder(v []byte) Encoder { // MapToRecords encodes the passed TLV map as a series of regular tlv.Record // instances. The resulting set of records will be returned in sorted order by // their type. -func MapToRecords(tlvMap map[uint64][]byte) ([]Record, error) { +func MapToRecords(tlvMap map[uint64][]byte) []Record { records := make([]Record, 0, len(tlvMap)) for k, v := range tlvMap { // We don't pass in a decoder here since we don't actually know @@ -234,7 +234,7 @@ func MapToRecords(tlvMap map[uint64][]byte) ([]Record, error) { SortRecords(records) - return records, nil + return records } // SortRecords is a helper function that will sort a slice of records in place diff --git a/tlv/record_test.go b/tlv/record_test.go index 02d2e893..d1f14501 100644 --- a/tlv/record_test.go +++ b/tlv/record_test.go @@ -114,10 +114,7 @@ func TestRecordMapTransformation(t *testing.T) { spew.Sdump(mappedRecords)) } - unmappedRecords, err := MapToRecords(mappedRecords) - if err != nil { - t.Fatalf("#%v: unable to unmap records: %v", i, err) - } + unmappedRecords := MapToRecords(mappedRecords) for i := 0; i < len(testCase.records); i++ { if unmappedRecords[i].Type() != testCase.records[i].Type() {