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.
This commit is contained in:
Boris Nagaev 2024-09-16 21:13:57 -03:00
parent 90c45ddd8f
commit f485e079b7
No known key found for this signature in database
3 changed files with 26 additions and 2 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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)
}