mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 17:55:36 +01:00
multi: add new SCB version for the taproot chan type
This commit is contained in:
parent
94f45b2b82
commit
5f1e0bf772
3 changed files with 45 additions and 0 deletions
|
@ -48,6 +48,10 @@ const (
|
||||||
// commitment and HTLC outputs that pay directly to the channel
|
// commitment and HTLC outputs that pay directly to the channel
|
||||||
// initiator.
|
// initiator.
|
||||||
ScriptEnforcedLeaseVersion = 4
|
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
|
// Single is a static description of an existing channel that can be used for
|
||||||
|
@ -213,6 +217,9 @@ func NewSingle(channel *channeldb.OpenChannel,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case channel.ChanType.IsTaproot():
|
||||||
|
single.Version = SimpleTaprootVersion
|
||||||
|
|
||||||
case channel.ChanType.HasLeaseExpiration():
|
case channel.ChanType.HasLeaseExpiration():
|
||||||
single.Version = ScriptEnforcedLeaseVersion
|
single.Version = ScriptEnforcedLeaseVersion
|
||||||
single.LeaseExpiry = channel.ThawHeight
|
single.LeaseExpiry = channel.ThawHeight
|
||||||
|
@ -244,6 +251,7 @@ func (s *Single) Serialize(w io.Writer) error {
|
||||||
case AnchorsCommitVersion:
|
case AnchorsCommitVersion:
|
||||||
case AnchorsZeroFeeHtlcTxCommitVersion:
|
case AnchorsZeroFeeHtlcTxCommitVersion:
|
||||||
case ScriptEnforcedLeaseVersion:
|
case ScriptEnforcedLeaseVersion:
|
||||||
|
case SimpleTaprootVersion:
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unable to serialize w/ unknown "+
|
return fmt.Errorf("unable to serialize w/ unknown "+
|
||||||
"version: %v", s.Version)
|
"version: %v", s.Version)
|
||||||
|
@ -420,6 +428,7 @@ func (s *Single) Deserialize(r io.Reader) error {
|
||||||
case AnchorsCommitVersion:
|
case AnchorsCommitVersion:
|
||||||
case AnchorsZeroFeeHtlcTxCommitVersion:
|
case AnchorsZeroFeeHtlcTxCommitVersion:
|
||||||
case ScriptEnforcedLeaseVersion:
|
case ScriptEnforcedLeaseVersion:
|
||||||
|
case SimpleTaprootVersion:
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unable to de-serialize w/ unknown "+
|
return fmt.Errorf("unable to de-serialize w/ unknown "+
|
||||||
"version: %v", s.Version)
|
"version: %v", s.Version)
|
||||||
|
|
|
@ -154,6 +154,12 @@ func (c *chanDBRestorer) openChannelShell(backup chanbackup.Single) (
|
||||||
chanType |= channeldb.AnchorOutputsBit
|
chanType |= channeldb.AnchorOutputsBit
|
||||||
chanType |= channeldb.SingleFunderTweaklessBit
|
chanType |= channeldb.SingleFunderTweaklessBit
|
||||||
|
|
||||||
|
case chanbackup.SimpleTaprootVersion:
|
||||||
|
chanType = channeldb.ZeroHtlcTxFeeBit
|
||||||
|
chanType |= channeldb.AnchorOutputsBit
|
||||||
|
chanType |= channeldb.SingleFunderTweaklessBit
|
||||||
|
chanType |= channeldb.SimpleTaprootFeatureBit
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown Single version: %v", err)
|
return nil, fmt.Errorf("unknown Single version: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,13 @@ func newChanRestoreScenario(ht *lntest.HarnessTest, ct lnrpc.CommitmentType,
|
||||||
// with a portion pushed.
|
// with a portion pushed.
|
||||||
ht.ConnectNodes(dave, carol)
|
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{
|
return &chanRestoreScenario{
|
||||||
carol: carol,
|
carol: carol,
|
||||||
dave: dave,
|
dave: dave,
|
||||||
|
@ -117,6 +124,7 @@ func newChanRestoreScenario(ht *lntest.HarnessTest, ct lnrpc.CommitmentType,
|
||||||
PushAmt: pushAmt,
|
PushAmt: pushAmt,
|
||||||
ZeroConf: zeroConf,
|
ZeroConf: zeroConf,
|
||||||
CommitmentType: ct,
|
CommitmentType: ct,
|
||||||
|
Private: privateChan,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -564,6 +572,21 @@ func testChannelBackupRestoreCommitTypes(ht *lntest.HarnessTest) {
|
||||||
ct: lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE,
|
ct: lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE,
|
||||||
zeroConf: true,
|
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,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
@ -626,6 +649,13 @@ func runChanRestoreScenarioCommitTypes(ht *lntest.HarnessTest,
|
||||||
multi, err := ioutil.ReadFile(backupFilePath)
|
multi, err := ioutil.ReadFile(backupFilePath)
|
||||||
require.NoError(ht, err)
|
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
|
// Now that we have Dave's backup file, we'll create a new nodeRestorer
|
||||||
// that we'll restore using the on-disk channels.backup.
|
// that we'll restore using the on-disk channels.backup.
|
||||||
restoredNodeFunc := chanRestoreViaRPC(
|
restoredNodeFunc := chanRestoreViaRPC(
|
||||||
|
|
Loading…
Add table
Reference in a new issue