channeldb: deleting a channel twice no longer triggers an error
This commit adds an additional check within CloseChannel to ensure that sub-systems attempting to delete the channel one after the other (in the event of any sort of closure) doesn’t result in an extraneous error. To fix this, we now check if the channel exists before attempting a deletion. If the channel doesn’t exist, then we simply exit early with a nil error.
This commit is contained in:
parent
ddc1eb4c8a
commit
cbd26b35e0
@ -568,6 +568,11 @@ func (c *OpenChannel) FindPreviousState(updateNum uint64) (*ChannelDelta, error)
|
||||
// purposes.
|
||||
// TODO(roasbeef): delete on-disk set of HTLC's
|
||||
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.
|
||||
@ -589,12 +594,19 @@ func (c *OpenChannel) CloseChannel() error {
|
||||
if chanIndexBucket == nil {
|
||||
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.
|
||||
outPointBytes := b.Bytes()
|
||||
if err := chanIndexBucket.Delete(b.Bytes()); err != nil {
|
||||
if chanIndexBucket.Get(outPointBytes) == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Otherwise, we can safely delete the channel from the index
|
||||
// without running into any boltdb related errors by repeated
|
||||
// deletion attempts.
|
||||
if err := chanIndexBucket.Delete(outPointBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user