mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
channeldb: optimise FetchChannel method
This commit adds a small optimisation to the FetchChannel method. Instead of iterating over each channel bucket, an identifiable error is thrown once the wanted channel is found so that the iteration can stop early.
This commit is contained in:
parent
aebdd2375c
commit
908cb6060b
@ -661,6 +661,10 @@ func (c *ChannelStateDB) FetchChannel(tx kvdb.RTx, chanPoint wire.OutPoint) (
|
||||
var (
|
||||
targetChan *OpenChannel
|
||||
targetChanPoint bytes.Buffer
|
||||
|
||||
// errChanFound is used to signal that the channel has been
|
||||
// found so that iteration through the DB buckets can stop.
|
||||
errChanFound = errors.New("channel found")
|
||||
)
|
||||
|
||||
if err := writeOutpoint(&targetChanPoint, &chanPoint); err != nil {
|
||||
@ -739,7 +743,7 @@ func (c *ChannelStateDB) FetchChannel(tx kvdb.RTx, chanPoint wire.OutPoint) (
|
||||
targetChan = channel
|
||||
targetChan.Db = c
|
||||
|
||||
return nil
|
||||
return errChanFound
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -750,7 +754,7 @@ func (c *ChannelStateDB) FetchChannel(tx kvdb.RTx, chanPoint wire.OutPoint) (
|
||||
} else {
|
||||
err = chanScan(tx)
|
||||
}
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, errChanFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user