Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

funding: fund channel with selected utxos #7516

Merged
merged 8 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions cmd/lncli/cmd_open_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ var openChannelCommand = cli.Command{
"channel. This must not be set at the same " +
"time as local_amt",
},
cli.StringSliceFlag{
Name: "utxo",
Usage: "a utxo specified as outpoint(tx:idx) which " +
"will be used to fund a channel. This flag " +
"can be repeatedly used to fund a channel " +
"with a selection of utxos. The selected " +
"funds can either be entirely spent by " +
"specifying the fundmax flag or partially by " +
"selecting a fraction of the sum of the " +
"outpoints in local_amt",
},
cli.Uint64Flag{
Name: "base_fee_msat",
Usage: "the base fee in milli-satoshis that will " +
Expand Down Expand Up @@ -391,6 +402,17 @@ func openChannel(ctx *cli.Context) error {
"to commit the maximum amount out of the wallet")
}

if ctx.IsSet("utxo") {
utxos := ctx.StringSlice("utxo")

outpoints, err := utxosToOutpoints(utxos)
if err != nil {
return fmt.Errorf("unable to decode utxos: %w", err)
}

req.Outpoints = outpoints
}

if ctx.IsSet("push_amt") {
req.PushSat = int64(ctx.Int("push_amt"))
} else if args.Present() {
Expand Down Expand Up @@ -1109,3 +1131,21 @@ func decodePsbt(psbt string) ([]byte, error) {
return nil, fmt.Errorf("not a PSBT")
}
}

// parseUtxos parses a comma separated list of utxos into outpoints that are
// passed to the server.
func utxosToOutpoints(utxos []string) ([]*lnrpc.OutPoint, error) {
var outpoints []*lnrpc.OutPoint
if len(utxos) == 0 {
return nil, fmt.Errorf("no utxos specified")
}
for _, utxo := range utxos {
outpoint, err := NewProtoOutPoint(utxo)
if err != nil {
return nil, err
}
outpoints = append(outpoints, outpoint)
}

return outpoints, nil
}
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.17.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ on the old value of 10000](https://github.com/lightningnetwork/lnd/pull/7780).
key scopes. The non-deterministic behaviours linked to this case are fixed,
and users can no longer create two custom accounts with the same name.

* `OpenChannel` adds a new `utxo` flag that allows the specification of multiple
UTXOs [as a basis for funding a channel
opening.](https://github.com/lightningnetwork/lnd/pull/7516)

## Misc

* [Generate default macaroons
Expand Down
9 changes: 9 additions & 0 deletions funding/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ type InitFundingMsg struct {
// minimum amount to commit to.
MinFundAmt btcutil.Amount

// Outpoints is a list of client-selected outpoints that should be used
// for funding a channel. If LocalFundingAmt is specified then this
// amount is allocated from the sum of outpoints towards funding. If
// the FundUpToMaxAmt is specified the entirety of selected funds is
// allocated towards channel funding.
Outpoints []wire.OutPoint

// ChanFunder is an optional channel funder that allows the caller to
// control exactly how the channel funding is carried out. If not
// specified, then the default chanfunding.WalletAssembler will be
Expand Down Expand Up @@ -3973,6 +3980,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
maxHtlcs = msg.MaxHtlcs
maxCSV = msg.MaxLocalCsv
chanReserve = msg.RemoteChanReserve
outpoints = msg.Outpoints
)

// If no maximum CSV delay was set for this channel, we use our default
Expand Down Expand Up @@ -4101,6 +4109,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
FundUpToMaxAmt: msg.FundUpToMaxAmt,
MinFundAmt: msg.MinFundAmt,
RemoteChanReserve: chanReserve,
Outpoints: outpoints,
CommitFeePerKw: commitFeePerKw,
FundingFeePerKw: msg.FundingFeePerKw,
PushMSat: msg.PushAmt,
Expand Down
4 changes: 4 additions & 0 deletions itest/list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,8 @@ var allTestCases = []*lntest.TestCase{
Name: "custom features",
TestFunc: testCustomFeatures,
},
{
Name: "utxo selection funding",
TestFunc: testChannelUtxoSelection,
},
}
Loading