@@ -326,7 +326,7 @@ func (c *ChannelGraph) sourceNode(nodes *bbolt.Bucket) (*LightningNode, error) {
326
326
func (c * ChannelGraph ) SetSourceNode (node * LightningNode ) error {
327
327
nodePubBytes := node .PubKeyBytes [:]
328
328
329
- return c .db .Update (func (tx * bbolt.Tx ) error {
329
+ return c .db .Batch (func (tx * bbolt.Tx ) error {
330
330
// First grab the nodes bucket which stores the mapping from
331
331
// pubKey to node information.
332
332
nodes , err := tx .CreateBucketIfNotExists (nodeBucket )
@@ -355,7 +355,7 @@ func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
355
355
//
356
356
// TODO(roasbeef): also need sig of announcement
357
357
func (c * ChannelGraph ) AddLightningNode (node * LightningNode ) error {
358
- return c .db .Update (func (tx * bbolt.Tx ) error {
358
+ return c .db .Batch (func (tx * bbolt.Tx ) error {
359
359
return addLightningNode (tx , node )
360
360
})
361
361
}
@@ -419,7 +419,7 @@ func (c *ChannelGraph) LookupAlias(pub *btcec.PublicKey) (string, error) {
419
419
// from the database according to the node's public key.
420
420
func (c * ChannelGraph ) DeleteLightningNode (nodePub * btcec.PublicKey ) error {
421
421
// TODO(roasbeef): ensure dangling edges are removed...
422
- return c .db .Update (func (tx * bbolt.Tx ) error {
422
+ return c .db .Batch (func (tx * bbolt.Tx ) error {
423
423
nodes := tx .Bucket (nodeBucket )
424
424
if nodes == nil {
425
425
return ErrGraphNodeNotFound
@@ -483,7 +483,7 @@ func (c *ChannelGraph) deleteLightningNode(nodes *bbolt.Bucket,
483
483
// the channel supports. The chanPoint and chanID are used to uniquely identify
484
484
// the edge globally within the database.
485
485
func (c * ChannelGraph ) AddChannelEdge (edge * ChannelEdgeInfo ) error {
486
- return c .db .Update (func (tx * bbolt.Tx ) error {
486
+ return c .db .Batch (func (tx * bbolt.Tx ) error {
487
487
return c .addChannelEdge (tx , edge )
488
488
})
489
489
}
@@ -657,7 +657,7 @@ func (c *ChannelGraph) UpdateChannelEdge(edge *ChannelEdgeInfo) error {
657
657
var chanKey [8 ]byte
658
658
binary .BigEndian .PutUint64 (chanKey [:], edge .ChannelID )
659
659
660
- return c .db .Update (func (tx * bbolt.Tx ) error {
660
+ return c .db .Batch (func (tx * bbolt.Tx ) error {
661
661
edges := tx .Bucket (edgeBucket )
662
662
if edge == nil {
663
663
return ErrEdgeNotFound
@@ -697,7 +697,9 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
697
697
698
698
var chansClosed []* ChannelEdgeInfo
699
699
700
- err := c .db .Update (func (tx * bbolt.Tx ) error {
700
+ err := c .db .Batch (func (tx * bbolt.Tx ) error {
701
+ chansClosed = nil
702
+
701
703
// First grab the edges bucket which houses the information
702
704
// we'd like to delete
703
705
edges , err := tx .CreateBucketIfNotExists (edgeBucket )
@@ -801,7 +803,7 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
801
803
// that we only maintain a graph of reachable nodes. In the event that a pruned
802
804
// node gains more channels, it will be re-added back to the graph.
803
805
func (c * ChannelGraph ) PruneGraphNodes () error {
804
- return c .db .Update (func (tx * bbolt.Tx ) error {
806
+ return c .db .Batch (func (tx * bbolt.Tx ) error {
805
807
nodes := tx .Bucket (nodeBucket )
806
808
if nodes == nil {
807
809
return ErrGraphNodesNotFound
@@ -946,7 +948,9 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) ([]*ChannelEdgeInf
946
948
// Keep track of the channels that are removed from the graph.
947
949
var removedChans []* ChannelEdgeInfo
948
950
949
- if err := c .db .Update (func (tx * bbolt.Tx ) error {
951
+ if err := c .db .Batch (func (tx * bbolt.Tx ) error {
952
+ removedChans = nil
953
+
950
954
edges , err := tx .CreateBucketIfNotExists (edgeBucket )
951
955
if err != nil {
952
956
return err
@@ -1070,7 +1074,7 @@ func (c *ChannelGraph) DeleteChannelEdge(chanPoint *wire.OutPoint) error {
1070
1074
// channels
1071
1075
// TODO(roasbeef): don't delete both edges?
1072
1076
1073
- return c .db .Update (func (tx * bbolt.Tx ) error {
1077
+ return c .db .Batch (func (tx * bbolt.Tx ) error {
1074
1078
// First grab the edges bucket which houses the information
1075
1079
// we'd like to delete
1076
1080
edges := tx .Bucket (edgeBucket )
@@ -1642,7 +1646,7 @@ func delChannelByEdge(edges *bbolt.Bucket, edgeIndex *bbolt.Bucket,
1642
1646
// determined by the lexicographical ordering of the identity public keys of
1643
1647
// the nodes on either side of the channel.
1644
1648
func (c * ChannelGraph ) UpdateEdgePolicy (edge * ChannelEdgePolicy ) error {
1645
- return c .db .Update (func (tx * bbolt.Tx ) error {
1649
+ return c .db .Batch (func (tx * bbolt.Tx ) error {
1646
1650
return updateEdgePolicy (tx , edge )
1647
1651
})
1648
1652
}
0 commit comments