Skip to content

Commit 2a36e17

Browse files
committed
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.
1 parent e5d099e commit 2a36e17

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

graph/db/graph_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ func createLightningNode(priv *btcec.PrivateKey) *models.LightningNode {
8282
Alias: "kek" + hex.EncodeToString(pub),
8383
Features: testFeatures,
8484
Addresses: testAddrs,
85-
ExtraOpaqueData: make([]byte, 0),
8685
}
8786
copy(n.PubKeyBytes[:], priv.PubKey().SerializeCompressed())
8887

graph/db/kv_store.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4122,7 +4122,7 @@ func deserializeLightningNode(r io.Reader) (models.LightningNode, error) {
41224122

41234123
// We'll try and see if there are any opaque bytes left, if not, then
41244124
// we'll ignore the EOF error and return the node as is.
4125-
node.ExtraOpaqueData, err = wire.ReadVarBytes(
4125+
extraBytes, err := wire.ReadVarBytes(
41264126
r, 0, MaxAllowedExtraOpaqueBytes, "blob",
41274127
)
41284128
switch {
@@ -4132,6 +4132,10 @@ func deserializeLightningNode(r io.Reader) (models.LightningNode, error) {
41324132
return models.LightningNode{}, err
41334133
}
41344134

4135+
if len(extraBytes) > 0 {
4136+
node.ExtraOpaqueData = extraBytes
4137+
}
4138+
41354139
return node, nil
41364140
}
41374141

graph/db/sql_store.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,9 @@ func buildNode(ctx context.Context, db SQLQueries, dbNode *sqlc.Node) (
494494
copy(pub[:], dbNode.PubKey)
495495

496496
node := &models.LightningNode{
497-
PubKeyBytes: pub,
498-
Features: lnwire.EmptyFeatureVector(),
499-
LastUpdate: time.Unix(0, 0),
500-
ExtraOpaqueData: make([]byte, 0),
497+
PubKeyBytes: pub,
498+
Features: lnwire.EmptyFeatureVector(),
499+
LastUpdate: time.Unix(0, 0),
501500
}
502501

503502
if len(dbNode.Signature) == 0 {

0 commit comments

Comments
 (0)