refactor+multi: use *lnwire.FeatureVector for ChannelEdgeInfo features

In this commit, we move the serialisation details of a channel's
features to the DB layer and change the `models` field to instead use a
more useful `*lnwire.FeatureVector` type.

This makes the features easier to work with and moves the serialisation
to where it is actually used.
This commit is contained in:
Elle Mouton committed 2025-07-01 17:02:07 +02:00
1 parent d8a12a5e57
commit 2f2845dfc0
14 files changed
+70 -78

No files matched your search

+10 -25
View File
@@ -3833,26 +3833,16 @@ func insertChannel(ctx context.Context, db SQLQueries,
}
// Insert any channel features.
if len(edge.Features) != 0 {
chanFeatures := lnwire.NewRawFeatureVector()
err := chanFeatures.Decode(bytes.NewReader(edge.Features))
for feature := range edge.Features.Features() {
err = db.InsertChannelFeature(
ctx, sqlc.InsertChannelFeatureParams{
ChannelID: dbChanID,
FeatureBit: int32(feature),
},
)
if err != nil {
return nil, err
}
fv := lnwire.NewFeatureVector(chanFeatures, lnwire.Features)
for feature := range fv.Features() {
err = db.InsertChannelFeature(
ctx, sqlc.InsertChannelFeatureParams{
ChannelID: dbChanID,
FeatureBit: int32(feature),
},
)
if err != nil {
return nil, fmt.Errorf("unable to insert "+
"channel(%d) feature(%v): %w", dbChanID,
feature, err)
}
return nil, fmt.Errorf("unable to insert channel(%d) "+
"feature(%v): %w", dbChanID, feature, err)
}
}
@@ -3975,11 +3965,6 @@ func getAndBuildEdgeInfo(ctx context.Context, db SQLQueries,
return nil, err
}
var featureBuf bytes.Buffer
if err := fv.Encode(&featureBuf); err != nil {
return nil, fmt.Errorf("unable to encode features: %w", err)
}
recs, err := lnwire.CustomRecords(extras).Serialize()
if err != nil {
return nil, fmt.Errorf("unable to serialize extra signed "+
@@ -4002,7 +3987,7 @@ func getAndBuildEdgeInfo(ctx context.Context, db SQLQueries,
BitcoinKey2Bytes: btcKey2,
ChannelPoint: *op,
Capacity: btcutil.Amount(dbChan.Capacity.Int64),
Features: featureBuf.Bytes(),
Features: fv,
ExtraOpaqueData: recs,
}