channeldb: move serialization of outpoint into db txn in CloseChannel

This commit is contained in:
Olaoluwa Osuntokun 2017-02-02 16:59:14 -08:00
parent c1c1cabc4e
commit aeb7cce7c3
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -571,21 +571,16 @@ func (c *OpenChannel) FindPreviousState(updateNum uint64) (*ChannelDelta, error)
// purposes.
// TODO(roasbeef): delete on-disk set of HTLCs
func (c *OpenChannel) CloseChannel() error {
var b bytes.Buffer
if err := writeOutpoint(&b, c.ChanID); err != nil {
return err
}
return c.Db.Update(func(tx *bolt.Tx) error {
// First fetch the top level bucket which stores all data related to
// current, active channels.
// First fetch the top level bucket which stores all data
// related to current, active channels.
chanBucket := tx.Bucket(openChannelBucket)
if chanBucket == nil {
return ErrNoChanDBExists
}
// Within this top level bucket, fetch the bucket dedicated to storing
// open channel data specific to the remote node.
// Within this top level bucket, fetch the bucket dedicated to
// storing open channel data specific to the remote node.
nodePub := c.IdentityPub.SerializeCompressed()
nodeChanBucket := chanBucket.Bucket(nodePub)
if nodeChanBucket == nil {
@ -598,6 +593,11 @@ func (c *OpenChannel) CloseChannel() error {
return ErrNoActiveChannels
}
var b bytes.Buffer
if err := writeOutpoint(&b, c.ChanID); err != nil {
return err
}
// If this channel isn't found within the channel index bucket,
// then it has already been deleted. So we can exit early as
// there isn't any more work for us to do here.