Skip to content

Commit 2395c4d

Browse files
committed
rpc+funding: add taproot overlay as RPC chan type
1 parent d72de4c commit 2395c4d

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

funding/manager_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4653,8 +4653,8 @@ func testZeroConf(t *testing.T, chanType *lnwire.ChannelType) {
46534653
// opening behavior with a specified fundmax flag. To give a hypothetical
46544654
// example, if ANCHOR types had been introduced after the fundmax flag had been
46554655
// activated, the developer would have had to code for the anchor reserve in the
4656-
// funding manager in the context of public and private channels. Otherwise
4657-
// inconsistent bahvior would have resulted when specifying fundmax for
4656+
// funding manager in the context of public and private channels. Otherwise,
4657+
// inconsistent behavior would have resulted when specifying fundmax for
46584658
// different types of channel openings.
46594659
// To ensure consistency this test compares a map of locally defined channel
46604660
// commitment types to the list of channel types that are defined in the proto
@@ -4670,6 +4670,7 @@ func TestCommitmentTypeFundmaxSanityCheck(t *testing.T) {
46704670
"ANCHORS": 3,
46714671
"SCRIPT_ENFORCED_LEASE": 4,
46724672
"SIMPLE_TAPROOT": 5,
4673+
"SIMPLE_TAPROOT_OVERLAY": 6,
46734674
}
46744675

46754676
for commitmentType := range lnrpc.CommitmentType_value {

rpcserver.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,29 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
23092309

23102310
*channelType = lnwire.ChannelType(*fv)
23112311

2312+
case lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY:
2313+
// If the taproot overlay channel type is being set, then the
2314+
// channel MUST be private.
2315+
if !in.Private {
2316+
return nil, fmt.Errorf("taproot overlay channels " +
2317+
"must be private")
2318+
}
2319+
2320+
channelType = new(lnwire.ChannelType)
2321+
fv := lnwire.NewRawFeatureVector(
2322+
lnwire.SimpleTaprootOverlayChansRequired,
2323+
)
2324+
2325+
if in.ZeroConf {
2326+
fv.Set(lnwire.ZeroConfRequired)
2327+
}
2328+
2329+
if in.ScidAlias {
2330+
fv.Set(lnwire.ScidAliasRequired)
2331+
}
2332+
2333+
*channelType = lnwire.ChannelType(*fv)
2334+
23122335
default:
23132336
return nil, fmt.Errorf("unhandled request channel type %v",
23142337
in.CommitmentType)
@@ -4533,6 +4556,9 @@ func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType {
45334556
// first check whether it has anchors, since in that case it would also
45344557
// be tweakless.
45354558
switch {
4559+
case chanType.HasTapscriptRoot():
4560+
return lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY
4561+
45364562
case chanType.IsTaproot():
45374563
return lnrpc.CommitmentType_SIMPLE_TAPROOT
45384564

@@ -4544,6 +4570,7 @@ func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType {
45444570

45454571
case chanType.IsTweakless():
45464572
return lnrpc.CommitmentType_STATIC_REMOTE_KEY
4573+
45474574
default:
45484575

45494576
return lnrpc.CommitmentType_LEGACY

rpcserver_test.go

Lines changed: 50 additions & 0 deletions
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)