mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-30 07:58:15 +01:00
graph/db: batch loading for DisconnectBlockAtHeight
This commit is contained in:
@@ -2627,27 +2627,29 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) (
|
|||||||
return fmt.Errorf("unable to fetch channels: %w", err)
|
return fmt.Errorf("unable to fetch channels: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
chanIDsToDelete := make([]int64, len(rows))
|
if len(rows) == 0 {
|
||||||
for i, row := range rows {
|
// No channels to disconnect, but still clean up prune
|
||||||
node1, node2, err := buildNodeVertices(
|
// log.
|
||||||
row.Node1PubKey, row.Node2PubKey,
|
return db.DeletePruneLogEntriesInRange(
|
||||||
|
ctx, sqlc.DeletePruneLogEntriesInRangeParams{
|
||||||
|
StartHeight: int64(height),
|
||||||
|
EndHeight: int64(
|
||||||
|
endShortChanID.BlockHeight,
|
||||||
|
),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
channel, err := getAndBuildEdgeInfo(
|
|
||||||
ctx, db, s.cfg.ChainHash, row.GraphChannel,
|
|
||||||
node1, node2,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
chanIDsToDelete[i] = row.GraphChannel.ID
|
|
||||||
removedChans = append(removedChans, channel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Batch build all channel edges for disconnection.
|
||||||
|
channelEdges, chanIDsToDelete, err := batchBuildChannelInfo(
|
||||||
|
ctx, s.cfg, db, rows,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
removedChans = channelEdges
|
||||||
|
|
||||||
err = s.deleteChannels(ctx, db, chanIDsToDelete)
|
err = s.deleteChannels(ctx, db, chanIDsToDelete)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to delete channels: %w", err)
|
return fmt.Errorf("unable to delete channels: %w", err)
|
||||||
|
|||||||
@@ -126,3 +126,24 @@ func (r GetChannelsByOutpointsRow) Node1Pub() []byte {
|
|||||||
func (r GetChannelsByOutpointsRow) Node2Pub() []byte {
|
func (r GetChannelsByOutpointsRow) Node2Pub() []byte {
|
||||||
return r.Node2Pubkey
|
return r.Node2Pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Channel returns the GraphChannel associated with this interface.
|
||||||
|
//
|
||||||
|
// NOTE: This method is part of the ChannelAndNodeIDs interface.
|
||||||
|
func (r GetChannelsBySCIDRangeRow) Channel() GraphChannel {
|
||||||
|
return r.GraphChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
// Node1Pub returns the public key of the first node as a byte slice.
|
||||||
|
//
|
||||||
|
// NOTE: This method is part of the ChannelAndNodeIDs interface.
|
||||||
|
func (r GetChannelsBySCIDRangeRow) Node1Pub() []byte {
|
||||||
|
return r.Node1PubKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// Node2Pub returns the public key of the second node as a byte slice.
|
||||||
|
//
|
||||||
|
// NOTE: This method is part of the ChannelAndNodeIDs interface.
|
||||||
|
func (r GetChannelsBySCIDRangeRow) Node2Pub() []byte {
|
||||||
|
return r.Node2PubKey
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user