Merge pull request #1644 from wpaulino/kw-fees

multi: switch to sat/kw fees
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2018-08-09 20:19:28 -07:00
commit d2612e51bd
28 files changed
+408 -446

No files matched your search

+53 -48
View File
@@ -186,7 +186,7 @@ func loadTestCredits(miner *rpctest.Harness, w *lnwallet.LightningWallet,
Value: int64(satoshiPerOutput),
PkScript: script,
}
if _, err := miner.SendOutputs([]*wire.TxOut{output}, 10); err != nil {
if _, err := miner.SendOutputs([]*wire.TxOut{output}, 2500); err != nil {
return err
}
}
@@ -249,7 +249,7 @@ func createTestWallet(tempTestDir string, miningNode *rpctest.Harness,
WalletController: wc,
Signer: signer,
ChainIO: bio,
FeeEstimator: lnwallet.StaticFeeEstimator{FeeRate: 10},
FeeEstimator: lnwallet.StaticFeeEstimator{FeePerKW: 2500},
DefaultConstraints: channeldb.ChannelConstraints{
DustLimit: 500,
MaxPendingAmount: lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin) * 100,
@@ -290,14 +290,14 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
// Alice initiates a channel funded with 5 BTC for each side, so 10 BTC
// total. She also generates 2 BTC in change.
feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
if err != nil {
t.Fatalf("unable to query fee estimator: %v", err)
}
feePerKw := feeRate.FeePerKWeight()
aliceChanReservation, err := alice.InitChannelReservation(
fundingAmount*2, fundingAmount, 0, feePerKw, feeRate,
bobPub, bobAddr, chainHash, lnwire.FFAnnounceChannel)
fundingAmount*2, fundingAmount, 0, feePerKw, feePerKw, bobPub,
bobAddr, chainHash, lnwire.FFAnnounceChannel,
)
if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err)
}
@@ -325,9 +325,10 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
// Bob does the same, generating his own contribution. He then also
// receives' Alice's contribution, and consumes that so we can continue
// the funding process.
bobChanReservation, err := bob.InitChannelReservation(fundingAmount*2,
fundingAmount, 0, feePerKw, feeRate, alicePub, aliceAddr,
chainHash, lnwire.FFAnnounceChannel)
bobChanReservation, err := bob.InitChannelReservation(
fundingAmount*2, fundingAmount, 0, feePerKw, feePerKw, alicePub,
aliceAddr, chainHash, lnwire.FFAnnounceChannel,
)
if err != nil {
t.Fatalf("bob unable to init channel reservation: %v", err)
}
@@ -476,14 +477,13 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
if err != nil {
t.Fatalf("unable to create amt: %v", err)
}
feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
if err != nil {
t.Fatalf("unable to query fee estimator: %v", err)
}
feePerKw := feeRate.FeePerKWeight()
_, err = alice.InitChannelReservation(fundingAmount,
fundingAmount, 0, feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel,
_, err = alice.InitChannelReservation(
fundingAmount, fundingAmount, 0, feePerKw, feePerKw, bobPub,
bobAddr, chainHash, lnwire.FFAnnounceChannel,
)
if err != nil {
t.Fatalf("unable to initialize funding reservation 1: %v", err)
@@ -496,9 +496,10 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
if err != nil {
t.Fatalf("unable to create amt: %v", err)
}
failedReservation, err := alice.InitChannelReservation(amt, amt, 0,
feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel)
failedReservation, err := alice.InitChannelReservation(
amt, amt, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel,
)
if err == nil {
t.Fatalf("not error returned, should fail on coin selection")
}
@@ -513,28 +514,28 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
alice, _ *lnwallet.LightningWallet, t *testing.T) {
feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
if err != nil {
t.Fatalf("unable to query fee estimator: %v", err)
}
feePerKw := feeRate.FeePerKWeight()
// Create a reservation for 44 BTC.
fundingAmount, err := btcutil.NewAmount(44)
if err != nil {
t.Fatalf("unable to create amt: %v", err)
}
chanReservation, err := alice.InitChannelReservation(fundingAmount,
fundingAmount, 0, feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel)
chanReservation, err := alice.InitChannelReservation(
fundingAmount, fundingAmount, 0, feePerKw, feePerKw, bobPub,
bobAddr, chainHash, lnwire.FFAnnounceChannel,
)
if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err)
}
// Attempt to create another channel with 44 BTC, this should fail.
_, err = alice.InitChannelReservation(fundingAmount,
fundingAmount, 0, feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel,
_, err = alice.InitChannelReservation(
fundingAmount, fundingAmount, 0, feePerKw, feePerKw, bobPub,
bobAddr, chainHash, lnwire.FFAnnounceChannel,
)
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
t.Fatalf("coin selection succeeded should have insufficient funds: %v",
@@ -565,7 +566,7 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
// Request to fund a new channel should now succeed.
_, err = alice.InitChannelReservation(fundingAmount, fundingAmount,
0, feePerKw, feeRate, bobPub, bobAddr, chainHash,
0, feePerKw, feePerKw, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel)
if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err)
@@ -575,15 +576,15 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
func testCancelNonExistentReservation(miner *rpctest.Harness,
alice, _ *lnwallet.LightningWallet, t *testing.T) {
feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
if err != nil {
t.Fatalf("unable to query fee estimator: %v", err)
}
// Create our own reservation, give it some ID.
res, err := lnwallet.NewChannelReservation(
10000, 10000, feeRate.FeePerKWeight(), alice,
22, 10, &testHdSeed, lnwire.FFAnnounceChannel,
10000, 10000, feePerKw, alice, 22, 10, &testHdSeed,
lnwire.FFAnnounceChannel,
)
if err != nil {
t.Fatalf("unable to create res: %v", err)
@@ -602,14 +603,17 @@ func testReservationInitiatorBalanceBelowDustCancel(miner *rpctest.Harness,
// We'll attempt to create a new reservation with an extremely high fee
// rate. This should push our balance into the negative and result in a
// failure to create the reservation.
fundingAmount, err := btcutil.NewAmount(4)
const numBTC = 4
fundingAmount, err := btcutil.NewAmount(numBTC)
if err != nil {
t.Fatalf("unable to create amt: %v", err)
}
feePerVSize := lnwallet.SatPerVByte(btcutil.SatoshiPerBitcoin * 4 / 100)
feePerKw := feePerVSize.FeePerKWeight()
feePerKw := lnwallet.SatPerKWeight(
numBTC * numBTC * btcutil.SatoshiPerBitcoin,
)
_, err = alice.InitChannelReservation(
fundingAmount, fundingAmount, 0, feePerKw, feePerVSize, bobPub,
fundingAmount, fundingAmount, 0, feePerKw, feePerKw, bobPub,
bobAddr, chainHash, lnwire.FFAnnounceChannel,
)
switch {
@@ -677,14 +681,14 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
t.Fatalf("unable to create amt: %v", err)
}
pushAmt := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
if err != nil {
t.Fatalf("unable to query fee estimator: %v", err)
}
feePerKw := feeRate.FeePerKWeight()
aliceChanReservation, err := alice.InitChannelReservation(fundingAmt,
fundingAmt, pushAmt, feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel)
aliceChanReservation, err := alice.InitChannelReservation(
fundingAmt, fundingAmt, pushAmt, feePerKw, feePerKw, bobPub,
bobAddr, chainHash, lnwire.FFAnnounceChannel,
)
if err != nil {
t.Fatalf("unable to init channel reservation: %v", err)
}
@@ -712,9 +716,10 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
// Next, Bob receives the initial request, generates a corresponding
// reservation initiation, then consume Alice's contribution.
bobChanReservation, err := bob.InitChannelReservation(fundingAmt, 0,
pushAmt, feePerKw, feeRate, alicePub, aliceAddr, chainHash,
lnwire.FFAnnounceChannel)
bobChanReservation, err := bob.InitChannelReservation(
fundingAmt, 0, pushAmt, feePerKw, feePerKw, alicePub, aliceAddr,
chainHash, lnwire.FFAnnounceChannel,
)
if err != nil {
t.Fatalf("unable to create bob reservation: %v", err)
}
@@ -901,7 +906,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
Value: outputAmt,
PkScript: script,
}
txid, err := miner.SendOutputs([]*wire.TxOut{output}, 10)
txid, err := miner.SendOutputs([]*wire.TxOut{output}, 2500)
if err != nil {
t.Fatalf("unable to send coinbase: %v", err)
}
@@ -1004,7 +1009,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
t.Fatalf("unable to make output script: %v", err)
}
burnOutput := wire.NewTxOut(outputAmt, outputScript)
burnTXID, err := alice.SendOutputs([]*wire.TxOut{burnOutput}, 10)
burnTXID, err := alice.SendOutputs([]*wire.TxOut{burnOutput}, 2500)
if err != nil {
t.Fatalf("unable to create burn tx: %v", err)
}
@@ -1118,7 +1123,7 @@ func testTransactionSubscriptions(miner *rpctest.Harness,
Value: outputAmt,
PkScript: script,
}
txid, err := miner.SendOutputs([]*wire.TxOut{output}, 10)
txid, err := miner.SendOutputs([]*wire.TxOut{output}, 2500)
if err != nil {
t.Fatalf("unable to send coinbase: %v", err)
}
@@ -1318,7 +1323,7 @@ func testPublishTransaction(r *rpctest.Harness,
Value: btcutil.SatoshiPerBitcoin,
PkScript: keyScript,
}
txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 10)
txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 2500)
if err != nil {
t.Fatalf("unable to create output: %v", err)
}
@@ -1563,7 +1568,7 @@ func testSignOutputUsingTweaks(r *rpctest.Harness,
Value: btcutil.SatoshiPerBitcoin,
PkScript: keyScript,
}
txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 10)
txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 2500)
if err != nil {
t.Fatalf("unable to create output: %v", err)
}
@@ -1689,7 +1694,7 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet,
Value: 1e8,
PkScript: script,
}
txid, err := w.SendOutputs([]*wire.TxOut{output}, 10)
txid, err := w.SendOutputs([]*wire.TxOut{output}, 2500)
if err != nil {
t.Fatalf("unable to send outputs: %v", err)
}
@@ -2083,7 +2088,7 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver,
}
case "neutrino":
feeEstimator = lnwallet.StaticFeeEstimator{FeeRate: 250}
feeEstimator = lnwallet.StaticFeeEstimator{FeePerKW: 62500}
// Set some package-level variable to speed up
// operation for tests.