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.
This commit is contained in:
Elle Mouton
2025-07-04 13:51:22 +02:00
parent 886ccd3f9b
commit 0162ee949c

View File

@@ -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))
}