From 00ef493aa0eb6efd18e082cb0011c5b9483a1915 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Tue, 26 Nov 2019 14:07:04 +0100 Subject: [PATCH] channeldb: keep open channel data in historical channel bucket --- channeldb/channel.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index 696cc4ed..ed0e42c3 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -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(