multi: update to latest fee estimation interface

This commit is contained in:
Wilmer Paulino committed 2018-08-09 17:29:52 -07:00
1 parent a63677a381
commit 9d2eeb6304
21 files changed
+150 -204

No files matched your search

+4 -4
View File
@@ -272,11 +272,11 @@ func (b *BtcWallet) GetPrivKey(a btcutil.Address) (*btcec.PrivateKey, error) {
//
// This is a part of the WalletController interface.
func (b *BtcWallet) SendOutputs(outputs []*wire.TxOut,
feeRate lnwallet.SatPerVByte) (*chainhash.Hash, error) {
feeRate lnwallet.SatPerKWeight) (*chainhash.Hash, error) {
// The fee rate is passed in using units of sat/vbyte, so we'll scale
// this up to sat/KB as the SendOutputs method requires this unit.
feeSatPerKB := btcutil.Amount(feeRate * 1000)
// Convert our fee rate from sat/kw to sat/kb since it's required by
// SendOutputs.
feeSatPerKB := btcutil.Amount(feeRate.FeePerKVByte())
return b.wallet.SendOutputs(outputs, defaultAccount, 1, feeSatPerKB)
}
+2 -3
View File
@@ -1131,12 +1131,11 @@ func TestHTLCSigNumber(t *testing.T) {
}
// Calculate two values that will be below and above Bob's dust limit.
estimator := &StaticFeeEstimator{24}
feePerVSize, err := estimator.EstimateFeePerVSize(1)
estimator := &StaticFeeEstimator{FeePerKW: 6000}
feePerKw, err := estimator.EstimateFeePerKW(1)
if err != nil {
t.Fatalf("unable to get fee: %v", err)
}
feePerKw := feePerVSize.FeePerKWeight()
belowDust := btcutil.Amount(500) + htlcTimeoutFee(feePerKw)
aboveDust := btcutil.Amount(1400) + htlcSuccessFee(feePerKw)
+6 -6
View File
@@ -154,13 +154,13 @@ type WalletController interface {
// error should be returned.
GetPrivKey(a btcutil.Address) (*btcec.PrivateKey, error)
// SendOutputs funds, signs, and broadcasts a Bitcoin transaction
// paying out to the specified outputs. In the case the wallet has
// insufficient funds, or the outputs are non-standard, an error should
// be returned. This method also takes the target fee expressed in
// sat/vbyte that should be used when crafting the transaction.
// SendOutputs funds, signs, and broadcasts a Bitcoin transaction paying
// out to the specified outputs. In the case the wallet has insufficient
// funds, or the outputs are non-standard, an error should be returned.
// This method also takes the target fee expressed in sat/kw that should
// be used when crafting the transaction.
SendOutputs(outputs []*wire.TxOut,
feeRate SatPerVByte) (*chainhash.Hash, error)
feeRate SatPerKWeight) (*chainhash.Hash, error)
// ListUnspentWitness returns all unspent outputs which are version 0
// witness programs. The 'confirms' parameter indicates the minimum
+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)
}
@@ -471,14 +472,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)
@@ -491,9 +491,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")
}
@@ -508,28 +509,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",
@@ -560,7 +561,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)
@@ -570,15 +571,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)
@@ -597,14 +598,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 {
@@ -672,14 +676,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)
}
@@ -707,9 +711,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)
}
@@ -891,7 +896,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)
}
@@ -994,7 +999,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)
}
@@ -1108,7 +1113,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)
}
@@ -1308,7 +1313,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)
}
@@ -1553,7 +1558,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)
}
@@ -1679,7 +1684,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)
}
@@ -2073,7 +2078,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.
+2 -3
View File
@@ -229,12 +229,11 @@ func CreateTestChannels() (*LightningChannel, *LightningChannel, func(), error)
return nil, nil, nil, err
}
estimator := &StaticFeeEstimator{24}
feePerVSize, err := estimator.EstimateFeePerVSize(1)
estimator := &StaticFeeEstimator{FeePerKW: 6000}
feePerKw, err := estimator.EstimateFeePerKW(1)
if err != nil {
return nil, nil, nil, err
}
feePerKw := feePerVSize.FeePerKWeight()
commitFee := calcStaticFee(0)
aliceCommit := channeldb.ChannelCommitment{