From 4aa9bba4ef98f34d42840d04838e87a32e0e3585 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 19 Jan 2023 20:42:06 -0800 Subject: [PATCH] rpc: update open channel parsing to detect taproot chans --- rpcserver.go | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 1b1aa40eb..646bc3046 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2142,6 +2142,32 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest, *channelType = lnwire.ChannelType(*fv) + case lnrpc.CommitmentType_SIMPLE_TAPROOT: + // If the taproot channel type is being set, then the channel + // MUST be private (unadvertised) for now. + if !in.Private { + return nil, fmt.Errorf("taproot channels must be " + + "private") + } + + channelType = new(lnwire.ChannelType) + fv := lnwire.NewRawFeatureVector( + lnwire.SimpleTaprootChannelsRequired, + ) + + // TODO(roasbeef): no need for the rest as they're now + // implicit? + + if in.ZeroConf { + fv.Set(lnwire.ZeroConfRequired) + } + + if in.ScidAlias { + fv.Set(lnwire.ScidAliasRequired) + } + + *channelType = lnwire.ChannelType(*fv) + default: return nil, fmt.Errorf("unhandled request channel type %v", in.CommitmentType) @@ -4146,19 +4172,22 @@ func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType { // Extract the commitment type from the channel type flags. We must // first check whether it has anchors, since in that case it would also // be tweakless. - if chanType.HasLeaseExpiration() { + switch { + case chanType.IsTaproot(): + return lnrpc.CommitmentType_SIMPLE_TAPROOT + + case chanType.HasLeaseExpiration(): return lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE - } - if chanType.HasAnchors() { + case chanType.HasAnchors(): return lnrpc.CommitmentType_ANCHORS - } - if chanType.IsTweakless() { + case chanType.IsTweakless(): return lnrpc.CommitmentType_STATIC_REMOTE_KEY - } + default: - return lnrpc.CommitmentType_LEGACY + return lnrpc.CommitmentType_LEGACY + } } // createChannelConstraint creates a *lnrpc.ChannelConstraints using the