Merge pull request #2773 from Roasbeef/graph-batch
channeldb: convert all Update calls to use Batch
This commit is contained in:
commit
6ad8be25e1
@ -1027,7 +1027,7 @@ func (c *OpenChannel) UpdateCommitment(newCommitment *ChannelCommitment) error {
|
|||||||
return ErrNoRestoredChannelMutation
|
return ErrNoRestoredChannelMutation
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.Db.Update(func(tx *bbolt.Tx) error {
|
err := c.Db.Batch(func(tx *bbolt.Tx) error {
|
||||||
chanBucket, err := fetchChanBucket(
|
chanBucket, err := fetchChanBucket(
|
||||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||||
)
|
)
|
||||||
@ -1465,7 +1465,7 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
|
|||||||
return ErrNoRestoredChannelMutation
|
return ErrNoRestoredChannelMutation
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
return c.Db.Batch(func(tx *bbolt.Tx) error {
|
||||||
// First, we'll grab the writable bucket where this channel's
|
// First, we'll grab the writable bucket where this channel's
|
||||||
// data resides.
|
// data resides.
|
||||||
chanBucket, err := fetchChanBucket(
|
chanBucket, err := fetchChanBucket(
|
||||||
@ -1608,7 +1608,9 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg) error {
|
|||||||
|
|
||||||
var newRemoteCommit *ChannelCommitment
|
var newRemoteCommit *ChannelCommitment
|
||||||
|
|
||||||
err := c.Db.Update(func(tx *bbolt.Tx) error {
|
err := c.Db.Batch(func(tx *bbolt.Tx) error {
|
||||||
|
newRemoteCommit = nil
|
||||||
|
|
||||||
chanBucket, err := fetchChanBucket(
|
chanBucket, err := fetchChanBucket(
|
||||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||||
)
|
)
|
||||||
@ -1746,7 +1748,7 @@ func (c *OpenChannel) AckAddHtlcs(addRefs ...AddRef) error {
|
|||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
return c.Db.Batch(func(tx *bbolt.Tx) error {
|
||||||
return c.Packager.AckAddHtlcs(tx, addRefs...)
|
return c.Packager.AckAddHtlcs(tx, addRefs...)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1759,7 +1761,7 @@ func (c *OpenChannel) AckSettleFails(settleFailRefs ...SettleFailRef) error {
|
|||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
return c.Db.Batch(func(tx *bbolt.Tx) error {
|
||||||
return c.Packager.AckSettleFails(tx, settleFailRefs...)
|
return c.Packager.AckSettleFails(tx, settleFailRefs...)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1770,7 +1772,7 @@ func (c *OpenChannel) SetFwdFilter(height uint64, fwdFilter *PkgFilter) error {
|
|||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
return c.Db.Batch(func(tx *bbolt.Tx) error {
|
||||||
return c.Packager.SetFwdFilter(tx, height, fwdFilter)
|
return c.Packager.SetFwdFilter(tx, height, fwdFilter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1783,14 +1785,15 @@ func (c *OpenChannel) RemoveFwdPkg(height uint64) error {
|
|||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
return c.Db.Batch(func(tx *bbolt.Tx) error {
|
||||||
return c.Packager.RemovePkg(tx, height)
|
return c.Packager.RemovePkg(tx, height)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// RevocationLogTail returns the "tail", or the end of the current revocation
|
// RevocationLogTail returns the "tail", or the end of the current revocation
|
||||||
// log. This entry represents the last previous state for the remote node's
|
// log. This entry represents the last previous state for the remote node's
|
||||||
// commitment chain. The ChannelDelta returned by this method will always lag one state behind the most current (unrevoked) state of the remote node's
|
// commitment chain. The ChannelDelta returned by this method will always lag
|
||||||
|
// one state behind the most current (unrevoked) state of the remote node's
|
||||||
// commitment chain.
|
// commitment chain.
|
||||||
func (c *OpenChannel) RevocationLogTail() (*ChannelCommitment, error) {
|
func (c *OpenChannel) RevocationLogTail() (*ChannelCommitment, error) {
|
||||||
c.RLock()
|
c.RLock()
|
||||||
|
@ -326,7 +326,7 @@ func (c *ChannelGraph) sourceNode(nodes *bbolt.Bucket) (*LightningNode, error) {
|
|||||||
func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
|
func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
|
||||||
nodePubBytes := node.PubKeyBytes[:]
|
nodePubBytes := node.PubKeyBytes[:]
|
||||||
|
|
||||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
return c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
// First grab the nodes bucket which stores the mapping from
|
// First grab the nodes bucket which stores the mapping from
|
||||||
// pubKey to node information.
|
// pubKey to node information.
|
||||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||||
@ -355,7 +355,7 @@ func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): also need sig of announcement
|
// TODO(roasbeef): also need sig of announcement
|
||||||
func (c *ChannelGraph) AddLightningNode(node *LightningNode) error {
|
func (c *ChannelGraph) AddLightningNode(node *LightningNode) error {
|
||||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
return c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
return addLightningNode(tx, node)
|
return addLightningNode(tx, node)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -419,7 +419,7 @@ func (c *ChannelGraph) LookupAlias(pub *btcec.PublicKey) (string, error) {
|
|||||||
// from the database according to the node's public key.
|
// from the database according to the node's public key.
|
||||||
func (c *ChannelGraph) DeleteLightningNode(nodePub *btcec.PublicKey) error {
|
func (c *ChannelGraph) DeleteLightningNode(nodePub *btcec.PublicKey) error {
|
||||||
// TODO(roasbeef): ensure dangling edges are removed...
|
// TODO(roasbeef): ensure dangling edges are removed...
|
||||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
return c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
nodes := tx.Bucket(nodeBucket)
|
nodes := tx.Bucket(nodeBucket)
|
||||||
if nodes == nil {
|
if nodes == nil {
|
||||||
return ErrGraphNodeNotFound
|
return ErrGraphNodeNotFound
|
||||||
@ -483,7 +483,7 @@ func (c *ChannelGraph) deleteLightningNode(nodes *bbolt.Bucket,
|
|||||||
// the channel supports. The chanPoint and chanID are used to uniquely identify
|
// the channel supports. The chanPoint and chanID are used to uniquely identify
|
||||||
// the edge globally within the database.
|
// the edge globally within the database.
|
||||||
func (c *ChannelGraph) AddChannelEdge(edge *ChannelEdgeInfo) error {
|
func (c *ChannelGraph) AddChannelEdge(edge *ChannelEdgeInfo) error {
|
||||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
return c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
return c.addChannelEdge(tx, edge)
|
return c.addChannelEdge(tx, edge)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -657,7 +657,7 @@ func (c *ChannelGraph) UpdateChannelEdge(edge *ChannelEdgeInfo) error {
|
|||||||
var chanKey [8]byte
|
var chanKey [8]byte
|
||||||
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
|
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
|
||||||
|
|
||||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
return c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
edges := tx.Bucket(edgeBucket)
|
edges := tx.Bucket(edgeBucket)
|
||||||
if edge == nil {
|
if edge == nil {
|
||||||
return ErrEdgeNotFound
|
return ErrEdgeNotFound
|
||||||
@ -697,7 +697,9 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
|||||||
|
|
||||||
var chansClosed []*ChannelEdgeInfo
|
var chansClosed []*ChannelEdgeInfo
|
||||||
|
|
||||||
err := c.db.Update(func(tx *bbolt.Tx) error {
|
err := c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
|
chansClosed = nil
|
||||||
|
|
||||||
// First grab the edges bucket which houses the information
|
// First grab the edges bucket which houses the information
|
||||||
// we'd like to delete
|
// we'd like to delete
|
||||||
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
||||||
@ -801,7 +803,7 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
|||||||
// that we only maintain a graph of reachable nodes. In the event that a pruned
|
// that we only maintain a graph of reachable nodes. In the event that a pruned
|
||||||
// node gains more channels, it will be re-added back to the graph.
|
// node gains more channels, it will be re-added back to the graph.
|
||||||
func (c *ChannelGraph) PruneGraphNodes() error {
|
func (c *ChannelGraph) PruneGraphNodes() error {
|
||||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
return c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
nodes := tx.Bucket(nodeBucket)
|
nodes := tx.Bucket(nodeBucket)
|
||||||
if nodes == nil {
|
if nodes == nil {
|
||||||
return ErrGraphNodesNotFound
|
return ErrGraphNodesNotFound
|
||||||
@ -946,7 +948,9 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) ([]*ChannelEdgeInf
|
|||||||
// Keep track of the channels that are removed from the graph.
|
// Keep track of the channels that are removed from the graph.
|
||||||
var removedChans []*ChannelEdgeInfo
|
var removedChans []*ChannelEdgeInfo
|
||||||
|
|
||||||
if err := c.db.Update(func(tx *bbolt.Tx) error {
|
if err := c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
|
removedChans = nil
|
||||||
|
|
||||||
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1070,7 +1074,7 @@ func (c *ChannelGraph) DeleteChannelEdge(chanPoint *wire.OutPoint) error {
|
|||||||
// channels
|
// channels
|
||||||
// TODO(roasbeef): don't delete both edges?
|
// TODO(roasbeef): don't delete both edges?
|
||||||
|
|
||||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
return c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
// First grab the edges bucket which houses the information
|
// First grab the edges bucket which houses the information
|
||||||
// we'd like to delete
|
// we'd like to delete
|
||||||
edges := tx.Bucket(edgeBucket)
|
edges := tx.Bucket(edgeBucket)
|
||||||
@ -1642,7 +1646,7 @@ func delChannelByEdge(edges *bbolt.Bucket, edgeIndex *bbolt.Bucket,
|
|||||||
// determined by the lexicographical ordering of the identity public keys of
|
// determined by the lexicographical ordering of the identity public keys of
|
||||||
// the nodes on either side of the channel.
|
// the nodes on either side of the channel.
|
||||||
func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy) error {
|
func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy) error {
|
||||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
return c.db.Batch(func(tx *bbolt.Tx) error {
|
||||||
return updateEdgePolicy(tx, edge)
|
return updateEdgePolicy(tx, edge)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,9 @@ func (d *DB) AddInvoice(newInvoice *Invoice, paymentHash lntypes.Hash) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
var invoiceAddIndex uint64
|
var invoiceAddIndex uint64
|
||||||
err := d.Update(func(tx *bbolt.Tx) error {
|
err := d.Batch(func(tx *bbolt.Tx) error {
|
||||||
|
invoiceAddIndex = 0
|
||||||
|
|
||||||
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -635,7 +637,9 @@ func (d *DB) AcceptOrSettleInvoice(paymentHash [32]byte,
|
|||||||
amtPaid lnwire.MilliSatoshi) (*Invoice, error) {
|
amtPaid lnwire.MilliSatoshi) (*Invoice, error) {
|
||||||
|
|
||||||
var settledInvoice *Invoice
|
var settledInvoice *Invoice
|
||||||
err := d.Update(func(tx *bbolt.Tx) error {
|
err := d.Batch(func(tx *bbolt.Tx) error {
|
||||||
|
settledInvoice = nil
|
||||||
|
|
||||||
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -714,7 +718,9 @@ func (d *DB) SettleHoldInvoice(preimage lntypes.Preimage) (*Invoice, error) {
|
|||||||
// payment hash.
|
// payment hash.
|
||||||
func (d *DB) CancelInvoice(paymentHash lntypes.Hash) (*Invoice, error) {
|
func (d *DB) CancelInvoice(paymentHash lntypes.Hash) (*Invoice, error) {
|
||||||
var canceledInvoice *Invoice
|
var canceledInvoice *Invoice
|
||||||
err := d.Update(func(tx *bbolt.Tx) error {
|
err := d.Batch(func(tx *bbolt.Tx) error {
|
||||||
|
canceledInvoice = nil
|
||||||
|
|
||||||
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user