-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
adds fundmax
flag to openchannel
#4029
Closed
bjarnemagnussen
wants to merge
8
commits into
lightningnetwork:master
from
bjarnemagnussen:fundall-flag
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bb40134
chanfunding: adds ability to fund up to some maximum amount
bjarnemagnussen 87b957a
lnrpc: adds a field `FundMax` to `OpenChannelRequest`
bjarnemagnussen e9a0c14
lnd: handles the `FundMax` field inside `parseOpenChannelReq`
bjarnemagnussen 2a2d6ca
lnd+lnwallet: adds `fundmax` flag to cli:openchannel
bjarnemagnussen 8276856
lntest/itest: adds tests for `fundmax` flag of cli:openchannel
bjarnemagnussen 3ac041f
lnd+funding: use Max- and MinChanSize as limits to fundmax
bjarnemagnussen 1a9f280
chanfunding: allow to set a reserved amount not used for funding
bjarnemagnussen 6d3de89
lnwallet: respect the reserved wallet balance when using fundmax
bjarnemagnussen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -650,7 +650,7 @@ func openChannel(t *testing.T, alice, bob *testNode, localFundingAmt, | |
*wire.OutPoint, *wire.MsgTx) { | ||
|
||
publ := fundChannel( | ||
t, alice, bob, localFundingAmt, pushAmt, false, numConfs, | ||
t, alice, bob, localFundingAmt, pushAmt, false, false, numConfs, | ||
updateChan, announceChan, | ||
) | ||
fundingOutPoint := &wire.OutPoint{ | ||
|
@@ -663,7 +663,7 @@ func openChannel(t *testing.T, alice, bob *testNode, localFundingAmt, | |
// fundChannel takes the funding process to the point where the funding | ||
// transaction is confirmed on-chain. Returns the funding tx. | ||
func fundChannel(t *testing.T, alice, bob *testNode, localFundingAmt, | ||
pushAmt btcutil.Amount, subtractFees bool, numConfs uint32, | ||
pushAmt btcutil.Amount, subtractFees, fundMax bool, numConfs uint32, // nolint:unparam | ||
updateChan chan *lnrpc.OpenStatusUpdate, announceChan bool) *wire.MsgTx { | ||
|
||
// Create a funding request and start the workflow. | ||
|
@@ -673,6 +673,7 @@ func fundChannel(t *testing.T, alice, bob *testNode, localFundingAmt, | |
TargetPubkey: bob.privKey.PubKey(), | ||
ChainHash: *fundingNetParams.GenesisHash, | ||
SubtractFees: subtractFees, | ||
FundMax: fundMax, | ||
LocalFundingAmt: localFundingAmt, | ||
PushAmt: lnwire.NewMSatFromSatoshis(pushAmt), | ||
FundingFeePerKw: 1000, | ||
|
@@ -3249,7 +3250,7 @@ func TestFundingManagerFundAll(t *testing.T) { | |
// Initiate a fund channel, and inspect the funding tx. | ||
pushAmt := btcutil.Amount(0) | ||
fundingTx := fundChannel( | ||
t, alice, bob, test.spendAmt, pushAmt, true, 1, | ||
t, alice, bob, test.spendAmt, pushAmt, true, false, 1, | ||
updateChan, true, | ||
) | ||
|
||
|
@@ -3280,6 +3281,94 @@ func TestFundingManagerFundAll(t *testing.T) { | |
} | ||
} | ||
|
||
// TestFundingManagerFundMax tests that we can initiate a funding request to | ||
// use the maximum allowed funds remaining in the wallet. | ||
func TestFundingManagerFundMax(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
coins []*lnwallet.Utxo | ||
change bool | ||
}{ | ||
{ | ||
// We will spend all the funds in the wallet, and | ||
// expects no change output. | ||
coins: []*lnwallet.Utxo{{ | ||
AddressType: lnwallet.WitnessPubKey, | ||
Value: MaxBtcFundingAmount + 1, | ||
PkScript: mock.CoinPkScript, | ||
OutPoint: wire.OutPoint{ | ||
Hash: chainhash.Hash{}, | ||
Index: 0, | ||
}, | ||
}}, | ||
change: false, | ||
}, | ||
{ | ||
// We spend less than the funds in the wallet, | ||
// so a change output should be created. | ||
coins: []*lnwallet.Utxo{{ | ||
AddressType: lnwallet.WitnessPubKey, | ||
Value: 2 * MaxBtcFundingAmount, | ||
PkScript: mock.CoinPkScript, | ||
OutPoint: wire.OutPoint{ | ||
Hash: chainhash.Hash{}, | ||
Index: 0, | ||
}, | ||
}}, | ||
change: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
// We set up our mock wallet to control a list of UTXOs that | ||
// sum to more than the max channel size. | ||
test := test | ||
addFunds := func(fundingCfg *Config) { | ||
wc := fundingCfg.Wallet.WalletController | ||
wc.(*mock.WalletController).Utxos = test.coins | ||
} | ||
alice, bob := setupFundingManagers(t, addFunds) | ||
defer tearDownFundingManagers(t, alice, bob) | ||
|
||
// We will consume the channel updates as we go, so no | ||
// buffering is needed. | ||
updateChan := make(chan *lnrpc.OpenStatusUpdate) | ||
|
||
// Initiate a fund channel, and inspect the funding tx. | ||
pushAmt := btcutil.Amount(0) | ||
fundingTx := fundChannel( | ||
t, alice, bob, MinChanFundingSize, pushAmt, false, true, | ||
1, updateChan, true, | ||
) | ||
|
||
// Check whether the expected change output is present. | ||
if test.change && len(fundingTx.TxOut) != 2 { | ||
t.Fatalf("expected 2 outputs, had %v", | ||
len(fundingTx.TxOut)) | ||
} | ||
|
||
if !test.change && len(fundingTx.TxOut) != 1 { | ||
t.Fatalf("expected 1 output, had %v", | ||
len(fundingTx.TxOut)) | ||
} | ||
|
||
// Inputs should be all funds in the wallet. | ||
if len(fundingTx.TxIn) != len(test.coins) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a test case with multiple inputs so this check actually does make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
t.Fatalf("Had %d inputs, expected %d", | ||
len(fundingTx.TxIn), len(test.coins)) | ||
} | ||
|
||
for i, txIn := range fundingTx.TxIn { | ||
if txIn.PreviousOutPoint != test.coins[i].OutPoint { | ||
t.Fatalf("expected outpoint to be %v, was %v", | ||
test.coins[i].OutPoint, | ||
txIn.PreviousOutPoint) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// TestGetUpfrontShutdown tests different combinations of inputs for getting a | ||
// shutdown script. It varies whether the peer has the feature set, whether | ||
// the user has provided a script and our local configuration to test that | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also test a pushamt greater than the MinChanFundingSize?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here 5e7d875#diff-97a234788862027c261c89226cdc9a681e96f8803888e57cdddfef9aad229da1R3459