From 149a8ce94f493acdd2fe97750a2971de2b6fb3c6 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 20 Nov 2018 15:09:45 +0100 Subject: [PATCH] channeldb/legacy_serialization: add deserializeCloseChannelSummaryV6 This commit adds a new file legacy_serialization.go, where a copy of the current deserializeCloseChannelSummary is made, called deserializeCloseChannelSummaryV6. The rationale is to keep old deserialization code around to be used during migration, as it is hard maintaining compatibility with the old format while changing the code in use. --- channeldb/legacy_serialization.go | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 channeldb/legacy_serialization.go diff --git a/channeldb/legacy_serialization.go b/channeldb/legacy_serialization.go new file mode 100644 index 00000000..2abb3f04 --- /dev/null +++ b/channeldb/legacy_serialization.go @@ -0,0 +1,53 @@ +package channeldb + +import "io" + +// deserializeCloseChannelSummaryV6 reads the v6 database format for +// ChannelCloseSummary. +// +// NOTE: deprecated, only for migration. +func deserializeCloseChannelSummaryV6(r io.Reader) (*ChannelCloseSummary, error) { + c := &ChannelCloseSummary{} + + err := ReadElements(r, + &c.ChanPoint, &c.ShortChanID, &c.ChainHash, &c.ClosingTXID, + &c.CloseHeight, &c.RemotePub, &c.Capacity, &c.SettledBalance, + &c.TimeLockedBalance, &c.CloseType, &c.IsPending, + ) + if err != nil { + return nil, err + } + + // We'll now check to see if the channel close summary was encoded with + // any of the additional optional fields. + err = ReadElements(r, &c.RemoteCurrentRevocation) + switch { + case err == io.EOF: + return c, nil + + // If we got a non-eof error, then we know there's an actually issue. + // Otherwise, it may have been the case that this summary didn't have + // the set of optional fields. + case err != nil: + return nil, err + } + + if err := readChanConfig(r, &c.LocalChanConfig); err != nil { + return nil, err + } + + // Finally, we'll attempt to read the next unrevoked commitment point + // for the remote party. If we closed the channel before receiving a + // funding locked message, then this can be nil. As a result, we'll use + // the same technique to read the field, only if there's still data + // left in the buffer. + err = ReadElements(r, &c.RemoteNextRevocation) + if err != nil && err != io.EOF { + // If we got a non-eof error, then we know there's an actually + // issue. Otherwise, it may have been the case that this + // summary didn't have the set of optional fields. + return nil, err + } + + return c, nil +}