From 040c6bdf2282cab77c1ee2d2971d7600ac20d758 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 9 Nov 2017 19:57:33 -0800 Subject: [PATCH] channeldb: add new HtlcIndex and LogIndex fields to the HTLC struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By adding these two fields, it is now possible to fully reconstruct the channel’s update log from the set of HTLC’s stored on disk, as we now properly note both the log index and HTLC index. Prior to this commit we would simply start the new log index based on the amount of HTLC’s that were present in the prior state. --- channeldb/channel.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index 20bbf5ce..7ffc8f17 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -566,9 +566,11 @@ func (c *OpenChannel) UpdateHTLCs(htlcs []*HTLC) error { }) } -// HTLC is the on-disk representation of a hash time-locked contract. HTLCs -// are contained within ChannelDeltas which encode the current state of the +// HTLC is the on-disk representation of a hash time-locked contract. HTLCs are +// contained within ChannelDeltas which encode the current state of the // commitment between state updates. +// +// TODO(roasbeef): save space by using smaller ints at tail end? type HTLC struct { // Signature is the signature for the second level covenant transaction // for this HTLC. The second level transaction is a timeout tx in the @@ -600,8 +602,17 @@ type HTLC struct { // routing. OnionBlob []byte - // AddLocalInclusionHeight... - AddLocalInclusionHeight uint64 + // HtlcIndex is the HTLC counter index of this active, outstanding + // HTLC. This differs from the LogIndex, as the HtlcIndex is only + // incremented for each offered HTLC, while they LogIndex is + // incremented for each update (includes settle+fail). + HtlcIndex uint64 + + // LogIndex is the cumulative log index of this this HTLC. This differs + // from the HtlcIndex as this will be incremented for each new log + // update added. + LogIndex uint64 +} // AddRemoteInclusionHeight... AddRemoteInclusionHeight uint64