Skip to content

Commit

Permalink
Merge pull request #7347 from Roasbeef/simple-taproot-chans-cli-rpc
Browse files Browse the repository at this point in the history
[8/?] - lncli+lnrpc: add support for creating unadvertised taproot channels
  • Loading branch information
Roasbeef committed Jul 27, 2023
2 parents dd8820d + 7598dae commit 96cceb1
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 418 deletions.
12 changes: 8 additions & 4 deletions cmd/lncli/cmd_open_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ Signed base64 encoded PSBT or hex encoded raw wire TX (or path to file): `
// of memory issues or other weird errors.
psbtMaxFileSize = 1024 * 1024

channelTypeTweakless = "tweakless"
channelTypeAnchors = "anchors"
channelTypeTweakless = "tweakless"
channelTypeAnchors = "anchors"
channelTypeSimpleTaproot = "taproot"
)

// TODO(roasbeef): change default number of confirmations.
Expand Down Expand Up @@ -230,8 +231,9 @@ var openChannelCommand = cli.Command{
cli.StringFlag{
Name: "channel_type",
Usage: fmt.Sprintf("(optional) the type of channel to "+
"propose to the remote peer (%q, %q)",
channelTypeTweakless, channelTypeAnchors),
"propose to the remote peer (%q, %q, %q)",
channelTypeTweakless, channelTypeAnchors,
channelTypeSimpleTaproot),
},
cli.BoolFlag{
Name: "zero_conf",
Expand Down Expand Up @@ -384,6 +386,8 @@ func openChannel(ctx *cli.Context) error {
req.CommitmentType = lnrpc.CommitmentType_STATIC_REMOTE_KEY
case channelTypeAnchors:
req.CommitmentType = lnrpc.CommitmentType_ANCHORS
case channelTypeSimpleTaproot:
req.CommitmentType = lnrpc.CommitmentType_SIMPLE_TAPROOT
default:
return fmt.Errorf("unsupported channel type %v", channelType)
}
Expand Down
8 changes: 8 additions & 0 deletions feature/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type Config struct {
// NoWumbo unsets any bits signalling support for wumbo channels.
NoWumbo bool

// NoTaprootChans unsets any bits signaling support for taproot
// channels.
NoTaprootChans bool

// NoScriptEnforcementLease unsets any bits signaling support for script
// enforced leases.
NoScriptEnforcementLease bool
Expand Down Expand Up @@ -150,6 +154,10 @@ func newManager(cfg Config, desc setDesc) (*Manager, error) {
raw.Unset(lnwire.ShutdownAnySegwitOptional)
raw.Unset(lnwire.ShutdownAnySegwitRequired)
}
if cfg.NoTaprootChans {
raw.Unset(lnwire.SimpleTaprootChannelsOptional)
raw.Unset(lnwire.SimpleTaprootChannelsRequired)
}

// Ensure that all of our feature sets properly set any
// dependent features.
Expand Down
4 changes: 4 additions & 0 deletions lncfg/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type ProtocolOptions struct {
// mini.
WumboChans bool `long:"wumbo-channels" description:"if set, then lnd will create and accept requests for channels larger chan 0.16 BTC"`

// TaprootChans should be set if we want to enable support for the
// experimental simple taproot chans commitment type.
TaprootChans bool `long:"taproot-chans" description:"if set, then lnd will create and accept requests for channels using the simple taproot commitment type"`

// NoAnchors should be set if we don't want to support opening or accepting
// channels having the anchor commitment type.
NoAnchors bool `long:"no-anchors" description:"disable support for anchor commitments"`
Expand Down
4 changes: 4 additions & 0 deletions lncfg/protocol_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type ProtocolOptions struct {
// mini.
WumboChans bool `long:"wumbo-channels" description:"if set, then lnd will create and accept requests for channels larger chan 0.16 BTC"`

// TaprootChans should be set if we want to enable support for the
// experimental simple taproot chans commitment type.
TaprootChans bool `long:"taproot-chans" description:"if set, then lnd will create and accept requests for channels using the simple taproot commitment type"`

// Anchors enables anchor commitments.
// TODO(halseth): transition itests to anchors instead!
Anchors bool `long:"anchors" description:"enable support for anchor commitments"`
Expand Down
815 changes: 410 additions & 405 deletions lnrpc/lightning.pb.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,13 @@ enum CommitmentType {
channel before its maturity date.
*/
SCRIPT_ENFORCED_LEASE = 4;

/*
A channel that uses musig2 for the funding output, and the new tapscript
features where relevant.
*/
// TODO(roasbeef): need script enforce mirror type for the above as well?
SIMPLE_TAPROOT = 5;
}

message ChannelConstraints {
Expand Down
5 changes: 3 additions & 2 deletions lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4209,10 +4209,11 @@
"LEGACY",
"STATIC_REMOTE_KEY",
"ANCHORS",
"SCRIPT_ENFORCED_LEASE"
"SCRIPT_ENFORCED_LEASE",
"SIMPLE_TAPROOT"
],
"default": "UNKNOWN_COMMITMENT_TYPE",
"description": " - UNKNOWN_COMMITMENT_TYPE: Returned when the commitment type isn't known or unavailable.\n - LEGACY: A channel using the legacy commitment format having tweaked to_remote\nkeys.\n - STATIC_REMOTE_KEY: A channel that uses the modern commitment format where the key in the\noutput of the remote party does not change each state. This makes back\nup and recovery easier as when the channel is closed, the funds go\ndirectly to that key.\n - ANCHORS: A channel that uses a commitment format that has anchor outputs on the\ncommitments, allowing fee bumping after a force close transaction has\nbeen broadcast.\n - SCRIPT_ENFORCED_LEASE: A channel that uses a commitment type that builds upon the anchors\ncommitment format, but in addition requires a CLTV clause to spend outputs\npaying to the channel initiator. This is intended for use on leased channels\nto guarantee that the channel initiator has no incentives to close a leased\nchannel before its maturity date."
"title": "- UNKNOWN_COMMITMENT_TYPE: Returned when the commitment type isn't known or unavailable.\n - LEGACY: A channel using the legacy commitment format having tweaked to_remote\nkeys.\n - STATIC_REMOTE_KEY: A channel that uses the modern commitment format where the key in the\noutput of the remote party does not change each state. This makes back\nup and recovery easier as when the channel is closed, the funds go\ndirectly to that key.\n - ANCHORS: A channel that uses a commitment format that has anchor outputs on the\ncommitments, allowing fee bumping after a force close transaction has\nbeen broadcast.\n - SCRIPT_ENFORCED_LEASE: A channel that uses a commitment type that builds upon the anchors\ncommitment format, but in addition requires a CLTV clause to spend outputs\npaying to the channel initiator. This is intended for use on leased channels\nto guarantee that the channel initiator has no incentives to close a leased\nchannel before its maturity date.\n - SIMPLE_TAPROOT: TODO(roasbeef): need script enforce mirror type for the above as well?"
},
"lnrpcConnectPeerRequest": {
"type": "object",
Expand Down
45 changes: 38 additions & 7 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2121,11 +2121,39 @@ 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)
}

// TODO(roasbeef): make taproot the default chan type?

// Instruct the server to trigger the necessary events to attempt to
// open a new channel. A stream is returned in place, this stream will
// be used to consume updates of the state of the pending channel.
Expand Down Expand Up @@ -4058,19 +4086,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
Expand Down
3 changes: 3 additions & 0 deletions sample-lnd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,9 @@ litecoin.node=ltcd
; closing.
; protocol.no-any-segwit

; Set to enable support for the experimental taproot channel type.
; protocol.taproot-chans

[db]

; The selected database backend. The current default backend is "bolt". lnd
Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
NoOptionScidAlias: !cfg.ProtocolOptions.ScidAlias(),
NoZeroConf: !cfg.ProtocolOptions.ZeroConf(),
NoAnySegwit: cfg.ProtocolOptions.NoAnySegwit(),
NoTaprootChans: !cfg.ProtocolOptions.TaprootChans,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 96cceb1

Please sign in to comment.