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
7 changes: 4 additions & 3 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4547,12 +4547,12 @@ func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType {
// first check whether it has anchors, since in that case it would also
// be tweakless.
switch {
case chanType.IsTaproot():
return lnrpc.CommitmentType_SIMPLE_TAPROOT

case chanType.HasTapscriptRoot():
return lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY

case chanType.IsTaproot():
return lnrpc.CommitmentType_SIMPLE_TAPROOT

case chanType.HasLeaseExpiration():
return lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE

Expand All @@ -4561,6 +4561,7 @@ func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType {

case chanType.IsTweakless():
return lnrpc.CommitmentType_STATIC_REMOTE_KEY

default:

return lnrpc.CommitmentType_LEGACY
Expand Down
50 changes: 50 additions & 0 deletions rpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,53 @@ func TestAuxDataParser(t *testing.T) {
require.NotNil(t, resp)
require.Equal(t, []byte{0x00, 0x00}, resp.CustomChannelData)
}

// TestRpcCommitmentType tests the rpcCommitmentType returns the corect
// commitment type given a channel type.
func TestRpcCommitmentType(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

tests := []struct {
name string
chanType channeldb.ChannelType
want lnrpc.CommitmentType
}{
{
name: "tapscript overlay",
chanType: channeldb.SimpleTaprootFeatureBit |
channeldb.TapscriptRootBit,
want: lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY,
},
{
name: "simple taproot",
chanType: channeldb.SimpleTaprootFeatureBit,
want: lnrpc.CommitmentType_SIMPLE_TAPROOT,
},
{
name: "lease expiration",
chanType: channeldb.LeaseExpirationBit,
want: lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE,
},
{
name: "anchors",
chanType: channeldb.AnchorOutputsBit,
want: lnrpc.CommitmentType_ANCHORS,
},
{
name: "tweakless",
chanType: channeldb.SingleFunderTweaklessBit,
want: lnrpc.CommitmentType_STATIC_REMOTE_KEY,
},
{
name: "legacy",
chanType: channeldb.SingleFunderBit,
want: lnrpc.CommitmentType_LEGACY,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(
t, tt.want, rpcCommitmentType(tt.chanType),
)
})
}
}