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