lnwallet: NewChannelReservation now accepts target feePerKw for commitment

This commit is contained in:
Olaoluwa Osuntokun 2017-05-16 18:55:22 -07:00
parent 48850d31d6
commit 52942e4f13
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 27 additions and 13 deletions

@ -385,9 +385,11 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness, wallet *lnwallet
// Bob initiates a channel funded with 5 BTC for each side, so 10 // Bob initiates a channel funded with 5 BTC for each side, so 10
// BTC total. He also generates 2 BTC in change. // BTC total. He also generates 2 BTC in change.
feePerWeight := btcutil.Amount(wallet.FeeEstimator.EstimateFeePerWeight(1))
feePerKw := feePerWeight * 1000
chanReservation, err := wallet.InitChannelReservation(fundingAmount*2, chanReservation, err := wallet.InitChannelReservation(fundingAmount*2,
fundingAmount, bobNode.id, bobAddr, numReqConfs, 4, fundingAmount, bobNode.id, bobAddr, numReqConfs, 4,
lnwallet.DefaultDustLimit(), 0) lnwallet.DefaultDustLimit(), 0, feePerKw)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err) t.Fatalf("unable to initialize funding reservation: %v", err)
} }
@ -505,8 +507,11 @@ 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 := btcutil.Amount(wallet.FeeEstimator.EstimateFeePerWeight(1))
feePerKw := feePerWeight * 1000
_, err := wallet.InitChannelReservation(fundingAmount, fundingAmount, _, err := wallet.InitChannelReservation(fundingAmount, fundingAmount,
testPub, bobAddr, numReqConfs, 4, lnwallet.DefaultDustLimit(), 0) testPub, bobAddr, numReqConfs, 4, lnwallet.DefaultDustLimit(),
0, feePerKw)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation 1: %v", err) t.Fatalf("unable to initialize funding reservation 1: %v", err)
} }
@ -516,7 +521,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 := wallet.InitChannelReservation(amt, amt, failedReservation, err := wallet.InitChannelReservation(amt, amt,
testPub, bobAddr, numReqConfs, 4, lnwallet.DefaultDustLimit(), 0) testPub, bobAddr, numReqConfs, 4, lnwallet.DefaultDustLimit(),
0, feePerKw)
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")
} }
@ -533,11 +539,14 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
t.Log("Running funding insufficient funds tests") t.Log("Running funding insufficient funds tests")
feePerWeight := btcutil.Amount(wallet.FeeEstimator.EstimateFeePerWeight(1))
feePerKw := feePerWeight * 1000
// Create a reservation for 44 BTC. // Create a reservation for 44 BTC.
fundingAmount := btcutil.Amount(44 * 1e8) fundingAmount := btcutil.Amount(44 * 1e8)
chanReservation, err := wallet.InitChannelReservation(fundingAmount, chanReservation, err := wallet.InitChannelReservation(fundingAmount,
fundingAmount, testPub, bobAddr, numReqConfs, 4, fundingAmount, testPub, bobAddr, numReqConfs, 4,
lnwallet.DefaultDustLimit(), 0) lnwallet.DefaultDustLimit(), 0, feePerKw)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err) t.Fatalf("unable to initialize funding reservation: %v", err)
} }
@ -545,7 +554,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 = wallet.InitChannelReservation(fundingAmount, _, err = wallet.InitChannelReservation(fundingAmount,
fundingAmount, testPub, bobAddr, numReqConfs, 4, fundingAmount, testPub, bobAddr, numReqConfs, 4,
lnwallet.DefaultDustLimit(), 0) lnwallet.DefaultDustLimit(), 0, feePerKw)
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok { if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
t.Fatalf("coin selection succeded should have insufficient funds: %v", t.Fatalf("coin selection succeded should have insufficient funds: %v",
err) err)
@ -575,7 +584,8 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
// Request to fund a new channel should now succeed. // Request to fund a new channel should now succeed.
_, err = wallet.InitChannelReservation(fundingAmount, fundingAmount, _, err = wallet.InitChannelReservation(fundingAmount, fundingAmount,
testPub, bobAddr, numReqConfs, 4, lnwallet.DefaultDustLimit(), 0) testPub, bobAddr, numReqConfs, 4, lnwallet.DefaultDustLimit(),
0, feePerKw)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err) t.Fatalf("unable to initialize funding reservation: %v", err)
} }
@ -618,9 +628,11 @@ func testSingleFunderReservationWorkflowInitiator(miner *rpctest.Harness,
// side. // side.
fundingAmt := btcutil.Amount(4 * 1e8) fundingAmt := btcutil.Amount(4 * 1e8)
pushAmt := btcutil.Amount(btcutil.SatoshiPerBitcoin) pushAmt := btcutil.Amount(btcutil.SatoshiPerBitcoin)
feePerWeight := btcutil.Amount(wallet.FeeEstimator.EstimateFeePerWeight(1))
feePerKw := feePerWeight * 1000
chanReservation, err := wallet.InitChannelReservation(fundingAmt, chanReservation, err := wallet.InitChannelReservation(fundingAmt,
fundingAmt, bobNode.id, bobAddr, numReqConfs, 4, fundingAmt, bobNode.id, bobAddr, numReqConfs, 4,
lnwallet.DefaultDustLimit(), pushAmt) lnwallet.DefaultDustLimit(), pushAmt, feePerKw)
if err != nil { if err != nil {
t.Fatalf("unable to init channel reservation: %v", err) t.Fatalf("unable to init channel reservation: %v", err)
} }
@ -760,9 +772,11 @@ func testSingleFunderReservationWorkflowResponder(miner *rpctest.Harness,
// Bob sends over a single funding request, so we allocate our // Bob sends over a single funding request, so we allocate our
// contribution and the necessary resources. // contribution and the necessary resources.
fundingAmt := btcutil.Amount(0) fundingAmt := btcutil.Amount(0)
feePerWeight := btcutil.Amount(wallet.FeeEstimator.EstimateFeePerWeight(1))
feePerKw := feePerWeight * 1000
chanReservation, err := wallet.InitChannelReservation(capacity, chanReservation, err := wallet.InitChannelReservation(capacity,
fundingAmt, bobNode.id, bobAddr, numReqConfs, 4, fundingAmt, bobNode.id, bobAddr, numReqConfs, 4,
lnwallet.DefaultDustLimit(), 0) lnwallet.DefaultDustLimit(), 0, feePerKw)
if err != nil { if err != nil {
t.Fatalf("unable to init channel reservation: %v", err) t.Fatalf("unable to init channel reservation: %v", err)
} }

@ -145,9 +145,9 @@ type ChannelReservation struct {
// used only internally by lnwallet. In order to concurrent safety, the // used only internally by lnwallet. In order to concurrent safety, the
// creation of all channel reservations should be carried out via the // creation of all channel reservations should be carried out via the
// lnwallet.InitChannelReservation interface. // lnwallet.InitChannelReservation interface.
func NewChannelReservation(capacity, fundingAmt btcutil.Amount, minFeeRate btcutil.Amount, func NewChannelReservation(capacity, fundingAmt btcutil.Amount,
wallet *LightningWallet, id uint64, numConfs uint16, feePerKw btcutil.Amount, wallet *LightningWallet, id uint64,
pushSat btcutil.Amount) *ChannelReservation { numConfs uint16, pushSat btcutil.Amount) *ChannelReservation {
var ( var (
ourBalance btcutil.Amount ourBalance btcutil.Amount
@ -155,7 +155,7 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount, minFeeRate btcut
initiator bool initiator bool
) )
commitFee := minFeeRate * commitWeight / 1000 commitFee := (feePerKw * commitWeight) / 1000
// If we're the responder to a single-funder reservation, then we have // If we're the responder to a single-funder reservation, then we have
// no initial balance in the channel unless the remote party is pushing // no initial balance in the channel unless the remote party is pushing
@ -217,7 +217,7 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount, minFeeRate btcut
ChanType: chanType, ChanType: chanType,
OurBalance: ourBalance, OurBalance: ourBalance,
TheirBalance: theirBalance, TheirBalance: theirBalance,
MinFeePerKb: minFeeRate, FeePerKw: feePerKw,
Db: wallet.ChannelDB, Db: wallet.ChannelDB,
CommitFee: commitFee, CommitFee: commitFee,
}, },