Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions chanbackup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ func FetchBackupForChan(chanPoint wire.OutPoint,
return nil, fmt.Errorf("unable to find target channel")
}

// TODO(halseth): support chan backups for anchor types.
if targetChan.ChanType.HasAnchors() {
return nil, fmt.Errorf("channel type does not support " +
"backups yet")
}

// Once we have the target channel, we can assemble the backup using
// the source to obtain any extra information that we may need.
staticChanBackup, err := assembleChanBackup(chanSource, targetChan)
Expand All @@ -93,11 +87,6 @@ func FetchStaticChanBackups(chanSource LiveChannelSource) ([]Single, error) {
// channel.
staticChanBackups := make([]Single, 0, len(openChans))
for _, openChan := range openChans {
// TODO(halseth): support chan backups for anchor types.
if openChan.ChanType.HasAnchors() {
continue
}

chanBackup, err := assembleChanBackup(chanSource, openChan)
if err != nil {
return nil, err
Expand Down
6 changes: 0 additions & 6 deletions chanbackup/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ func (s *SubSwapper) backupUpdater() {
// For all new open channels, we'll create a new SCB
// given the required information.
for _, newChan := range chanUpdate.NewChans {
// TODO(halseth): support chan backups for
// anchor types.
if newChan.ChanType.HasAnchors() {
continue
}

log.Debugf("Adding channel %v to backup state",
newChan.FundingOutpoint)

Expand Down
16 changes: 14 additions & 2 deletions chanbackup/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const (
// implicitly denotes that this channel uses the new tweakless commit
// format.
TweaklessCommitVersion = 1

// AnchorsCommitVersion is the third SCB version. This version
// implicitly denotes that this channel uses the new anchor commitment
// format.
AnchorsCommitVersion = 2
)

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

if channel.ChanType.IsTweakless() {
switch {
case channel.ChanType.HasAnchors():
single.Version = AnchorsCommitVersion

case channel.ChanType.IsTweakless():
single.Version = TweaklessCommitVersion
} else {

default:
single.Version = DefaultSingleVersion
}

Expand All @@ -174,6 +184,7 @@ func (s *Single) Serialize(w io.Writer) error {
switch s.Version {
case DefaultSingleVersion:
case TweaklessCommitVersion:
case AnchorsCommitVersion:
default:
return fmt.Errorf("unable to serialize w/ unknown "+
"version: %v", s.Version)
Expand Down Expand Up @@ -332,6 +343,7 @@ func (s *Single) Deserialize(r io.Reader) error {
switch s.Version {
case DefaultSingleVersion:
case TweaklessCommitVersion:
case AnchorsCommitVersion:
default:
return fmt.Errorf("unable to de-serialize w/ unknown "+
"version: %v", s.Version)
Expand Down
10 changes: 9 additions & 1 deletion chanbackup/single_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,20 @@ func TestSinglePackUnpack(t *testing.T) {
valid: true,
},

// The new tweakless version, should pack/unpack with no problem.
// The new tweakless version, should pack/unpack with no
// problem.
{
version: TweaklessCommitVersion,
valid: true,
},

// The new anchor version, should pack/unpack with no
// problem.
{
version: AnchorsCommitVersion,
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 @@ -106,10 +106,17 @@ func (c *chanDBRestorer) openChannelShell(backup chanbackup.Single) (
case chanbackup.TweaklessCommitVersion:
chanType = channeldb.SingleFunderTweaklessBit

case chanbackup.AnchorsCommitVersion:
chanType = channeldb.AnchorOutputsBit
chanType |= channeldb.SingleFunderTweaklessBit

default:
return nil, fmt.Errorf("unknown Single version: %v", err)
}

ltndLog.Infof("SCB Recovery: created channel shell for ChannelPoint(%v), "+
"chan_type=%v", backup.FundingOutpoint, chanType)

chanShell := channeldb.ChannelShell{
NodeAddrs: backup.Addresses,
Chan: &channeldb.OpenChannel{
Expand Down
4 changes: 2 additions & 2 deletions lncfg/protocol_legacy_on.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ProtocolOptions struct {

// Anchors should be set if we want to support opening or accepting
// channels having the anchor commitment type.
Anchors bool `long:"anchors" description:"EXPERIMENTAL: enable experimental support for anchor commitments. Won't work with watchtowers or static channel backups"`
Anchors bool `long:"anchors" description:"EXPERIMENTAL: enable experimental support for anchor commitments, won't work with watchtowers"`
}

// LegacyOnion returns true if the old legacy onion format should be used when
Expand All @@ -35,7 +35,7 @@ func (l *ProtocolOptions) NoStaticRemoteKey() bool {
return l.CommitmentTweak
}

// AnchorCommitments returns true if support for the the anchor commitment type
// AnchorCommitments returns true if support for the anchor commitment type
// should be signaled.
func (l *ProtocolOptions) AnchorCommitments() bool {
return l.Anchors
Expand Down
51 changes: 48 additions & 3 deletions lntest/itest/lnd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,11 +959,15 @@ type commitType byte

const (
// commitTypeLegacy is the old school commitment type.
commitTypeLegacy = iota
commitTypeLegacy commitType = iota

// commiTypeTweakless is the commitment type where the remote key is
// static (non-tweaked).
commitTypeTweakless

// commitTypeAnchors is the kind of commitment that has extra outputs
// used for anchoring down to commitment using CPFP.
commitTypeAnchors
)

// String returns that name of the commitment type.
Expand All @@ -973,6 +977,8 @@ func (c commitType) String() string {
return "legacy"
case commitTypeTweakless:
return "tweakless"
case commitTypeAnchors:
return "anchors"
default:
return "invalid"
}
Expand All @@ -985,6 +991,8 @@ func (c commitType) Args() []string {
return []string{"--protocol.committweak"}
case commitTypeTweakless:
return []string{}
case commitTypeAnchors:
return []string{"--protocol.anchors"}
Comment thread
Roasbeef marked this conversation as resolved.
Outdated
}

return nil
Expand Down Expand Up @@ -8888,6 +8896,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
if err != nil {
t.Fatalf("unable to suspend node: %v", err)
}

return restart, chanPoint, balResp.ConfirmedBalance, nil
}

Expand Down Expand Up @@ -13986,6 +13995,10 @@ type chanRestoreTestCase struct {
// confirmed or not.
unconfirmed bool

// anchorCommit is true, then the new anchor commitment type will be
// used for the channels created in the test.
anchorCommit bool

// restoreMethod takes an old node, then returns a function
// closure that'll return the same node, but with its state
// restored via a custom method. We use this to abstract away
Expand All @@ -14010,11 +14023,16 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,

ctxb := context.Background()

var nodeArgs []string
if testCase.anchorCommit {
nodeArgs = commitTypeAnchors.Args()
}

// First, we'll create a brand new node we'll use within the test. If
// we have a custom backup file specified, then we'll also create that
// for use.
dave, mnemonic, err := net.NewNodeWithSeed(
"dave", nil, password,
"dave", nodeArgs, password,
)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
Expand All @@ -14024,7 +14042,7 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
defer func() {
shutdownAndAssert(net, t, dave)
}()
carol, err := net.NewNode("carol", nil)
carol, err := net.NewNode("carol", nodeArgs)
if err != nil {
t.Fatalf("unable to make new node: %v", err)
}
Expand Down Expand Up @@ -14545,6 +14563,33 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) {
)
},
},

// Restore the backup from the on-disk file, using the RPC
// interface, for anchor commitment channels.
{
name: "restore from backup file anchors",
initiator: true,
private: false,
anchorCommit: true,
restoreMethod: func(oldNode *lntest.HarnessNode,
backupFilePath string,
mnemonic []string) (nodeRestorer, error) {

// Read the entire Multi backup stored within
// this node's channels.backup file.
multi, err := ioutil.ReadFile(backupFilePath)
if err != nil {
return nil, err
}

// Now that we have Dave's backup file, we'll
// create a new nodeRestorer that will restore
// using the on-disk channels.backup.
return chanRestoreViaRPC(
net, password, mnemonic, multi,
)
},
},
}

// TODO(roasbeef): online vs offline close?
Expand Down
2 changes: 1 addition & 1 deletion lnwallet/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func CommitScriptAnchors(localChanCfg,
return nil, nil, err
}

// And the anchor spemdable by the remote node.
// And the anchor spendable by the remote node.
remoteAnchor, err := anchorScript(remoteChanCfg.MultiSigKey.PubKey)
if err != nil {
return nil, nil, err
Expand Down