lnd/graph/db
Olaoluwa Osuntokun 56a7f45b99 graphdb: fix backwards-compat for channel edge feature deserialization
This commit fixes a backwards compatibility issue that prevented nodes
from upgrading from v0.19.x to v0.20.x.

In v0.19.x, channel edge features were serialized as raw feature bytes
without a length prefix. In v0.20.x (commit 2f2845dfc), the serialization
changed to use Features.Encode() which adds a 2-byte big-endian length
prefix before the feature bits. The deserialization code was updated to
use Features.Decode() which expects this length prefix.

When v0.20.x reads a database created by v0.19.x, Decode() tries to read
a length prefix that doesn't exist, causing an EOF error:

    unable to decode features: EOF

The fix adds a deserializeChanEdgeFeatures() helper that detects which
format is being read and decodes accordingly:

- New format (v0.20+): First 2 bytes encode the length of the remaining
  bytes. Detected when uint16(bytes[0:2]) == len(bytes)-2.

- Legacy format (pre-v0.20): Raw feature bits without length prefix.
  Uses DecodeBase256 with the known length.

The format detection is safe because in the legacy format, the first byte
always has at least one bit set (the serialization uses minimum bytes),
so the first two bytes can never encode a value equal to len-2.

Fixes #10528.
2026-02-03 09:12:04 -08:00
..
migration1 graph/db: freeze sql migration queries 2025-11-12 22:54:06 +08:00
models graph/db/models: fix race conditions in ChannelEdgeInfo 2025-12-08 11:56:36 +02:00
addr.go graph/db+chanbackup: dns add encoding/decoding for persistence 2025-09-03 01:11:35 +00:00
addr_test.go graph/db+chanbackup: dns add encoding/decoding for persistence 2025-09-03 01:11:35 +00:00
benchmark_test.go graph/db: remove TestPopulateViaMigration 2025-11-12 22:54:05 +08:00
channel_cache.go refactor: move graph related DB code to graph/db from channeldb 2024-11-28 13:36:13 +02:00
channel_cache_test.go refactor: move graph related DB code to graph/db from channeldb 2024-11-28 13:36:13 +02:00
codec.go channeldb/graphdb: move outpoint ser/deser funcs to graphdb 2024-11-28 13:34:08 +02:00
errors.go graph/db: let IsZombieEdge return an error 2025-06-26 10:19:51 +02:00
graph.go graph/db: remove outdated comment 2025-11-12 22:54:05 +08:00
graph_cache.go graphdb: reduce log noise from WRN to DBG 2026-01-21 20:25:08 +01:00
graph_cache_test.go graph: add regression test for the fixed behaviour 2025-11-19 16:09:33 +01:00
graph_test.go graphdb: add benchmark for isPublicNode query 2025-12-23 21:04:36 +01:00
interfaces.go multi: add models.Node V1 constructor 2025-11-12 22:54:05 +08:00
kv_store.go graphdb: fix backwards-compat for channel edge feature deserialization 2026-02-03 09:12:04 -08:00
kv_store_features_test.go graphdb: fix backwards-compat for channel edge feature deserialization 2026-02-03 09:12:04 -08:00
log.go graph/db+log: use v2 logger for graph subsystem 2025-07-29 11:34:47 +02:00
notifications.go multi: add models.Node V1 constructor 2025-11-12 22:54:05 +08:00
options.go graph/db: add options infrastructure for iterator configuration 2025-09-26 16:56:20 -07:00
reject_cache.go refactor: move graph related DB code to graph/db from channeldb 2024-11-28 13:36:13 +02:00
reject_cache_test.go refactor: move graph related DB code to graph/db from channeldb 2024-11-28 13:36:13 +02:00
setup_test.go refactor: move graph related DB code to graph/db from channeldb 2024-11-28 13:36:13 +02:00
sql_store.go graphdb: fix potential sql tx exhaustion 2025-12-09 11:51:46 +01:00
test_kvdb.go graph/db: skip TestGraphLoading for non-bbolt store 2025-05-23 10:53:27 +02:00
test_postgres.go graph/db+sqldb: find best default query cfg values for sqlite & postgres 2025-08-13 14:43:31 +02:00
test_sqlite.go graph/db+sqldb: find best default query cfg values for sqlite & postgres 2025-08-13 14:43:31 +02:00