mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-06 21:20:32 +02:00
graph/db: fix linter issues of old code
Since we have renamed a file housing some very old code, the linter has now run on all this code for the first time. So we gotta do some clean-up work here to make it happy.
This commit is contained in:
parent
1ee4bb8c51
commit
ae3961b47f
@ -321,6 +321,8 @@ The underlying functionality between those two options remain the same.
|
|||||||
- [Abstract autopilot access](https://github.com/lightningnetwork/lnd/pull/9480)
|
- [Abstract autopilot access](https://github.com/lightningnetwork/lnd/pull/9480)
|
||||||
- [Abstract invoicerpc server access](https://github.com/lightningnetwork/lnd/pull/9516)
|
- [Abstract invoicerpc server access](https://github.com/lightningnetwork/lnd/pull/9516)
|
||||||
- [Refactor to hide DB transactions](https://github.com/lightningnetwork/lnd/pull/9513)
|
- [Refactor to hide DB transactions](https://github.com/lightningnetwork/lnd/pull/9513)
|
||||||
|
- Move the graph cache out of the graph CRUD layer:
|
||||||
|
- [1](https://github.com/lightningnetwork/lnd/pull/9533)
|
||||||
|
|
||||||
* [Golang was updated to
|
* [Golang was updated to
|
||||||
`v1.22.11`](https://github.com/lightningnetwork/lnd/pull/9462).
|
`v1.22.11`](https://github.com/lightningnetwork/lnd/pull/9462).
|
||||||
|
@ -132,8 +132,8 @@ var (
|
|||||||
//
|
//
|
||||||
// The chanID represents the channel ID of the edge and the direction is
|
// The chanID represents the channel ID of the edge and the direction is
|
||||||
// one byte representing the direction of the edge. The main purpose of
|
// one byte representing the direction of the edge. The main purpose of
|
||||||
// this index is to allow pruning disabled channels in a fast way without
|
// this index is to allow pruning disabled channels in a fast way
|
||||||
// the need to iterate all over the graph.
|
// without the need to iterate all over the graph.
|
||||||
disabledEdgePolicyBucket = []byte("disabled-edge-policy-index")
|
disabledEdgePolicyBucket = []byte("disabled-edge-policy-index")
|
||||||
|
|
||||||
// graphMetaBucket is a top-level bucket which stores various meta-deta
|
// graphMetaBucket is a top-level bucket which stores various meta-deta
|
||||||
@ -308,7 +308,7 @@ func (c *KVStore) getChannelMap(edges kvdb.RBucket) (
|
|||||||
switch {
|
switch {
|
||||||
// If the db policy was missing an expected optional field, we
|
// If the db policy was missing an expected optional field, we
|
||||||
// return nil as if the policy was unknown.
|
// return nil as if the policy was unknown.
|
||||||
case err == ErrEdgePolicyOptionalFieldNotFound:
|
case errors.Is(err, ErrEdgePolicyOptionalFieldNotFound):
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case err != nil:
|
case err != nil:
|
||||||
@ -340,10 +340,13 @@ func (c *KVStore) Wipe() error {
|
|||||||
err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||||
for _, tlb := range graphTopLevelBuckets {
|
for _, tlb := range graphTopLevelBuckets {
|
||||||
err := tx.DeleteTopLevelBucket(tlb)
|
err := tx.DeleteTopLevelBucket(tlb)
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
if err != nil &&
|
||||||
|
!errors.Is(err, kvdb.ErrBucketNotFound) {
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {})
|
}, func() {})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -395,6 +398,7 @@ func initKVStore(db kvdb.Backend) error {
|
|||||||
|
|
||||||
graphMeta := tx.ReadWriteBucket(graphMetaBucket)
|
graphMeta := tx.ReadWriteBucket(graphMetaBucket)
|
||||||
_, err = graphMeta.CreateBucketIfNotExists(pruneLogBucket)
|
_, err = graphMeta.CreateBucketIfNotExists(pruneLogBucket)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}, func() {})
|
}, func() {})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -550,6 +554,7 @@ func (c *KVStore) forEachNodeDirectedChannel(tx kvdb.RTx,
|
|||||||
|
|
||||||
return cb(directedChannel)
|
return cb(directedChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeTraversal(tx, node[:], c.db, dbCallback)
|
return nodeTraversal(tx, node[:], c.db, dbCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,14 +570,14 @@ func (c *KVStore) fetchNodeFeatures(tx kvdb.RTx,
|
|||||||
|
|
||||||
// Fallback that uses the database.
|
// Fallback that uses the database.
|
||||||
targetNode, err := c.FetchLightningNodeTx(tx, node)
|
targetNode, err := c.FetchLightningNodeTx(tx, node)
|
||||||
switch err {
|
switch {
|
||||||
// If the node exists and has features, return them directly.
|
// If the node exists and has features, return them directly.
|
||||||
case nil:
|
case err == nil:
|
||||||
return targetNode.Features, nil
|
return targetNode.Features, nil
|
||||||
|
|
||||||
// If we couldn't find a node announcement, populate a blank feature
|
// If we couldn't find a node announcement, populate a blank feature
|
||||||
// vector.
|
// vector.
|
||||||
case ErrGraphNodeNotFound:
|
case errors.Is(err, ErrGraphNodeNotFound):
|
||||||
return lnwire.EmptyFeatureVector(), nil
|
return lnwire.EmptyFeatureVector(), nil
|
||||||
|
|
||||||
// Otherwise, bubble the error up.
|
// Otherwise, bubble the error up.
|
||||||
@ -915,7 +920,7 @@ func (c *KVStore) SetSourceNode(node *models.LightningNode) error {
|
|||||||
// already present node from a node announcement, or to insert a node found in a
|
// already present node from a node announcement, or to insert a node found in a
|
||||||
// channel update.
|
// channel update.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): also need sig of announcement
|
// TODO(roasbeef): also need sig of announcement.
|
||||||
func (c *KVStore) AddLightningNode(node *models.LightningNode,
|
func (c *KVStore) AddLightningNode(node *models.LightningNode,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
@ -984,6 +989,7 @@ func (c *KVStore) LookupAlias(pub *btcec.PublicKey) (string, error) {
|
|||||||
// TODO(roasbeef): should actually be using the utf-8
|
// TODO(roasbeef): should actually be using the utf-8
|
||||||
// package...
|
// package...
|
||||||
alias = string(a)
|
alias = string(a)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {
|
}, func() {
|
||||||
alias = ""
|
alias = ""
|
||||||
@ -1076,7 +1082,7 @@ func (c *KVStore) AddChannelEdge(edge *models.ChannelEdgeInfo,
|
|||||||
|
|
||||||
// Silence ErrEdgeAlreadyExist so that the batch can
|
// Silence ErrEdgeAlreadyExist so that the batch can
|
||||||
// succeed, but propagate the error via local state.
|
// succeed, but propagate the error via local state.
|
||||||
if err == ErrEdgeAlreadyExist {
|
if errors.Is(err, ErrEdgeAlreadyExist) {
|
||||||
alreadyExists = true
|
alreadyExists = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -1150,7 +1156,7 @@ func (c *KVStore) addChannelEdge(tx kvdb.RwTx,
|
|||||||
// public key, so subsequent validation and queries can work properly.
|
// public key, so subsequent validation and queries can work properly.
|
||||||
_, node1Err := fetchLightningNode(nodes, edge.NodeKey1Bytes[:])
|
_, node1Err := fetchLightningNode(nodes, edge.NodeKey1Bytes[:])
|
||||||
switch {
|
switch {
|
||||||
case node1Err == ErrGraphNodeNotFound:
|
case errors.Is(node1Err, ErrGraphNodeNotFound):
|
||||||
node1Shell := models.LightningNode{
|
node1Shell := models.LightningNode{
|
||||||
PubKeyBytes: edge.NodeKey1Bytes,
|
PubKeyBytes: edge.NodeKey1Bytes,
|
||||||
HaveNodeAnnouncement: false,
|
HaveNodeAnnouncement: false,
|
||||||
@ -1166,7 +1172,7 @@ func (c *KVStore) addChannelEdge(tx kvdb.RwTx,
|
|||||||
|
|
||||||
_, node2Err := fetchLightningNode(nodes, edge.NodeKey2Bytes[:])
|
_, node2Err := fetchLightningNode(nodes, edge.NodeKey2Bytes[:])
|
||||||
switch {
|
switch {
|
||||||
case node2Err == ErrGraphNodeNotFound:
|
case errors.Is(node2Err, ErrGraphNodeNotFound):
|
||||||
node2Shell := models.LightningNode{
|
node2Shell := models.LightningNode{
|
||||||
PubKeyBytes: edge.NodeKey2Bytes,
|
PubKeyBytes: edge.NodeKey2Bytes,
|
||||||
HaveNodeAnnouncement: false,
|
HaveNodeAnnouncement: false,
|
||||||
@ -1206,6 +1212,7 @@ func (c *KVStore) addChannelEdge(tx kvdb.RwTx,
|
|||||||
if err := WriteOutpoint(&b, &edge.ChannelPoint); err != nil {
|
if err := WriteOutpoint(&b, &edge.ChannelPoint); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return chanIndex.Put(b.Bytes(), chanKey[:])
|
return chanIndex.Put(b.Bytes(), chanKey[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1233,6 +1240,7 @@ func (c *KVStore) HasChannelEdge(
|
|||||||
upd1Time = time.Unix(entry.upd1Time, 0)
|
upd1Time = time.Unix(entry.upd1Time, 0)
|
||||||
upd2Time = time.Unix(entry.upd2Time, 0)
|
upd2Time = time.Unix(entry.upd2Time, 0)
|
||||||
exists, isZombie = entry.flags.unpack()
|
exists, isZombie = entry.flags.unpack()
|
||||||
|
|
||||||
return upd1Time, upd2Time, exists, isZombie, nil
|
return upd1Time, upd2Time, exists, isZombie, nil
|
||||||
}
|
}
|
||||||
c.cacheMu.RUnlock()
|
c.cacheMu.RUnlock()
|
||||||
@ -1247,6 +1255,7 @@ func (c *KVStore) HasChannelEdge(
|
|||||||
upd1Time = time.Unix(entry.upd1Time, 0)
|
upd1Time = time.Unix(entry.upd1Time, 0)
|
||||||
upd2Time = time.Unix(entry.upd2Time, 0)
|
upd2Time = time.Unix(entry.upd2Time, 0)
|
||||||
exists, isZombie = entry.flags.unpack()
|
exists, isZombie = entry.flags.unpack()
|
||||||
|
|
||||||
return upd1Time, upd2Time, exists, isZombie, nil
|
return upd1Time, upd2Time, exists, isZombie, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1791,8 +1800,8 @@ func (c *KVStore) PruneTip() (*chainhash.Hash, uint32, error) {
|
|||||||
|
|
||||||
// Once we have the prune tip, the value will be the block hash,
|
// Once we have the prune tip, the value will be the block hash,
|
||||||
// and the key the block height.
|
// and the key the block height.
|
||||||
copy(tipHash[:], v[:])
|
copy(tipHash[:], v)
|
||||||
tipHeight = byteOrder.Uint32(k[:])
|
tipHeight = byteOrder.Uint32(k)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {})
|
}, func() {})
|
||||||
@ -1946,11 +1955,12 @@ func (c *KVStore) HighestChanID() (uint64, error) {
|
|||||||
// Otherwise, we'll de serialize the channel ID and return it
|
// Otherwise, we'll de serialize the channel ID and return it
|
||||||
// to the caller.
|
// to the caller.
|
||||||
cid = byteOrder.Uint64(lastChanID)
|
cid = byteOrder.Uint64(lastChanID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {
|
}, func() {
|
||||||
cid = 0
|
cid = 0
|
||||||
})
|
})
|
||||||
if err != nil && err != ErrGraphNoEdgesFound {
|
if err != nil && !errors.Is(err, ErrGraphNoEdgesFound) {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2035,7 +2045,6 @@ func (c *KVStore) ChanUpdatesInHorizon(startTime,
|
|||||||
//nolint:ll
|
//nolint:ll
|
||||||
for indexKey, _ := updateCursor.Seek(startTimeBytes[:]); indexKey != nil &&
|
for indexKey, _ := updateCursor.Seek(startTimeBytes[:]); indexKey != nil &&
|
||||||
bytes.Compare(indexKey, endTimeBytes[:]) <= 0; indexKey, _ = updateCursor.Next() {
|
bytes.Compare(indexKey, endTimeBytes[:]) <= 0; indexKey, _ = updateCursor.Next() {
|
||||||
|
|
||||||
// We have a new eligible entry, so we'll slice of the
|
// We have a new eligible entry, so we'll slice of the
|
||||||
// chan ID so we can query it in the DB.
|
// chan ID so we can query it in the DB.
|
||||||
chanID := indexKey[8:]
|
chanID := indexKey[8:]
|
||||||
@ -2052,6 +2061,7 @@ func (c *KVStore) ChanUpdatesInHorizon(startTime,
|
|||||||
hits++
|
hits++
|
||||||
edgesSeen[chanIDInt] = struct{}{}
|
edgesSeen[chanIDInt] = struct{}{}
|
||||||
edgesInHorizon = append(edgesInHorizon, channel)
|
edgesInHorizon = append(edgesInHorizon, channel)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2110,9 +2120,9 @@ func (c *KVStore) ChanUpdatesInHorizon(startTime,
|
|||||||
edgesInHorizon = nil
|
edgesInHorizon = nil
|
||||||
})
|
})
|
||||||
switch {
|
switch {
|
||||||
case err == ErrGraphNoEdgesFound:
|
case errors.Is(err, ErrGraphNoEdgesFound):
|
||||||
fallthrough
|
fallthrough
|
||||||
case err == ErrGraphNodesNotFound:
|
case errors.Is(err, ErrGraphNodesNotFound):
|
||||||
break
|
break
|
||||||
|
|
||||||
case err != nil:
|
case err != nil:
|
||||||
@ -2170,7 +2180,6 @@ func (c *KVStore) NodeUpdatesInHorizon(startTime,
|
|||||||
//nolint:ll
|
//nolint:ll
|
||||||
for indexKey, _ := updateCursor.Seek(startTimeBytes[:]); indexKey != nil &&
|
for indexKey, _ := updateCursor.Seek(startTimeBytes[:]); indexKey != nil &&
|
||||||
bytes.Compare(indexKey, endTimeBytes[:]) <= 0; indexKey, _ = updateCursor.Next() {
|
bytes.Compare(indexKey, endTimeBytes[:]) <= 0; indexKey, _ = updateCursor.Next() {
|
||||||
|
|
||||||
nodePub := indexKey[8:]
|
nodePub := indexKey[8:]
|
||||||
node, err := fetchLightningNode(nodes, nodePub)
|
node, err := fetchLightningNode(nodes, nodePub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2185,9 +2194,9 @@ func (c *KVStore) NodeUpdatesInHorizon(startTime,
|
|||||||
nodesInHorizon = nil
|
nodesInHorizon = nil
|
||||||
})
|
})
|
||||||
switch {
|
switch {
|
||||||
case err == ErrGraphNoEdgesFound:
|
case errors.Is(err, ErrGraphNoEdgesFound):
|
||||||
fallthrough
|
fallthrough
|
||||||
case err == ErrGraphNodesNotFound:
|
case errors.Is(err, ErrGraphNodesNotFound):
|
||||||
break
|
break
|
||||||
|
|
||||||
case err != nil:
|
case err != nil:
|
||||||
@ -2294,7 +2303,7 @@ func (c *KVStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
|
|||||||
switch {
|
switch {
|
||||||
// If we don't know of any edges yet, then we'll return the entire set
|
// If we don't know of any edges yet, then we'll return the entire set
|
||||||
// of chan IDs specified.
|
// of chan IDs specified.
|
||||||
case err == ErrGraphNoEdgesFound:
|
case errors.Is(err, ErrGraphNoEdgesFound):
|
||||||
ogChanIDs := make([]uint64, len(chansInfo))
|
ogChanIDs := make([]uint64, len(chansInfo))
|
||||||
for i, info := range chansInfo {
|
for i, info := range chansInfo {
|
||||||
ogChanIDs[i] = info.ShortChannelID.ToUint64()
|
ogChanIDs[i] = info.ShortChannelID.ToUint64()
|
||||||
@ -2482,7 +2491,7 @@ func (c *KVStore) FilterChannelRange(startHeight,
|
|||||||
switch {
|
switch {
|
||||||
// If we don't know of any channels yet, then there's nothing to
|
// If we don't know of any channels yet, then there's nothing to
|
||||||
// filter, so we'll return an empty slice.
|
// filter, so we'll return an empty slice.
|
||||||
case err == ErrGraphNoEdgesFound || len(channelsPerBlock) == 0:
|
case errors.Is(err, ErrGraphNoEdgesFound) || len(channelsPerBlock) == 0:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
||||||
case err != nil:
|
case err != nil:
|
||||||
@ -2596,6 +2605,7 @@ func (c *KVStore) fetchChanInfos(tx kvdb.RTx, chanIDs []uint64) (
|
|||||||
Node2: &node2,
|
Node2: &node2,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2990,7 +3000,7 @@ func (c *KVStore) isPublic(tx kvdb.RTx, nodePub route.Vertex,
|
|||||||
// Otherwise, we'll continue our search.
|
// Otherwise, we'll continue our search.
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil && err != errDone {
|
if err != nil && !errors.Is(err, errDone) {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3113,6 +3123,7 @@ func (c *KVStore) HasLightningNode(nodePub [33]byte) (time.Time, bool,
|
|||||||
|
|
||||||
exists = true
|
exists = true
|
||||||
updateTime = node.LastUpdate
|
updateTime = node.LastUpdate
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {
|
}, func() {
|
||||||
updateTime = time.Time{}
|
updateTime = time.Time{}
|
||||||
@ -3382,6 +3393,7 @@ func (c *KVStore) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
|
|||||||
|
|
||||||
policy1 = e1
|
policy1 = e1
|
||||||
policy2 = e2
|
policy2 = e2
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {
|
}, func() {
|
||||||
edgeInfo = nil
|
edgeInfo = nil
|
||||||
@ -3466,6 +3478,7 @@ func (c *KVStore) FetchChannelEdgesByID(chanID uint64) (
|
|||||||
NodeKey1Bytes: pubKey1,
|
NodeKey1Bytes: pubKey1,
|
||||||
NodeKey2Bytes: pubKey2,
|
NodeKey2Bytes: pubKey2,
|
||||||
}
|
}
|
||||||
|
|
||||||
return ErrZombieEdge
|
return ErrZombieEdge
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3487,13 +3500,14 @@ func (c *KVStore) FetchChannelEdgesByID(chanID uint64) (
|
|||||||
|
|
||||||
policy1 = e1
|
policy1 = e1
|
||||||
policy2 = e2
|
policy2 = e2
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {
|
}, func() {
|
||||||
edgeInfo = nil
|
edgeInfo = nil
|
||||||
policy1 = nil
|
policy1 = nil
|
||||||
policy2 = nil
|
policy2 = nil
|
||||||
})
|
})
|
||||||
if err == ErrZombieEdge {
|
if errors.Is(err, ErrZombieEdge) {
|
||||||
return edgeInfo, nil, nil, err
|
return edgeInfo, nil, nil, err
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -3523,6 +3537,7 @@ func (c *KVStore) IsPublicNode(pubKey [33]byte) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nodeIsPublic, err = c.isPublic(tx, node.PubKeyBytes, ourPubKey)
|
nodeIsPublic, err = c.isPublic(tx, node.PubKeyBytes, ourPubKey)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}, func() {
|
}, func() {
|
||||||
nodeIsPublic = false
|
nodeIsPublic = false
|
||||||
@ -3783,6 +3798,7 @@ func (c *KVStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isZombie, pubKey1, pubKey2 = isZombieEdge(zombieIndex, chanID)
|
isZombie, pubKey1, pubKey2 = isZombieEdge(zombieIndex, chanID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {
|
}, func() {
|
||||||
isZombie = false
|
isZombie = false
|
||||||
@ -3936,8 +3952,8 @@ func (c *nodeTraverserSession) FetchNodeFeatures(nodePub route.Vertex) (
|
|||||||
return c.db.fetchNodeFeatures(c.tx, nodePub)
|
return c.db.fetchNodeFeatures(c.tx, nodePub)
|
||||||
}
|
}
|
||||||
|
|
||||||
func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket, // nolint:dupl
|
func putLightningNode(nodeBucket, aliasBucket, updateIndex kvdb.RwBucket,
|
||||||
updateIndex kvdb.RwBucket, node *models.LightningNode) error {
|
node *models.LightningNode) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
scratch [16]byte
|
scratch [16]byte
|
||||||
@ -4074,6 +4090,7 @@ func fetchLightningNode(nodeBucket kvdb.RBucket,
|
|||||||
}
|
}
|
||||||
|
|
||||||
nodeReader := bytes.NewReader(nodeBytes)
|
nodeReader := bytes.NewReader(nodeBytes)
|
||||||
|
|
||||||
return deserializeLightningNode(nodeReader)
|
return deserializeLightningNode(nodeReader)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4219,8 +4236,8 @@ func deserializeLightningNode(r io.Reader) (models.LightningNode, error) {
|
|||||||
r, 0, MaxAllowedExtraOpaqueBytes, "blob",
|
r, 0, MaxAllowedExtraOpaqueBytes, "blob",
|
||||||
)
|
)
|
||||||
switch {
|
switch {
|
||||||
case err == io.ErrUnexpectedEOF:
|
case errors.Is(err, io.ErrUnexpectedEOF):
|
||||||
case err == io.EOF:
|
case errors.Is(err, io.EOF):
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return models.LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
@ -4306,6 +4323,7 @@ func fetchChanEdgeInfo(edgeIndex kvdb.RBucket,
|
|||||||
}
|
}
|
||||||
|
|
||||||
edgeInfoReader := bytes.NewReader(edgeInfoBytes)
|
edgeInfoReader := bytes.NewReader(edgeInfoBytes)
|
||||||
|
|
||||||
return deserializeChanEdgeInfo(edgeInfoReader)
|
return deserializeChanEdgeInfo(edgeInfoReader)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4377,8 +4395,8 @@ func deserializeChanEdgeInfo(r io.Reader) (models.ChannelEdgeInfo, error) {
|
|||||||
r, 0, MaxAllowedExtraOpaqueBytes, "blob",
|
r, 0, MaxAllowedExtraOpaqueBytes, "blob",
|
||||||
)
|
)
|
||||||
switch {
|
switch {
|
||||||
case err == io.ErrUnexpectedEOF:
|
case errors.Is(err, io.ErrUnexpectedEOF):
|
||||||
case err == io.EOF:
|
case errors.Is(err, io.EOF):
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return models.ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
@ -4415,7 +4433,7 @@ func putChanEdgePolicy(edges kvdb.RwBucket, edge *models.ChannelEdgePolicy,
|
|||||||
// An unknown policy value does not have a update time recorded, so
|
// An unknown policy value does not have a update time recorded, so
|
||||||
// it also does not need to be removed.
|
// it also does not need to be removed.
|
||||||
if edgeBytes := edges.Get(edgeKey[:]); edgeBytes != nil &&
|
if edgeBytes := edges.Get(edgeKey[:]); edgeBytes != nil &&
|
||||||
!bytes.Equal(edgeBytes[:], unknownPolicy) {
|
!bytes.Equal(edgeBytes, unknownPolicy) {
|
||||||
|
|
||||||
// In order to delete the old entry, we'll need to obtain the
|
// In order to delete the old entry, we'll need to obtain the
|
||||||
// *prior* update time in order to delete it. To do this, we'll
|
// *prior* update time in order to delete it. To do this, we'll
|
||||||
@ -4429,7 +4447,9 @@ func putChanEdgePolicy(edges kvdb.RwBucket, edge *models.ChannelEdgePolicy,
|
|||||||
oldEdgePolicy, err := deserializeChanEdgePolicy(
|
oldEdgePolicy, err := deserializeChanEdgePolicy(
|
||||||
bytes.NewReader(edgeBytes),
|
bytes.NewReader(edgeBytes),
|
||||||
)
|
)
|
||||||
if err != nil && err != ErrEdgePolicyOptionalFieldNotFound {
|
if err != nil &&
|
||||||
|
!errors.Is(err, ErrEdgePolicyOptionalFieldNotFound) {
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4457,7 +4477,7 @@ func putChanEdgePolicy(edges kvdb.RwBucket, edge *models.ChannelEdgePolicy,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return edges.Put(edgeKey[:], b.Bytes()[:])
|
return edges.Put(edgeKey[:], b.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateEdgePolicyDisabledIndex is used to update the disabledEdgePolicyIndex
|
// updateEdgePolicyDisabledIndex is used to update the disabledEdgePolicyIndex
|
||||||
@ -4514,7 +4534,7 @@ func fetchChanEdgePolicy(edges kvdb.RBucket, chanID []byte,
|
|||||||
|
|
||||||
var edgeKey [33 + 8]byte
|
var edgeKey [33 + 8]byte
|
||||||
copy(edgeKey[:], nodePub)
|
copy(edgeKey[:], nodePub)
|
||||||
copy(edgeKey[33:], chanID[:])
|
copy(edgeKey[33:], chanID)
|
||||||
|
|
||||||
edgeBytes := edges.Get(edgeKey[:])
|
edgeBytes := edges.Get(edgeKey[:])
|
||||||
if edgeBytes == nil {
|
if edgeBytes == nil {
|
||||||
@ -4522,7 +4542,7 @@ func fetchChanEdgePolicy(edges kvdb.RBucket, chanID []byte,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No need to deserialize unknown policy.
|
// No need to deserialize unknown policy.
|
||||||
if bytes.Equal(edgeBytes[:], unknownPolicy) {
|
if bytes.Equal(edgeBytes, unknownPolicy) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4532,7 +4552,7 @@ func fetchChanEdgePolicy(edges kvdb.RBucket, chanID []byte,
|
|||||||
switch {
|
switch {
|
||||||
// If the db policy was missing an expected optional field, we return
|
// If the db policy was missing an expected optional field, we return
|
||||||
// nil as if the policy was unknown.
|
// nil as if the policy was unknown.
|
||||||
case err == ErrEdgePolicyOptionalFieldNotFound:
|
case errors.Is(err, ErrEdgePolicyOptionalFieldNotFound):
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
||||||
case err != nil:
|
case err != nil:
|
||||||
@ -4642,6 +4662,7 @@ func serializeChanEdgePolicy(w io.Writer, edge *models.ChannelEdgePolicy,
|
|||||||
if err := wire.WriteVarBytes(w, 0, opaqueBuf.Bytes()); err != nil {
|
if err := wire.WriteVarBytes(w, 0, opaqueBuf.Bytes()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4650,7 +4671,7 @@ func deserializeChanEdgePolicy(r io.Reader) (*models.ChannelEdgePolicy, error) {
|
|||||||
// found, both an error and a populated policy object are returned.
|
// found, both an error and a populated policy object are returned.
|
||||||
edge, deserializeErr := deserializeChanEdgePolicyRaw(r)
|
edge, deserializeErr := deserializeChanEdgePolicyRaw(r)
|
||||||
if deserializeErr != nil &&
|
if deserializeErr != nil &&
|
||||||
deserializeErr != ErrEdgePolicyOptionalFieldNotFound {
|
!errors.Is(deserializeErr, ErrEdgePolicyOptionalFieldNotFound) {
|
||||||
|
|
||||||
return nil, deserializeErr
|
return nil, deserializeErr
|
||||||
}
|
}
|
||||||
@ -4716,8 +4737,8 @@ func deserializeChanEdgePolicyRaw(r io.Reader) (*models.ChannelEdgePolicy,
|
|||||||
r, 0, MaxAllowedExtraOpaqueBytes, "blob",
|
r, 0, MaxAllowedExtraOpaqueBytes, "blob",
|
||||||
)
|
)
|
||||||
switch {
|
switch {
|
||||||
case err == io.ErrUnexpectedEOF:
|
case errors.Is(err, io.ErrUnexpectedEOF):
|
||||||
case err == io.EOF:
|
case errors.Is(err, io.EOF):
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -4818,12 +4839,14 @@ func MakeTestGraph(t testing.TB, modifiers ...OptionModifier) (*ChannelGraph,
|
|||||||
backend, backendCleanup, err := kvdb.GetTestBackend(t.TempDir(), "cgr")
|
backend, backendCleanup, err := kvdb.GetTestBackend(t.TempDir(), "cgr")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
backendCleanup()
|
backendCleanup()
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
graph, err := NewChannelGraph(backend)
|
graph, err := NewChannelGraph(backend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
backendCleanup()
|
backendCleanup()
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user