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.
This commit is contained in:
3 files changed
+8
-6
No files matched your search
@@ -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())
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user