Skip to content

Commit 97a5415

Browse files
committed
rpc: fix ordering of feature bit check in rpcCommitmentType
We need to check if it has a tapsript root first, as if it has a tapscript root, then it's also a taproot channel. By checking if it has a tapscript root first, we'll now display the proper commitment type for RPC responses.
1 parent 1b353b0 commit 97a5415

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

rpcserver.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -4547,12 +4547,12 @@ func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType {
45474547
// first check whether it has anchors, since in that case it would also
45484548
// be tweakless.
45494549
switch {
4550-
case chanType.IsTaproot():
4551-
return lnrpc.CommitmentType_SIMPLE_TAPROOT
4552-
45534550
case chanType.HasTapscriptRoot():
45544551
return lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY
45554552

4553+
case chanType.IsTaproot():
4554+
return lnrpc.CommitmentType_SIMPLE_TAPROOT
4555+
45564556
case chanType.HasLeaseExpiration():
45574557
return lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE
45584558

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

45624562
case chanType.IsTweakless():
45634563
return lnrpc.CommitmentType_STATIC_REMOTE_KEY
4564+
45644565
default:
45654566

45664567
return lnrpc.CommitmentType_LEGACY

rpcserver_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,53 @@ func TestAuxDataParser(t *testing.T) {
7777
require.NotNil(t, resp)
7878
require.Equal(t, []byte{0x00, 0x00}, resp.CustomChannelData)
7979
}
80+
81+
// TestRpcCommitmentType tests the rpcCommitmentType returns the corect
82+
// commitment type given a channel type.
83+
func TestRpcCommitmentType(t *testing.T) {
84+
tests := []struct {
85+
name string
86+
chanType channeldb.ChannelType
87+
want lnrpc.CommitmentType
88+
}{
89+
{
90+
name: "tapscript overlay",
91+
chanType: channeldb.SimpleTaprootFeatureBit |
92+
channeldb.TapscriptRootBit,
93+
want: lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY,
94+
},
95+
{
96+
name: "simple taproot",
97+
chanType: channeldb.SimpleTaprootFeatureBit,
98+
want: lnrpc.CommitmentType_SIMPLE_TAPROOT,
99+
},
100+
{
101+
name: "lease expiration",
102+
chanType: channeldb.LeaseExpirationBit,
103+
want: lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE,
104+
},
105+
{
106+
name: "anchors",
107+
chanType: channeldb.AnchorOutputsBit,
108+
want: lnrpc.CommitmentType_ANCHORS,
109+
},
110+
{
111+
name: "tweakless",
112+
chanType: channeldb.SingleFunderTweaklessBit,
113+
want: lnrpc.CommitmentType_STATIC_REMOTE_KEY,
114+
},
115+
{
116+
name: "legacy",
117+
chanType: channeldb.SingleFunderBit,
118+
want: lnrpc.CommitmentType_LEGACY,
119+
},
120+
}
121+
122+
for _, tt := range tests {
123+
t.Run(tt.name, func(t *testing.T) {
124+
require.Equal(
125+
t, tt.want, rpcCommitmentType(tt.chanType),
126+
)
127+
})
128+
}
129+
}

0 commit comments

Comments
 (0)