Skip to content

Commit

Permalink
itest: enable anchor type for basic funding flow, force close test
Browse files Browse the repository at this point in the history
  • Loading branch information
halseth committed Mar 19, 2020
1 parent 20c9ad9 commit d142a3d
Showing 1 changed file with 51 additions and 18 deletions.
69 changes: 51 additions & 18 deletions lntest/itest/lnd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
allTypes := []commitType{
commitTypeLegacy,
commitTypeTweakless,
commitTypeAnchors,
}

test:
Expand Down Expand Up @@ -1210,27 +1211,58 @@ test:
t.Fatalf("failed funding flow: %v", err)
}

carolTweakless := carolCommitType == commitTypeTweakless
// Both nodes should report the same commitment
// type.
chansCommitType := carolChannel.CommitmentType
if daveChannel.CommitmentType != chansCommitType {
t.Fatalf("commit types don't match, "+
"carol got %v, dave got %v",
carolChannel.CommitmentType,
daveChannel.CommitmentType,
)
}

// Now check that the commitment type reported
// by both nodes is what we expect. It will be
// the minimum of the two nodes' preference, in
// the order Legacy, Tweakless, Anchors.
expType := carolCommitType

switch daveCommitType {

// Dave supports anchors, type will be what
// Carol supports.
case commitTypeAnchors:

// Dave only supports tweakless, channel will
// be downgraded to this type if Carol supports
// anchors.
case commitTypeTweakless:
if expType == commitTypeAnchors {
expType = commitTypeTweakless
}

// Dave only supoprts legacy type, channel will
// be downgraded to this type.
case commitTypeLegacy:
expType = commitTypeLegacy

daveTweakless := daveCommitType == commitTypeTweakless
default:
t.Fatalf("invalid commit type %v",
daveCommitType)
}

tweaklessSignalled := carolTweakless && daveTweakless
tweaklessChans := (carolChannel.StaticRemoteKey &&
daveChannel.StaticRemoteKey)
// Check that the signalled type match what we
// expect.
switch {
// If both sides signalled a tweakless channel, and the
// resulting channel doesn't reflect this, then this
// is a failed case.
case tweaklessSignalled && !tweaklessChans:
t.Fatalf("expected tweakless channnel, got " +
"non-tweaked channel")

// If both sides didn't signal a tweakless
// channel, and the resulting channel is
// tweakless, and this is also a failed case.
case !tweaklessSignalled && tweaklessChans:
t.Fatalf("expected non-tweaked channel, got " +
"tweakless channel")
case expType == commitTypeAnchors && chansCommitType == lnrpc.CommitmentType_ANCHORS:
case expType == commitTypeTweakless && chansCommitType == lnrpc.CommitmentType_STATIC_REMOTE_KEY:
case expType == commitTypeLegacy && chansCommitType == lnrpc.CommitmentType_LEGACY:

default:
t.Fatalf("expected nodes to signal "+
"commit type %v, instead got "+
"%v", expType, chansCommitType)
}

// As we've concluded this sub-test case we'll
Expand Down Expand Up @@ -3052,6 +3084,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
allTypes := []commitType{
commitTypeLegacy,
commitTypeTweakless,
commitTypeAnchors,
}

for _, channelType := range allTypes {
Expand Down

0 comments on commit d142a3d

Please sign in to comment.