Add option to set remote channel reservation in open channel#2708
Add option to set remote channel reservation in open channel#2708roeierez wants to merge 5 commits intolightningnetwork:masterfrom
Conversation
2bfa980 to
be28948
Compare
|
Do you think it worth scheduling this PR for 0.7.1 release now that the channel reserve fields are in the RPC interface (#3238)? |
|
Can target for 0.8 possibly. |
That would be great! |
|
Needs a rebase. |
be28948 to
a108889
Compare
a108889 to
6a368e6
Compare
|
Rebased. |
Likely just a choice of wording here, but isn't dynamic, even with this it would still be fixed. Also this isn't costless, by setting this value to zero or near zero (as I'm guessing you'd like to do), you introduce a costless attack for who ever you open a channel with. |
Agree. Removed the word dynamically.
Right. To me, though, it looks like it is a business decision that shouldn't be limited by the protocol itself. Default value may remain 1%, but it is up to the initiator to change the value based on its business model. For example, Bitrefill offers their users to buy channels. In this case, users already have skin in the game. |
cfromknecht
left a comment
There was a problem hiding this comment.
looks pretty good on first pass!
fundingmanager.go
Outdated
There was a problem hiding this comment.
if i'm reading this correctly, we'll only use the user chosen reserve if it is at least the our dust limit. it doesn't seem obvious that it would be ignored if the value is too low. should we check this sooner in the pipeline and return an error?
There was a problem hiding this comment.
I agree. I have shifted the input validation code to rpcserver.go similar to the way other rpc fields are being validated: https://github.com/lightningnetwork/lnd/pull/2708/files#diff-01ada5680aaa18fc79cbf78b2d55a37bR1366
6a368e6 to
80e19f0
Compare
wpaulino
left a comment
There was a problem hiding this comment.
LGTM, though we should add some tests at the funding manager level with different values (valid and invalid).
server.go
Outdated
There was a problem hiding this comment.
Nit: move next to remoteCsvDelay?
Sounds good! I will work on that. |
85e8436 to
61d109c
Compare
|
@wpaulino I added tests for:
For the functionality to be testable I needed to add validation for the channel reserve inside the fundingmanager.go. |
|
This is no longer blocked by anchor outputs, and can be rebased. |
This commit is the basis of enabling the intiator of a channel to determine the amount of satoshis he requires the remote peer to reserve as a direct payment in his side of the channel As stated in Bolt 2.
This commit uses the "remote_chan_reserve_sat" field value that was added to the OpenChannelRequest in the funding workflow. Upon start of the workflow the handleInitFundingMsg code was changed to take this value into account, save it in the pending channel reservation and finally read the value when creating the channel constraints for the remote contribution in handleFundingAccept.
61d109c to
f1a7479
Compare
This commit adds the lncli support to configure the remote channel reservation value.
This commit adds validation for channel reserve custom parameter in the funding manager itself. Since opening a channel is not done only from the RPC interface, this validation makes sure callers won't pass a wrong value. It also makes the channel reserve functionality testable.
ea6e106 to
cf4e796
Compare
This commit adds three test cases for the remote channel reserve parameter: 1. custom valid value. 2. non valid value bellow dust. 3. non valid value over capacity.
cf4e796 to
d9c3f5d
Compare
| uint32 max_local_csv = 17; | ||
|
|
||
| // The number of satoshis we require the remote peer to reserve. | ||
| int64 remote_chan_reserve_sat = 18; |
| localFundingAmt btcutil.Amount) error { | ||
|
|
||
| dustLimit := lnwallet.DefaultDustLimit() | ||
| if chanReserve > 0 && chanReserve < dustLimit { |
There was a problem hiding this comment.
Nit: could omit the > 0 check if the proto type is unsigned.
| if chanReserve == 0 { | ||
| chanReserve = f.cfg.RequiredRemoteChanReserve(capacity, ourDustLimit) | ||
| } | ||
| if chanReserve < ourDustLimit { |
There was a problem hiding this comment.
We already have a similar check in CommitConstraints, though that doesn't check against the capacity.
| case <-alice.msgChan: | ||
| t.Fatalf("init funding workflow should fail with invalid chan"+ | ||
| "reserve %v", chanReserve) | ||
| case <-initReq.Err: |
There was a problem hiding this comment.
Should assert on the expected error here.
|
@roeierez still interested in getting this in? I can pick up review once its rebased. |
|
Would be great to see this in LND. LDK recently merged in a similar feature: lightningdevkit/rust-lightning#1163
@Roasbeef you could also look at this in reverse if the channel opener had big trust issues with their partner they could increase the reserve so more is at stake. This would make sense if the local capacities of both parties differs substantially. As @roeierez mentioned, this is more of a business feature (particularly for LSPs) but the default can stay at 1% and changes be opt-in only. |
|
@roeierez, remember to re-request review from reviewers when ready |
This PR adds the option for a channel initiator to set the “channel_reserve_satoshis”, as defined in Bolt 2 for open_channel message.
Before this change, the field was fixed to 1% of the channel capacity (the recommended value in Bolt 2).
It seems reasonable to allow the channel initiator to change this value if it is willing to take the risk (or responsibility) of watching and monitoring the channel on-chain.
With the ability to dynamically set the channel reserve, nodes will be able to provide the other side better liquidity, enabling them to spend more funds