channeldb/channel: allow storing empty closes

This is preparation for the subsequent commit, allowing us to fix a race
condition in the integration test assertions.
This commit is contained in:
Conner Fromknecht
2019-12-04 13:30:46 -08:00
parent d9cf0396b3
commit 46990c412c
2 changed files with 30 additions and 9 deletions

View File

@@ -956,13 +956,18 @@ func (c *OpenChannel) markBroadcasted(status ChannelStatus, key []byte,
c.Lock()
defer c.Unlock()
var b bytes.Buffer
if err := WriteElement(&b, closeTx); err != nil {
return err
}
// If a closing tx is provided, we'll generate a closure to write the
// transaction in the appropriate bucket under the given key.
var putClosingTx func(*bbolt.Bucket) error
if closeTx != nil {
var b bytes.Buffer
if err := WriteElement(&b, closeTx); err != nil {
return err
}
putClosingTx := func(chanBucket *bbolt.Bucket) error {
return chanBucket.Put(key, b.Bytes())
putClosingTx = func(chanBucket *bbolt.Bucket) error {
return chanBucket.Put(key, b.Bytes())
}
}
return c.putChanStatus(status, putClosingTx)
@@ -1039,6 +1044,11 @@ func (c *OpenChannel) putChanStatus(status ChannelStatus,
}
for _, f := range fs {
// Skip execution of nil closures.
if f == nil {
continue
}
if err := f(chanBucket); err != nil {
return err
}