mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-28 13:52:55 +02:00
Merge pull request #5642 from guggero/in-memory-graph
In-memory graph cache for faster pathfinding
This commit is contained in:
@@ -130,9 +130,18 @@ type Config struct {
|
||||
// subsystem.
|
||||
LocalChannelClose func(pubKey []byte, request *ChanClose)
|
||||
|
||||
// DB is the channeldb instance that will be used to back the switch's
|
||||
// DB is the database backend that will be used to back the switch's
|
||||
// persistent circuit map.
|
||||
DB *channeldb.DB
|
||||
DB kvdb.Backend
|
||||
|
||||
// FetchAllOpenChannels is a function that fetches all currently open
|
||||
// channels from the channel database.
|
||||
FetchAllOpenChannels func() ([]*channeldb.OpenChannel, error)
|
||||
|
||||
// FetchClosedChannels is a function that fetches all closed channels
|
||||
// from the channel database.
|
||||
FetchClosedChannels func(
|
||||
pendingOnly bool) ([]*channeldb.ChannelCloseSummary, error)
|
||||
|
||||
// SwitchPackager provides access to the forwarding packages of all
|
||||
// active channels. This gives the switch the ability to read arbitrary
|
||||
@@ -294,6 +303,8 @@ type Switch struct {
|
||||
func New(cfg Config, currentHeight uint32) (*Switch, error) {
|
||||
circuitMap, err := NewCircuitMap(&CircuitMapConfig{
|
||||
DB: cfg.DB,
|
||||
FetchAllOpenChannels: cfg.FetchAllOpenChannels,
|
||||
FetchClosedChannels: cfg.FetchClosedChannels,
|
||||
ExtractErrorEncrypter: cfg.ExtractErrorEncrypter,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -1455,7 +1466,7 @@ func (s *Switch) closeCircuit(pkt *htlcPacket) (*PaymentCircuit, error) {
|
||||
// we're the originator of the payment, so the link stops attempting to
|
||||
// re-broadcast.
|
||||
func (s *Switch) ackSettleFail(settleFailRefs ...channeldb.SettleFailRef) error {
|
||||
return kvdb.Batch(s.cfg.DB.Backend, func(tx kvdb.RwTx) error {
|
||||
return kvdb.Batch(s.cfg.DB, func(tx kvdb.RwTx) error {
|
||||
return s.cfg.SwitchPackager.AckSettleFails(tx, settleFailRefs...)
|
||||
})
|
||||
}
|
||||
@@ -1859,7 +1870,7 @@ func (s *Switch) Start() error {
|
||||
// forwarding packages and reforwards any Settle or Fail HTLCs found. This is
|
||||
// used to resurrect the switch's mailboxes after a restart.
|
||||
func (s *Switch) reforwardResponses() error {
|
||||
openChannels, err := s.cfg.DB.FetchAllOpenChannels()
|
||||
openChannels, err := s.cfg.FetchAllOpenChannels()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -2122,6 +2133,17 @@ func (s *Switch) getLink(chanID lnwire.ChannelID) (ChannelLink, error) {
|
||||
return link, nil
|
||||
}
|
||||
|
||||
// GetLinkByShortID attempts to return the link which possesses the target short
|
||||
// channel ID.
|
||||
func (s *Switch) GetLinkByShortID(chanID lnwire.ShortChannelID) (ChannelLink,
|
||||
error) {
|
||||
|
||||
s.indexMtx.RLock()
|
||||
defer s.indexMtx.RUnlock()
|
||||
|
||||
return s.getLinkByShortID(chanID)
|
||||
}
|
||||
|
||||
// getLinkByShortID attempts to return the link which possesses the target
|
||||
// short channel ID.
|
||||
//
|
||||
|
Reference in New Issue
Block a user