Skip to content

Commit

Permalink
chanbackup: add backup version for TapscriptRoot
Browse files Browse the repository at this point in the history
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 lightningnetwork#8183 for more details.
  • Loading branch information
starius committed Oct 2, 2024
1 parent 8f33afb commit b3326f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
12 changes: 11 additions & 1 deletion chanbackup/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion chanbackup/single_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions chanrestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b3326f0

Please sign in to comment.