From 21133e185617ca092a761c04e102747036b1cc24 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 31 Jul 2019 19:59:32 -0700 Subject: [PATCH] channeldb: define new channel type, SingleFunderTweakless In this commit, we define a new channel type: SingleFunderTweakless. We'll use this channel type to denote channels with commitments that don't tweak the remote party's key in their non-delay output. --- channeldb/channel.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index 8b5d5253b..fefd27404 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -135,14 +135,31 @@ const ( // SingleFunder represents a channel wherein one party solely funds the // entire capacity of the channel. - SingleFunder = 0 + SingleFunder ChannelType = 0 // DualFunder represents a channel wherein both parties contribute // funds towards the total capacity of the channel. The channel may be // funded symmetrically or asymmetrically. - DualFunder = 1 + DualFunder ChannelType = 1 + + // SingleFunderTweakless is similar to the basic SingleFunder channel + // type, but it omits the tweak for one's key in the commitment + // transaction of the remote party. + SingleFunderTweakless ChannelType = 2 ) +// IsSingleFunder returns true if the channel type if one of the known single +// funder variants. +func (c ChannelType) IsSingleFunder() bool { + return c == SingleFunder || c == SingleFunderTweakless +} + +// IsTweakless returns true if the target channel uses a commitment that +// doesn't tweak the key for the remote party. +func (c ChannelType) IsTweakless() bool { + return c == SingleFunderTweakless +} + // ChannelConstraints represents a set of constraints meant to allow a node to // limit their exposure, enact flow control and ensure that all HTLCs are // economically relevant. This struct will be mirrored for both sides of the @@ -2506,7 +2523,7 @@ func putChanInfo(chanBucket *bbolt.Bucket, channel *OpenChannel) error { } // For single funder channels that we initiated, write the funding txn. - if channel.ChanType == SingleFunder && channel.IsInitiator && + if channel.ChanType.IsSingleFunder() && channel.IsInitiator && !channel.hasChanStatus(ChanStatusRestored) { if err := WriteElement(&w, channel.FundingTxn); err != nil { @@ -2628,7 +2645,7 @@ func fetchChanInfo(chanBucket *bbolt.Bucket, channel *OpenChannel) error { } // For single funder channels that we initiated, read the funding txn. - if channel.ChanType == SingleFunder && channel.IsInitiator && + if channel.ChanType.IsSingleFunder() && channel.IsInitiator && !channel.hasChanStatus(ChanStatusRestored) { if err := ReadElement(r, &channel.FundingTxn); err != nil {