From 2a36e17f6f690060404a237514d885fb0297c9be Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 27 May 2025 08:21:11 +0200 Subject: [PATCH] graph/db: only init extra byte if not nil In preparation for having consistency with the structs created by the SQLStore and the KVStore (so that they have the same behaviour when tested by the unit tests), here we make sure not to init the ExtraOpaqueData field of the LightningNode struct unless there are actualy bytes to set. --- graph/db/graph_test.go | 1 - graph/db/kv_store.go | 6 +++++- graph/db/sql_store.go | 7 +++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index aae7e5a7e..e644fea19 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -82,7 +82,6 @@ func createLightningNode(priv *btcec.PrivateKey) *models.LightningNode { Alias: "kek" + hex.EncodeToString(pub), Features: testFeatures, Addresses: testAddrs, - ExtraOpaqueData: make([]byte, 0), } copy(n.PubKeyBytes[:], priv.PubKey().SerializeCompressed()) diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index 187fc13af..b08c86022 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -4122,7 +4122,7 @@ func deserializeLightningNode(r io.Reader) (models.LightningNode, error) { // We'll try and see if there are any opaque bytes left, if not, then // we'll ignore the EOF error and return the node as is. - node.ExtraOpaqueData, err = wire.ReadVarBytes( + extraBytes, err := wire.ReadVarBytes( r, 0, MaxAllowedExtraOpaqueBytes, "blob", ) switch { @@ -4132,6 +4132,10 @@ func deserializeLightningNode(r io.Reader) (models.LightningNode, error) { return models.LightningNode{}, err } + if len(extraBytes) > 0 { + node.ExtraOpaqueData = extraBytes + } + return node, nil } diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index 66a59af80..1ca00442a 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -494,10 +494,9 @@ func buildNode(ctx context.Context, db SQLQueries, dbNode *sqlc.Node) ( copy(pub[:], dbNode.PubKey) node := &models.LightningNode{ - PubKeyBytes: pub, - Features: lnwire.EmptyFeatureVector(), - LastUpdate: time.Unix(0, 0), - ExtraOpaqueData: make([]byte, 0), + PubKeyBytes: pub, + Features: lnwire.EmptyFeatureVector(), + LastUpdate: time.Unix(0, 0), } if len(dbNode.Signature) == 0 {