Skip to content

lnrpc+lnwallet+funding: implement new RPCs to enable external channel funding#3722

Merged
Roasbeef merged 5 commits into
lightningnetwork:masterfrom
Roasbeef:external-funding-rpc
Dec 23, 2019
Merged

lnrpc+lnwallet+funding: implement new RPCs to enable external channel funding#3722
Roasbeef merged 5 commits into
lightningnetwork:masterfrom
Roasbeef:external-funding-rpc

Conversation

@Roasbeef
Copy link
Copy Markdown
Member

In this commit, we start to expose some of the new external funding
functionality over the RPC interface.

First, we add a new funding_shim field to the regular OpenChannel
method. This can be used by a caller to express that certain parameters
of the funding flow have already been negotiated outside the protocol,
and should be used instead. For example, a shim can be provided to use a
particular key for the commitment key (ideally cold) rather than use one
this is generated by the wallet as normal, or signal that signing will
be carried out in an interactive manner (PSBT based).

Next, we add a brand new method: FundingStateStep. FundingStateStep is
an advanced funding related call that allows the caller to either
execute some preparatory steps for a funding workflow, or manually
progress a funding workflow. The primary way a funding flow is
identified is via its pending channel ID. As an example, this method can
be used to specify that we're expecting a funding flow for a particular
pending channel ID, for which we need to use specific parameters.
Alternatively, this can be used to interactively drive PSBT signing for
funding for partially complete funding transactions.

The new transition methods (funding state machine modifiers) in this
commit allow a party to register a funding intent that should be used
for a specified incoming pending channel ID. The "responder" to the
external channel flow should use this to prep lnd to be able to handle
the channel flow properly.

NOTE: this is an early version of the PR without additional tests in order to get early feedback on the proposed cut outs to enable a class of external channel funding useful in channel factory like contexts.

This builds on #3659.

@Roasbeef Roasbeef requested review from guggero and wpaulino and removed request for cfromknecht and halseth November 14, 2019 05:03
@Roasbeef Roasbeef added funding Related to the opening of new channels with funding transactions on the blockchain rpc Related to the RPC interface v0.9.0 labels Nov 14, 2019
Comment thread lnrpc/rpc.proto Outdated
@Roasbeef
Copy link
Copy Markdown
Member Author

Oh also only the last two commits are new.

Copy link
Copy Markdown
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Very nice to see that an involved change like this has such a small API surface.

Comment thread lnrpc/rpc.proto Outdated
Comment thread lnrpc/rpc.proto Outdated
Comment thread lnrpc/rpc.proto Outdated
Comment thread lnrpc/rpc.proto Outdated
Comment thread lnrpc/rpc.proto Outdated
@joostjager joostjager added this to the 0.9.0 milestone Nov 18, 2019
Comment thread fundingmanager.go Outdated
@halseth halseth self-requested a review November 26, 2019 20:22
Comment thread rpcserver.go Outdated
Comment thread rpcserver.go Outdated
Comment thread rpcserver.go Outdated
Comment thread rpcserver.go Outdated
@Roasbeef Roasbeef force-pushed the external-funding-rpc branch from 4e1c104 to dc92f9f Compare December 3, 2019 00:23
@Roasbeef
Copy link
Copy Markdown
Member Author

Roasbeef commented Dec 3, 2019

Updated to be based off of master, won't build yet though until the next push.

@Roasbeef Roasbeef force-pushed the external-funding-rpc branch from dc92f9f to 4a01028 Compare December 7, 2019 04:45
@Roasbeef Roasbeef requested review from guggero and halseth December 7, 2019 04:45
@Roasbeef
Copy link
Copy Markdown
Member Author

Roasbeef commented Dec 7, 2019

Will add an itest, then this should be ready for final review.

Copy link
Copy Markdown
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Looks almost ready to me, great work! I think an itest would be very valuable indeed.
The RPC API looks good to me, it can easily be extended (with the oneof in place) but is quite minimal for this first iteration.
The requested changes are around input validation only.

Comment thread rpcserver.go Outdated
Comment thread fundingmanager.go Outdated
Comment thread rpcserver.go Outdated
@Roasbeef Roasbeef force-pushed the external-funding-rpc branch 3 times, most recently from 2600450 to d25e32f Compare December 11, 2019 04:05
@Roasbeef
Copy link
Copy Markdown
Member Author

New integration tests pushed! Along the way, I had to copy over the KeyLocator and KeyDescriptor structs in order to avoid an import cycle with the signrpc package. An alternative is just to move all the new RPC calls to a sub-server otherwise....

@Roasbeef Roasbeef requested a review from guggero December 11, 2019 04:06
Copy link
Copy Markdown
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice itest!
The linter complains but apart from that, the PR looks good to me. The other comments are just nits.

Comment thread rpcserver.go Outdated
Comment thread rpcserver.go Outdated
Comment thread rpcserver.go Outdated
Comment thread rpcserver.go Outdated
@Roasbeef Roasbeef force-pushed the external-funding-rpc branch 2 times, most recently from 09c95d7 to b04ee32 Compare December 12, 2019 03:14
Copy link
Copy Markdown
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me! Only main comment is about having separate RPCs for the funding state step instead of dealing with oneofs.

Comment thread rpcserver.go Outdated
Comment thread lntest/itest/lnd_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a more realistic test would be to publish the funding tx first after the commitment was properly signed

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.

Sure but we don't have the capabilities to do something like that easily using the current RPC system for both lnd and the miner. There's an internal memWallet in the main btcd harness we can expose for this, but this set gives us a full run through either way. This method only broadcasts the transaction, it's still mined as normal in the regular basic funding tests.

Comment thread lntest/itest/lnd_test.go Outdated
Comment thread lntest/itest/lnd_test.go Outdated
Comment thread lnrpc/rpc.proto Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the rational behind having a oneof here, instead of just two RPC endpoints? Seems simpler not having to deal with the oneonf, and the switch in the implementation.

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.

That would mean a new RPC method for each new funding variation we think of in the future. This instead presents a set of distinct triggers similar to how we do things in the contract court.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SGTM

Comment thread rpcserver.go Outdated
Comment thread rpcserver.go Outdated
@Roasbeef Roasbeef force-pushed the external-funding-rpc branch from b04ee32 to 34ef876 Compare December 14, 2019 03:30
Comment thread fundingmanager.go Outdated
Comment thread rpcserver.go Outdated
Comment thread lnwallet/wallet.go Outdated
Comment thread rpcserver.go Outdated
Comment thread lnwallet/chanfunding/canned_assembler.go Outdated
Comment thread lntest/itest/lnd_test.go Outdated
Comment thread lntest/itest/lnd_test.go Outdated
@Roasbeef Roasbeef force-pushed the external-funding-rpc branch 2 times, most recently from 5a85a64 to 8bffcc7 Compare December 21, 2019 01:15
…ng modifiers

In this commit, we start to expose some of the new external funding
functionality over the RPC interface.

First, we add a new `funding_shim` field to the regular `OpenChannel`
method. This can be used by a caller to express that certain parameters
of the funding flow have already been negotiated outside the protocol,
and should be used instead. For example, a shim can be provided to use a
particular key for the commitment key (ideally cold) rather than use one
this is generated by the wallet as normal, or signal that signing will
be carried out in an interactive manner (PSBT based).

Next, we add a brand new method: `FundingStateStep`. FundingStateStep is
an advanced funding related call that allows the caller to either
execute some preparatory steps for a funding workflow, or manually
progress a funding workflow. The primary way a funding flow is
identified is via its pending channel ID. As an example, this method can
be used to specify that we're expecting a funding flow for a particular
pending channel ID, for which we need to use specific parameters.
Alternatively, this can be used to interactively drive PSBT signing for
funding for partially complete funding transactions.

The new transition methods (funding state machine modifiers) in this
commit allow a party to register a funding intent that should be used
for a specified incoming pending channel ID. The "responder" to the
external channel flow should use this to prep lnd to be able to handle
the channel flow properly.
In this commit, we update the `OpenChannel` method to observe the new
`funding_shim` field in the main open channel request. If this is
specified, and is a channel point shim, then we'll create a custom
`chanfunding.Assembler` for the wallet to use in place of the regular
funding workflow.

With this commit, the "initiator" of an external funding flow can now
delegate the remainder of the channel funding workflow to lnd.
In this commit, we implement the currently defined transition methods
for the new `FundingStateStep` method. At this point, we're now able to
serve the "responder" of the externally initiated channel funding flow
by being able to register and cancel a funding flow according to its
expected pending channel ID.
@Roasbeef Roasbeef force-pushed the external-funding-rpc branch from 8bffcc7 to 3de3ec8 Compare December 21, 2019 03:11
Copy link
Copy Markdown
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

This PR LGTM now 💯 Excited about the possibilities this opens up 💪

@Roasbeef Roasbeef merged commit 7eacc40 into lightningnetwork:master Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

funding Related to the opening of new channels with funding transactions on the blockchain rpc Related to the RPC interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants