Skip to content

Commit

Permalink
multi: add new SCB version for the taproot chan type
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Aug 19, 2023
1 parent e16354a commit 67d31fe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
9 changes: 9 additions & 0 deletions chanbackup/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const (
// commitment and HTLC outputs that pay directly to the channel
// initiator.
ScriptEnforcedLeaseVersion = 4

// SimpleTaprootVersion is a version that denotes this channel is using
// the musig2 based taproot commitment format.
SimpleTaprootVersion = 5
)

// Single is a static description of an existing channel that can be used for
Expand Down Expand Up @@ -213,6 +217,9 @@ func NewSingle(channel *channeldb.OpenChannel,
}

switch {
case channel.ChanType.IsTaproot():
single.Version = SimpleTaprootVersion

case channel.ChanType.HasLeaseExpiration():
single.Version = ScriptEnforcedLeaseVersion
single.LeaseExpiry = channel.ThawHeight
Expand Down Expand Up @@ -244,6 +251,7 @@ func (s *Single) Serialize(w io.Writer) error {
case AnchorsCommitVersion:
case AnchorsZeroFeeHtlcTxCommitVersion:
case ScriptEnforcedLeaseVersion:
case SimpleTaprootVersion:
default:
return fmt.Errorf("unable to serialize w/ unknown "+
"version: %v", s.Version)
Expand Down Expand Up @@ -420,6 +428,7 @@ func (s *Single) Deserialize(r io.Reader) error {
case AnchorsCommitVersion:
case AnchorsZeroFeeHtlcTxCommitVersion:
case ScriptEnforcedLeaseVersion:
case SimpleTaprootVersion:
default:
return fmt.Errorf("unable to de-serialize w/ unknown "+
"version: %v", s.Version)
Expand Down
6 changes: 6 additions & 0 deletions chanrestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ func (c *chanDBRestorer) openChannelShell(backup chanbackup.Single) (
chanType |= channeldb.AnchorOutputsBit
chanType |= channeldb.SingleFunderTweaklessBit

case chanbackup.SimpleTaprootVersion:
chanType = channeldb.ZeroHtlcTxFeeBit
chanType |= channeldb.AnchorOutputsBit
chanType |= channeldb.SingleFunderTweaklessBit
chanType |= channeldb.SimpleTaprootFeatureBit

default:
return nil, fmt.Errorf("unknown Single version: %v", err)
}
Expand Down
32 changes: 31 additions & 1 deletion itest/lnd_channel_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ func newChanRestoreScenario(ht *lntest.HarnessTest, ct lnrpc.CommitmentType,
// with a portion pushed.
ht.ConnectNodes(dave, carol)

// If the commitment type is taproot, then the channel must also be
// private.
var privateChan bool
if ct == lnrpc.CommitmentType_SIMPLE_TAPROOT {
privateChan = true
}

return &chanRestoreScenario{
carol: carol,
dave: dave,
Expand All @@ -117,6 +124,7 @@ func newChanRestoreScenario(ht *lntest.HarnessTest, ct lnrpc.CommitmentType,
PushAmt: pushAmt,
ZeroConf: zeroConf,
CommitmentType: ct,
Private: privateChan,
},
}
}
Expand Down Expand Up @@ -537,7 +545,7 @@ func testChannelBackupRestoreCommitTypes(ht *lntest.HarnessTest) {
}{
// Restore the backup from the on-disk file, using the RPC
// interface, for anchor commitment channels.
{
/*{
name: "restore from backup file anchors",
ct: lnrpc.CommitmentType_ANCHORS,
},
Expand Down Expand Up @@ -566,6 +574,21 @@ func testChannelBackupRestoreCommitTypes(ht *lntest.HarnessTest) {
"script-enforced leased channel",
ct: lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE,
zeroConf: true,
},*/

// Restore a channel back up of a taproot channel that was
// confirmed.
{
name: "restore from backup taproot",
ct: lnrpc.CommitmentType_SIMPLE_TAPROOT,
zeroConf: false,
},

// Restore a chanenl back up of an unconfirmed taproot channel.
{
name: "restore from backup taproot zero conf",
ct: lnrpc.CommitmentType_SIMPLE_TAPROOT,
zeroConf: true,
},
}

Expand Down Expand Up @@ -629,6 +652,13 @@ func runChanRestoreScenarioCommitTypes(ht *lntest.HarnessTest,
multi, err := ioutil.ReadFile(backupFilePath)
require.NoError(ht, err)

// If this was a zero conf taproot channel, then since it's private,
// we'll need to mine an extra block (framework won't mine extra blocks
// otherwise).
if ct == lnrpc.CommitmentType_SIMPLE_TAPROOT && zeroConf {
ht.MineBlocksAndAssertNumTxes(1, 1)
}

// Now that we have Dave's backup file, we'll create a new nodeRestorer
// that we'll restore using the on-disk channels.backup.
restoredNodeFunc := chanRestoreViaRPC(
Expand Down

0 comments on commit 67d31fe

Please sign in to comment.