mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-31 10:10:31 +02:00
channeldb: make MarkEdgeLive logic reusable
This commit is a set-up commit. It extracts the logic from `MarkEdgeLive` to a helper `markEdgeLive` method so that the logic can be called from within other kvdb.Update blocks. This will be used in the next commit.
This commit is contained in:
parent
e12321cfd6
commit
ebe0755a97
@ -3580,10 +3580,17 @@ func markEdgeZombie(zombieIndex kvdb.RwBucket, chanID uint64, pubKey1,
|
||||
|
||||
// MarkEdgeLive clears an edge from our zombie index, deeming it as live.
|
||||
func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
|
||||
return c.markEdgeLive(nil, chanID)
|
||||
}
|
||||
|
||||
// markEdgeLive clears an edge from the zombie index. This method can be called
|
||||
// with an existing kvdb.RwTx or the argument can be set to nil in which case a
|
||||
// new transaction will be created.
|
||||
func (c *ChannelGraph) markEdgeLive(tx kvdb.RwTx, chanID uint64) error {
|
||||
c.cacheMu.Lock()
|
||||
defer c.cacheMu.Unlock()
|
||||
|
||||
err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||
dbFn := func(tx kvdb.RwTx) error {
|
||||
edges := tx.ReadWriteBucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
@ -3601,7 +3608,16 @@ func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
|
||||
}
|
||||
|
||||
return zombieIndex.Delete(k[:])
|
||||
}, func() {})
|
||||
}
|
||||
|
||||
// If the transaction is nil, we'll create a new one. Otherwise, we use
|
||||
// the existing transaction
|
||||
var err error
|
||||
if tx == nil {
|
||||
err = kvdb.Update(c.db, dbFn, func() {})
|
||||
} else {
|
||||
err = dbFn(tx)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -3611,11 +3627,12 @@ func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
|
||||
|
||||
// We need to add the channel back into our graph cache, otherwise we
|
||||
// won't use it for path finding.
|
||||
edgeInfos, err := c.FetchChanInfos([]uint64{chanID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c.graphCache != nil {
|
||||
edgeInfos, err := c.FetchChanInfos([]uint64{chanID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, edgeInfo := range edgeInfos {
|
||||
c.graphCache.AddChannel(
|
||||
edgeInfo.Info, edgeInfo.Policy1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user