From 0162ee949c2ee527633ee5579cc79037dad5d13b Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 4 Jul 2025 13:51:22 +0200 Subject: [PATCH] graph/db: move TLV validation for KVStore Here, we move TLV validation for the KVStore out of `updateEdgePolicy` so that we can re-use `updateEdgePolicy` in our tests to write policies with invalid TLV (since that was possible before the recently added TLV sanity check) so that we can test that our SQL migration behaves correctly for these cases. --- graph/db/kv_store.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index 42b9f9245..8c5fcde9c 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -2844,7 +2844,17 @@ func (c *KVStore) UpdateEdgePolicy(ctx context.Context, edgeNotFound = false }, Do: func(tx kvdb.RwTx) error { - var err error + // Validate that the ExtraOpaqueData is in fact a valid + // TLV stream. This is done here instead of within + // updateEdgePolicy so that updateEdgePolicy can be used + // by unit tests to recreate the case where we already + // have nodes persisted with invalid TLV data. + err := edge.ExtraOpaqueData.ValidateTLV() + if err != nil { + return fmt.Errorf("%w: %w", + ErrParsingExtraTLVBytes, err) + } + from, to, isUpdate1, err = updateEdgePolicy(tx, edge) if err != nil { log.Errorf("UpdateEdgePolicy faild: %v", err) @@ -4703,12 +4713,6 @@ func serializeChanEdgePolicy(w io.Writer, edge *models.ChannelEdgePolicy, } } - // Validate that the ExtraOpaqueData is in fact a valid TLV stream. - err = edge.ExtraOpaqueData.ValidateTLV() - if err != nil { - return fmt.Errorf("%w: %w", ErrParsingExtraTLVBytes, err) - } - if len(edge.ExtraOpaqueData) > MaxAllowedExtraOpaqueBytes { return ErrTooManyExtraOpaqueBytes(len(edge.ExtraOpaqueData)) }