From f485e079b71e96e69d62f06736c1b70afe9c98e9 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Mon, 16 Sep 2024 21:13:57 -0300 Subject: [PATCH] chanbackup: add backup version for TapscriptRoot Previous to this change taproot assets channels and simple taproot channels were considered the same in the context of chanbackup package, since they stored the same data. In the following commits we are adding the data needed to produce a signed commitment transaction from a SCB file and in order to do that we need to add more fields and a custom channel gets one additional field (TapscriptRoot) compared to a simple taproot channel. So now we have to distinguish these kinds of channels in chanbackup package. See PR https://github.com/lightningnetwork/lnd/pull/8183 for more details. --- chanbackup/single.go | 12 +++++++++++- chanbackup/single_test.go | 9 ++++++++- chanrestore.go | 7 +++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/chanbackup/single.go b/chanbackup/single.go index dd63bf1f65..47a4b50545 100644 --- a/chanbackup/single.go +++ b/chanbackup/single.go @@ -52,6 +52,10 @@ const ( // SimpleTaprootVersion is a version that denotes this channel is using // the musig2 based taproot commitment format. SimpleTaprootVersion = 5 + + // TapscriptRootVersion is a version that denotes this is a MuSig2 + // channel with a top level tapscript commitment. + TapscriptRootVersion = 6 ) // Single is a static description of an existing channel that can be used for @@ -218,7 +222,11 @@ func NewSingle(channel *channeldb.OpenChannel, switch { case channel.ChanType.IsTaproot(): - single.Version = SimpleTaprootVersion + if channel.ChanType.HasTapscriptRoot() { + single.Version = TapscriptRootVersion + } else { + single.Version = SimpleTaprootVersion + } case channel.ChanType.HasLeaseExpiration(): single.Version = ScriptEnforcedLeaseVersion @@ -252,6 +260,7 @@ func (s *Single) Serialize(w io.Writer) error { case AnchorsZeroFeeHtlcTxCommitVersion: case ScriptEnforcedLeaseVersion: case SimpleTaprootVersion: + case TapscriptRootVersion: default: return fmt.Errorf("unable to serialize w/ unknown "+ "version: %v", s.Version) @@ -429,6 +438,7 @@ func (s *Single) Deserialize(r io.Reader) error { case AnchorsZeroFeeHtlcTxCommitVersion: case ScriptEnforcedLeaseVersion: case SimpleTaprootVersion: + case TapscriptRootVersion: default: return fmt.Errorf("unable to de-serialize w/ unknown "+ "version: %v", s.Version) diff --git a/chanbackup/single_test.go b/chanbackup/single_test.go index a2d44027b4..68ce35c56c 100644 --- a/chanbackup/single_test.go +++ b/chanbackup/single_test.go @@ -250,13 +250,20 @@ func TestSinglePackUnpack(t *testing.T) { valid: true, }, - // The new taproot channel lease version should + // The new taproot channel version should // pack/unpack with no problem. { version: SimpleTaprootVersion, valid: true, }, + // The new tapscript root channel version should pack/unpack + // with no problem. + { + version: TapscriptRootVersion, + valid: true, + }, + // A non-default version, atm this should result in a failure. { version: 99, diff --git a/chanrestore.go b/chanrestore.go index 27f6d6d9e0..5b221c105a 100644 --- a/chanrestore.go +++ b/chanrestore.go @@ -162,6 +162,13 @@ func (c *chanDBRestorer) openChannelShell(backup chanbackup.Single) ( chanType |= channeldb.SingleFunderTweaklessBit chanType |= channeldb.SimpleTaprootFeatureBit + case chanbackup.TapscriptRootVersion: + chanType = channeldb.ZeroHtlcTxFeeBit + chanType |= channeldb.AnchorOutputsBit + chanType |= channeldb.SingleFunderTweaklessBit + chanType |= channeldb.SimpleTaprootFeatureBit + chanType |= channeldb.TapscriptRootBit + default: return nil, fmt.Errorf("unknown Single version: %w", err) }