channeldb: keep open channel data in historical channel bucket

This commit is contained in:
Joost Jager 2019-11-26 14:07:04 +01:00
parent 509d0fb82d
commit 00ef493aa0
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -37,6 +37,11 @@ var (
// TODO(roasbeef): flesh out comment
openChannelBucket = []byte("open-chan-bucket")
// historicalChannelBucket stores all channels that have seen their
// commitment tx confirm. All information from their previous open state
// is retained.
historicalChannelBucket = []byte("historical-chan-bucket")
// chanInfoKey can be accessed within the bucket for a channel
// (identified by its chanPoint). This key stores all the static
// information for a channel which is decided at the end of the
@ -2229,7 +2234,8 @@ func (c *OpenChannel) CloseChannel(summary *ChannelCloseSummary) error {
if err != nil {
return err
}
chanBucket := chainBucket.Bucket(chanPointBuf.Bytes())
chanKey := chanPointBuf.Bytes()
chanBucket := chainBucket.Bucket(chanKey)
if chanBucket == nil {
return ErrNoActiveChannels
}
@ -2266,6 +2272,25 @@ func (c *OpenChannel) CloseChannel(summary *ChannelCloseSummary) error {
return err
}
// Add channel state to the historical channel bucket.
historicalBucket, err := tx.CreateBucketIfNotExists(
historicalChannelBucket,
)
if err != nil {
return err
}
historicalChanBucket, err :=
historicalBucket.CreateBucketIfNotExists(chanKey)
if err != nil {
return err
}
err = putOpenChannel(historicalChanBucket, chanState)
if err != nil {
return err
}
// Finally, create a summary of this channel in the closed
// channel bucket for this node.
return putChannelCloseSummary(