lnwallet tests: update tests to new FeeEstimator and fee rate types

This commit is contained in:
Johan T. Halseth 2018-02-13 14:51:48 +01:00
parent 1f839d2526
commit d7834ca4eb
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
3 changed files with 69 additions and 65 deletions

@ -231,11 +231,11 @@ func createTestChannels(revocationWindow int) (*LightningChannel,
} }
estimator := &StaticFeeEstimator{24} estimator := &StaticFeeEstimator{24}
feePerWeight, err := estimator.EstimateFeePerWeight(1) feePerVSize, err := estimator.EstimateFeePerVSize(1)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
feePerKw := feePerWeight * 1000 feePerKw := feePerVSize.FeePerKWeight()
commitFee := calcStaticFee(0) commitFee := calcStaticFee(0)
aliceCommit := channeldb.ChannelCommitment{ aliceCommit := channeldb.ChannelCommitment{
@ -243,7 +243,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee), LocalBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal), RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal),
CommitFee: commitFee, CommitFee: commitFee,
FeePerKw: feePerKw, FeePerKw: btcutil.Amount(feePerKw),
CommitTx: aliceCommitTx, CommitTx: aliceCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71), CommitSig: bytes.Repeat([]byte{1}, 71),
} }
@ -252,7 +252,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal), LocalBalance: lnwire.NewMSatFromSatoshis(channelBal),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee), RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
CommitFee: commitFee, CommitFee: commitFee,
FeePerKw: feePerKw, FeePerKw: btcutil.Amount(feePerKw),
CommitTx: bobCommitTx, CommitTx: bobCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71), CommitSig: bytes.Repeat([]byte{1}, 71),
} }
@ -747,12 +747,12 @@ func TestCooperativeChannelClosure(t *testing.T) {
aliceDeliveryScript := bobsPrivKey[:] aliceDeliveryScript := bobsPrivKey[:]
bobDeliveryScript := testHdSeed[:] bobDeliveryScript := testHdSeed[:]
aliceFeeRate := uint64(aliceChannel.channelState.LocalCommitment.FeePerKw) aliceFeeRate := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
bobFeeRate := uint64(bobChannel.channelState.LocalCommitment.FeePerKw) bobFeeRate := SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw)
// We'll store with both Alice and Bob creating a new close proposal // We'll store with both Alice and Bob creating a new close proposal
// with the same fee. // with the same fee.
aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate)) aliceFee := aliceChannel.CalcFee(aliceFeeRate)
aliceSig, _, _, err := aliceChannel.CreateCloseProposal( aliceSig, _, _, err := aliceChannel.CreateCloseProposal(
aliceFee, aliceDeliveryScript, bobDeliveryScript, aliceFee, aliceDeliveryScript, bobDeliveryScript,
) )
@ -761,7 +761,7 @@ func TestCooperativeChannelClosure(t *testing.T) {
} }
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll)) aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate)) bobFee := bobChannel.CalcFee(bobFeeRate)
bobSig, _, _, err := bobChannel.CreateCloseProposal( bobSig, _, _, err := bobChannel.CreateCloseProposal(
bobFee, bobDeliveryScript, aliceDeliveryScript, bobFee, bobDeliveryScript, aliceDeliveryScript,
) )
@ -889,8 +889,8 @@ func TestForceClose(t *testing.T) {
// Factoring in the fee rate, Alice's amount should properly reflect // Factoring in the fee rate, Alice's amount should properly reflect
// that we've added two additional HTLC to the commitment transaction. // that we've added two additional HTLC to the commitment transaction.
totalCommitWeight := CommitWeight + (HtlcWeight * 2) totalCommitWeight := CommitWeight + (HtlcWeight * 2)
feePerKw := aliceChannel.channelState.LocalCommitment.FeePerKw feePerKw := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
commitFee := btcutil.Amount((int64(feePerKw) * totalCommitWeight) / 1000) commitFee := feePerKw.FeeForWeight(totalCommitWeight)
expectedAmount := (aliceChannel.Capacity / 2) - htlcAmount.ToSatoshis() - commitFee expectedAmount := (aliceChannel.Capacity / 2) - htlcAmount.ToSatoshis() - commitFee
if aliceCommitResolution.SelfOutputSignDesc.Output.Value != int64(expectedAmount) { if aliceCommitResolution.SelfOutputSignDesc.Output.Value != int64(expectedAmount) {
t.Fatalf("alice incorrect output value in SelfOutputSignDesc, "+ t.Fatalf("alice incorrect output value in SelfOutputSignDesc, "+
@ -1297,8 +1297,8 @@ func TestHTLCDustLimit(t *testing.T) {
// The amount of the HTLC should be above Alice's dust limit and below // The amount of the HTLC should be above Alice's dust limit and below
// Bob's dust limit. // Bob's dust limit.
htlcSat := (btcutil.Amount(500) + htlcSat := (btcutil.Amount(500) + htlcTimeoutFee(
htlcTimeoutFee(aliceChannel.channelState.LocalCommitment.FeePerKw)) SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)))
htlcAmount := lnwire.NewMSatFromSatoshis(htlcSat) htlcAmount := lnwire.NewMSatFromSatoshis(htlcSat)
htlc, preimage := createHTLC(0, htlcAmount) htlc, preimage := createHTLC(0, htlcAmount)
@ -1392,7 +1392,7 @@ func TestChannelBalanceDustLimit(t *testing.T) {
aliceBalance := aliceChannel.channelState.LocalCommitment.LocalBalance.ToSatoshis() aliceBalance := aliceChannel.channelState.LocalCommitment.LocalBalance.ToSatoshis()
htlcSat := aliceBalance - defaultFee htlcSat := aliceBalance - defaultFee
htlcSat += htlcSuccessFee( htlcSat += htlcSuccessFee(
aliceChannel.channelState.LocalCommitment.FeePerKw, SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw),
) )
htlcAmount := lnwire.NewMSatFromSatoshis(htlcSat) htlcAmount := lnwire.NewMSatFromSatoshis(htlcSat)
@ -1853,8 +1853,8 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
} }
defer cleanUp() defer cleanUp()
aliceFeeRate := uint64(aliceChannel.channelState.LocalCommitment.FeePerKw) aliceFeeRate := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
bobFeeRate := uint64(bobChannel.channelState.LocalCommitment.FeePerKw) bobFeeRate := SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw)
setDustLimit := func(dustVal btcutil.Amount) { setDustLimit := func(dustVal btcutil.Amount) {
aliceChannel.channelState.LocalChanCfg.DustLimit = dustVal aliceChannel.channelState.LocalChanCfg.DustLimit = dustVal
@ -2069,7 +2069,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
} }
// Simulate Alice sending update fee message to bob. // Simulate Alice sending update fee message to bob.
fee := btcutil.Amount(111) fee := SatPerKWeight(111)
aliceChannel.UpdateFee(fee) aliceChannel.UpdateFee(fee)
bobChannel.ReceiveUpdateFee(fee) bobChannel.ReceiveUpdateFee(fee)
@ -2089,7 +2089,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
t.Fatalf("bob unable to process alice's new commitment: %v", err) t.Fatalf("bob unable to process alice's new commitment: %v", err)
} }
if bobChannel.channelState.LocalCommitment.FeePerKw == fee { if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("bob's feePerKw was unexpectedly locked in") t.Fatalf("bob's feePerKw was unexpectedly locked in")
} }
@ -2100,7 +2100,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
t.Fatalf("unable to generate bob revocation: %v", err) t.Fatalf("unable to generate bob revocation: %v", err)
} }
if bobChannel.channelState.LocalCommitment.FeePerKw != fee { if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("bob's feePerKw was not locked in") t.Fatalf("bob's feePerKw was not locked in")
} }
@ -2125,7 +2125,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
t.Fatalf("alice unable to process bob's new commitment: %v", err) t.Fatalf("alice unable to process bob's new commitment: %v", err)
} }
if aliceChannel.channelState.LocalCommitment.FeePerKw == fee { if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("alice's feePerKw was unexpectedly locked in") t.Fatalf("alice's feePerKw was unexpectedly locked in")
} }
@ -2136,7 +2136,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
t.Fatalf("unable to revoke alice channel: %v", err) t.Fatalf("unable to revoke alice channel: %v", err)
} }
if aliceChannel.channelState.LocalCommitment.FeePerKw != fee { if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("alice's feePerKw was not locked in") t.Fatalf("alice's feePerKw was not locked in")
} }
@ -2181,7 +2181,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
} }
// Simulate Alice sending update fee message to bob // Simulate Alice sending update fee message to bob
fee := btcutil.Amount(111) fee := SatPerKWeight(111)
aliceChannel.UpdateFee(fee) aliceChannel.UpdateFee(fee)
bobChannel.ReceiveUpdateFee(fee) bobChannel.ReceiveUpdateFee(fee)
@ -2228,7 +2228,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
t.Fatalf("alice unable to process bob's new commitment: %v", err) t.Fatalf("alice unable to process bob's new commitment: %v", err)
} }
if bobChannel.channelState.LocalCommitment.FeePerKw == fee { if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("bob's feePerKw was unexpectedly locked in") t.Fatalf("bob's feePerKw was unexpectedly locked in")
} }
@ -2240,7 +2240,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
t.Fatalf("unable to revoke alice channel: %v", err) t.Fatalf("unable to revoke alice channel: %v", err)
} }
if bobChannel.channelState.LocalCommitment.FeePerKw != fee { if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("bob's feePerKw was not locked in") t.Fatalf("bob's feePerKw was not locked in")
} }
@ -2264,7 +2264,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
t.Fatalf("alice unable to process bob's new commitment: %v", err) t.Fatalf("alice unable to process bob's new commitment: %v", err)
} }
if aliceChannel.channelState.LocalCommitment.FeePerKw == fee { if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("alice's feePerKw was unexpectedly locked in") t.Fatalf("alice's feePerKw was unexpectedly locked in")
} }
@ -2275,7 +2275,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
t.Fatalf("unable to generate bob revocation: %v", err) t.Fatalf("unable to generate bob revocation: %v", err)
} }
if aliceChannel.channelState.LocalCommitment.FeePerKw != fee { if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("Alice's feePerKw was not locked in") t.Fatalf("Alice's feePerKw was not locked in")
} }
@ -2302,7 +2302,7 @@ func TestUpdateFeeReceiverSendsUpdate(t *testing.T) {
// Since Alice is the channel initiator, she should fail when receiving // Since Alice is the channel initiator, she should fail when receiving
// fee update // fee update
fee := btcutil.Amount(111) fee := SatPerKWeight(111)
err = aliceChannel.ReceiveUpdateFee(fee) err = aliceChannel.ReceiveUpdateFee(fee)
if err == nil { if err == nil {
t.Fatalf("expected alice to fail receiving fee update") t.Fatalf("expected alice to fail receiving fee update")
@ -2330,9 +2330,9 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
defer cleanUp() defer cleanUp()
// Simulate Alice sending update fee message to bob. // Simulate Alice sending update fee message to bob.
fee1 := btcutil.Amount(111) fee1 := SatPerKWeight(111)
fee2 := btcutil.Amount(222) fee2 := SatPerKWeight(222)
fee := btcutil.Amount(333) fee := SatPerKWeight(333)
aliceChannel.UpdateFee(fee1) aliceChannel.UpdateFee(fee1)
aliceChannel.UpdateFee(fee2) aliceChannel.UpdateFee(fee2)
aliceChannel.UpdateFee(fee) aliceChannel.UpdateFee(fee)
@ -2357,15 +2357,15 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
t.Fatalf("bob unable to process alice's new commitment: %v", err) t.Fatalf("bob unable to process alice's new commitment: %v", err)
} }
if bobChannel.channelState.LocalCommitment.FeePerKw == fee { if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("bob's feePerKw was unexpectedly locked in") t.Fatalf("bob's feePerKw was unexpectedly locked in")
} }
// Alice sending more fee updates now should not mess up the old fee // Alice sending more fee updates now should not mess up the old fee
// they both committed to. // they both committed to.
fee3 := btcutil.Amount(444) fee3 := SatPerKWeight(444)
fee4 := btcutil.Amount(555) fee4 := SatPerKWeight(555)
fee5 := btcutil.Amount(666) fee5 := SatPerKWeight(666)
aliceChannel.UpdateFee(fee3) aliceChannel.UpdateFee(fee3)
aliceChannel.UpdateFee(fee4) aliceChannel.UpdateFee(fee4)
aliceChannel.UpdateFee(fee5) aliceChannel.UpdateFee(fee5)
@ -2380,7 +2380,7 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
t.Fatalf("unable to generate bob revocation: %v", err) t.Fatalf("unable to generate bob revocation: %v", err)
} }
if bobChannel.channelState.LocalCommitment.FeePerKw != fee { if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("bob's feePerKw was not locked in") t.Fatalf("bob's feePerKw was not locked in")
} }
@ -2404,7 +2404,7 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
t.Fatalf("alice unable to process bob's new commitment: %v", err) t.Fatalf("alice unable to process bob's new commitment: %v", err)
} }
if aliceChannel.channelState.LocalCommitment.FeePerKw == fee { if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("alice's feePerKw was unexpectedly locked in") t.Fatalf("alice's feePerKw was unexpectedly locked in")
} }
@ -2415,7 +2415,7 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
t.Fatalf("unable to revoke alice channel: %v", err) t.Fatalf("unable to revoke alice channel: %v", err)
} }
if aliceChannel.channelState.LocalCommitment.FeePerKw != fee { if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("alice's feePerKw was not locked in") t.Fatalf("alice's feePerKw was not locked in")
} }
@ -3498,7 +3498,7 @@ func TestFeeUpdateRejectInsaneFee(t *testing.T) {
// Next, we'll try to add a fee rate to Alice which is 1,000,000x her // Next, we'll try to add a fee rate to Alice which is 1,000,000x her
// starting fee rate. // starting fee rate.
startingFeeRate := aliceChannel.channelState.LocalCommitment.FeePerKw startingFeeRate := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
newFeeRate := startingFeeRate * 1000000 newFeeRate := startingFeeRate * 1000000
// Both Alice and Bob should reject this new fee rate as it it far too // Both Alice and Bob should reject this new fee rate as it it far too
@ -3524,7 +3524,7 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
// First, we'll fetch the current fee rate present within the // First, we'll fetch the current fee rate present within the
// commitment transactions. // commitment transactions.
startingFeeRate := aliceChannel.channelState.LocalCommitment.FeePerKw startingFeeRate := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
// Next, we'll start a commitment update, with Alice sending a new // Next, we'll start a commitment update, with Alice sending a new
// update to double the fee rate of the commitment. // update to double the fee rate of the commitment.
@ -3664,10 +3664,10 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
} }
// Both parties should now have the latest fee rate locked-in. // Both parties should now have the latest fee rate locked-in.
if aliceChannel.channelState.LocalCommitment.FeePerKw != newFeeRate { if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) != newFeeRate {
t.Fatalf("alice's feePerKw was not locked in") t.Fatalf("alice's feePerKw was not locked in")
} }
if bobChannel.channelState.LocalCommitment.FeePerKw != newFeeRate { if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) != newFeeRate {
t.Fatalf("bob's feePerKw was not locked in") t.Fatalf("bob's feePerKw was not locked in")
} }

@ -283,13 +283,13 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
// Alice initiates a channel funded with 5 BTC for each side, so 10 BTC // Alice initiates a channel funded with 5 BTC for each side, so 10 BTC
// total. She also generates 2 BTC in change. // total. She also generates 2 BTC in change.
feePerWeight, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
if err != nil { if err != nil {
t.Fatalf("unable to query fee estimator: %v", err) t.Fatalf("unable to query fee estimator: %v", err)
} }
feePerKw := feePerWeight * 1000 feePerKw := feeRate.FeePerKWeight()
aliceChanReservation, err := alice.InitChannelReservation( aliceChanReservation, err := alice.InitChannelReservation(
fundingAmount*2, fundingAmount, 0, feePerKw, feePerKw, fundingAmount*2, fundingAmount, 0, feePerKw, feeRate,
bobPub, bobAddr, chainHash, lnwire.FFAnnounceChannel) bobPub, bobAddr, chainHash, lnwire.FFAnnounceChannel)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err) t.Fatalf("unable to initialize funding reservation: %v", err)
@ -313,7 +313,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
// receives' Alice's contribution, and consumes that so we can continue // receives' Alice's contribution, and consumes that so we can continue
// the funding process. // the funding process.
bobChanReservation, err := bob.InitChannelReservation(fundingAmount*2, bobChanReservation, err := bob.InitChannelReservation(fundingAmount*2,
fundingAmount, 0, feePerKw, feePerKw, alicePub, aliceAddr, fundingAmount, 0, feePerKw, feeRate, alicePub, aliceAddr,
chainHash, lnwire.FFAnnounceChannel) chainHash, lnwire.FFAnnounceChannel)
if err != nil { if err != nil {
t.Fatalf("bob unable to init channel reservation: %v", err) t.Fatalf("bob unable to init channel reservation: %v", err)
@ -449,13 +449,13 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
// Create a single channel asking for 16 BTC total. // Create a single channel asking for 16 BTC total.
fundingAmount := btcutil.Amount(8 * 1e8) fundingAmount := btcutil.Amount(8 * 1e8)
feePerWeight, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
if err != nil { if err != nil {
t.Fatalf("unable to query fee estimator: %v", err) t.Fatalf("unable to query fee estimator: %v", err)
} }
feePerKw := feePerWeight * 1000 feePerKw := feeRate.FeePerKWeight()
_, err = alice.InitChannelReservation(fundingAmount, _, err = alice.InitChannelReservation(fundingAmount,
fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash, fundingAmount, 0, feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel, lnwire.FFAnnounceChannel,
) )
if err != nil { if err != nil {
@ -467,7 +467,8 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
// that aren't locked, so this should fail. // that aren't locked, so this should fail.
amt := btcutil.Amount(900 * 1e8) amt := btcutil.Amount(900 * 1e8)
failedReservation, err := alice.InitChannelReservation(amt, amt, 0, failedReservation, err := alice.InitChannelReservation(amt, amt, 0,
feePerKw, feePerKw, bobPub, bobAddr, chainHash, lnwire.FFAnnounceChannel) feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel)
if err == nil { if err == nil {
t.Fatalf("not error returned, should fail on coin selection") t.Fatalf("not error returned, should fail on coin selection")
} }
@ -482,16 +483,16 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness, func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
alice, _ *lnwallet.LightningWallet, t *testing.T) { alice, _ *lnwallet.LightningWallet, t *testing.T) {
feePerWeight, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
if err != nil { if err != nil {
t.Fatalf("unable to query fee estimator: %v", err) t.Fatalf("unable to query fee estimator: %v", err)
} }
feePerKw := feePerWeight * 1000 feePerKw := feeRate.FeePerKWeight()
// Create a reservation for 44 BTC. // Create a reservation for 44 BTC.
fundingAmount := btcutil.Amount(44 * 1e8) fundingAmount := btcutil.Amount(44 * 1e8)
chanReservation, err := alice.InitChannelReservation(fundingAmount, chanReservation, err := alice.InitChannelReservation(fundingAmount,
fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash, fundingAmount, 0, feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel) lnwire.FFAnnounceChannel)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err) t.Fatalf("unable to initialize funding reservation: %v", err)
@ -499,7 +500,7 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
// Attempt to create another channel with 44 BTC, this should fail. // Attempt to create another channel with 44 BTC, this should fail.
_, err = alice.InitChannelReservation(fundingAmount, _, err = alice.InitChannelReservation(fundingAmount,
fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash, fundingAmount, 0, feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel, lnwire.FFAnnounceChannel,
) )
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok { if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
@ -530,8 +531,9 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
// attempting coin selection. // attempting coin selection.
// Request to fund a new channel should now succeed. // Request to fund a new channel should now succeed.
_, err = alice.InitChannelReservation(fundingAmount, fundingAmount, 0, _, err = alice.InitChannelReservation(fundingAmount, fundingAmount,
feePerKw, feePerKw, bobPub, bobAddr, chainHash, lnwire.FFAnnounceChannel) 0, feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err) t.Fatalf("unable to initialize funding reservation: %v", err)
} }
@ -540,14 +542,15 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
func testCancelNonExistentReservation(miner *rpctest.Harness, func testCancelNonExistentReservation(miner *rpctest.Harness,
alice, _ *lnwallet.LightningWallet, t *testing.T) { alice, _ *lnwallet.LightningWallet, t *testing.T) {
feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
if err != nil { if err != nil {
t.Fatalf("unable to query fee estimator: %v", err) t.Fatalf("unable to query fee estimator: %v", err)
} }
// Create our own reservation, give it some ID. // Create our own reservation, give it some ID.
res, err := lnwallet.NewChannelReservation( res, err := lnwallet.NewChannelReservation(
10000, 10000, feeRate, alice, 22, 10, &testHdSeed, lnwire.FFAnnounceChannel, 10000, 10000, feeRate.FeePerKWeight(), alice,
22, 10, &testHdSeed, lnwire.FFAnnounceChannel,
) )
if err != nil { if err != nil {
t.Fatalf("unable to create res: %v", err) t.Fatalf("unable to create res: %v", err)
@ -567,9 +570,10 @@ func testReservationInitiatorBalanceBelowDustCancel(miner *rpctest.Harness,
// rate. This should push our balance into the negative and result in a // rate. This should push our balance into the negative and result in a
// failure to create the reservation. // failure to create the reservation.
fundingAmount := btcutil.Amount(4 * 1e8) fundingAmount := btcutil.Amount(4 * 1e8)
feePerKw := btcutil.Amount(btcutil.SatoshiPerBitcoin * 10) feePerVSize := lnwallet.SatPerVByte(btcutil.SatoshiPerBitcoin * 4 / 100)
feePerKw := feePerVSize.FeePerKWeight()
_, err := alice.InitChannelReservation( _, err := alice.InitChannelReservation(
fundingAmount, fundingAmount, 0, feePerKw, feePerKw, bobPub, fundingAmount, fundingAmount, 0, feePerKw, feePerVSize, bobPub,
bobAddr, chainHash, lnwire.FFAnnounceChannel, bobAddr, chainHash, lnwire.FFAnnounceChannel,
) )
switch { switch {
@ -636,13 +640,13 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
// towards Bob's side. // towards Bob's side.
fundingAmt := btcutil.Amount(4 * 1e8) fundingAmt := btcutil.Amount(4 * 1e8)
pushAmt := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin) pushAmt := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
feePerWeight, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerVSize(1)
if err != nil { if err != nil {
t.Fatalf("unable to query fee estimator: %v", err) t.Fatalf("unable to query fee estimator: %v", err)
} }
feePerKw := feePerWeight * 1000 feePerKw := feeRate.FeePerKWeight()
aliceChanReservation, err := alice.InitChannelReservation(fundingAmt, aliceChanReservation, err := alice.InitChannelReservation(fundingAmt,
fundingAmt, pushAmt, feePerKw, feePerKw, bobPub, bobAddr, chainHash, fundingAmt, pushAmt, feePerKw, feeRate, bobPub, bobAddr, chainHash,
lnwire.FFAnnounceChannel) lnwire.FFAnnounceChannel)
if err != nil { if err != nil {
t.Fatalf("unable to init channel reservation: %v", err) t.Fatalf("unable to init channel reservation: %v", err)
@ -666,7 +670,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
// Next, Bob receives the initial request, generates a corresponding // Next, Bob receives the initial request, generates a corresponding
// reservation initiation, then consume Alice's contribution. // reservation initiation, then consume Alice's contribution.
bobChanReservation, err := bob.InitChannelReservation(fundingAmt, 0, bobChanReservation, err := bob.InitChannelReservation(fundingAmt, 0,
pushAmt, feePerKw, feePerKw, alicePub, aliceAddr, chainHash, pushAmt, feePerKw, feeRate, alicePub, aliceAddr, chainHash,
lnwire.FFAnnounceChannel) lnwire.FFAnnounceChannel)
if err != nil { if err != nil {
t.Fatalf("unable to create bob reservation: %v", err) t.Fatalf("unable to create bob reservation: %v", err)

@ -787,7 +787,7 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
height: test.commitment.CommitHeight, height: test.commitment.CommitHeight,
ourBalance: test.commitment.LocalBalance, ourBalance: test.commitment.LocalBalance,
theirBalance: test.commitment.RemoteBalance, theirBalance: test.commitment.RemoteBalance,
feePerKw: test.commitment.FeePerKw, feePerKw: SatPerKWeight(test.commitment.FeePerKw),
dustLimit: tc.dustLimit, dustLimit: tc.dustLimit,
isOurs: true, isOurs: true,
} }
@ -829,8 +829,8 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
// Generate second-level HTLC transactions for HTLCs in // Generate second-level HTLC transactions for HTLCs in
// commitment tx. // commitment tx.
htlcResolutions, err := extractHtlcResolutions( htlcResolutions, err := extractHtlcResolutions(
test.commitment.FeePerKw, true, signer, htlcs, keys, SatPerKWeight(test.commitment.FeePerKw), true, signer,
channel.localChanCfg, channel.remoteChanCfg, htlcs, keys, channel.localChanCfg, channel.remoteChanCfg,
commitTx.TxHash(), pCache, commitTx.TxHash(), pCache,
) )
if err != nil { if err != nil {