lnd/graph
Olaoluwa Osuntokun fe486e13a9 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.

(cherry picked from commit 56a7f45b99)
2026-02-03 18:24:39 -08:00
..
db graphdb: fix backwards-compat for channel edge feature deserialization 2026-02-03 18:24:39 -08:00
testdata refactor: move various duties from ChannelRouter to graph.Builder 2024-07-15 15:56:33 +02:00
builder.go graph: fix log formatting 2025-10-06 10:59:39 +02:00
builder_test.go multi: rename AddLightningNode methods 2025-09-03 10:14:35 +02:00
errors.go multi: use the "errors" package everywhere 2025-06-30 09:46:55 +02:00
interfaces.go graph+discovery: update graph/db gossip backlog interfaces to use iter.Seq2 2025-09-26 17:01:11 -07:00
log.go multi: start updating various loggers to use the new v2 type 2024-10-22 17:03:55 +02:00
notifications_test.go multi: rename models.LightningNode to models.Node 2025-09-03 10:14:35 +02:00
setup_test.go refactor: move various duties from ChannelRouter to graph.Builder 2024-07-15 15:56:33 +02:00
stats.go graph: rename routerStats to builderStats 2025-02-07 13:01:39 +02:00