mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
funding+utxonursery+breacharbiter: use new FeeEstimator API
This commit is contained in:
parent
ad364ae9a1
commit
a3cd248404
@ -35,7 +35,7 @@ const (
|
|||||||
// maxFundingAmount is a soft-limit of the maximum channel size
|
// maxFundingAmount is a soft-limit of the maximum channel size
|
||||||
// accepted within the Lightning Protocol Currently. This limit is
|
// accepted within the Lightning Protocol Currently. This limit is
|
||||||
// currently defined in BOLT-0002, and serves as an initial
|
// currently defined in BOLT-0002, and serves as an initial
|
||||||
// precaturioary limit while implementations are battle tested in the
|
// precautionary limit while implementations are battle tested in the
|
||||||
// real world.
|
// real world.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): add command line param to modify
|
// TODO(roasbeef): add command line param to modify
|
||||||
@ -2017,23 +2017,25 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||||||
ourDustLimit)
|
ourDustLimit)
|
||||||
|
|
||||||
// First, we'll query the fee estimator for a fee that should get the
|
// First, we'll query the fee estimator for a fee that should get the
|
||||||
// commitment transaction into the next block (conf target of 1). We
|
// commitment transaction confirmed by the next few blocks (conf target
|
||||||
// target the next block here to ensure that we'll be able to execute a
|
// of 3). We target the near blocks here to ensure that we'll be able
|
||||||
// timely unilateral channel closure if needed.
|
// to execute a timely unilateral channel closure if needed.
|
||||||
//
|
feePerWeight, err := f.cfg.FeeEstimator.EstimateFeePerWeight(3)
|
||||||
// TODO(roasbeef): shouldn't be targeting next block
|
if err != nil {
|
||||||
feePerWeight := btcutil.Amount(f.cfg.FeeEstimator.EstimateFeePerWeight(1))
|
msg.err <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// The protocol currently operates on the basis of fee-per-kw, so we'll
|
// The protocol currently operates on the basis of fee-per-kw, so we'll
|
||||||
// multiply the computed sat/weight by 1000 to arrive at fee-per-kw.
|
// multiply the computed sat/weight by 1000 to arrive at fee-per-kw.
|
||||||
feePerKw := feePerWeight * 1000
|
commitFeePerKw := feePerWeight * 1000
|
||||||
|
|
||||||
// Initialize a funding reservation with the local wallet. If the
|
// Initialize a funding reservation with the local wallet. If the
|
||||||
// wallet doesn't have enough funds to commit to this channel, then the
|
// wallet doesn't have enough funds to commit to this channel, then the
|
||||||
// request will fail, and be aborted.
|
// request will fail, and be aborted.
|
||||||
reservation, err := f.cfg.Wallet.InitChannelReservation(capacity,
|
reservation, err := f.cfg.Wallet.InitChannelReservation(capacity,
|
||||||
localAmt, msg.pushAmt, feePerKw, peerKey,
|
localAmt, msg.pushAmt, commitFeePerKw, msg.fundingFeePerWeight,
|
||||||
msg.peerAddress.Address, &msg.chainHash)
|
peerKey, msg.peerAddress.Address, &msg.chainHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg.err <- err
|
msg.err <- err
|
||||||
return
|
return
|
||||||
@ -2043,8 +2045,8 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||||||
// reservation throughout its lifetime.
|
// reservation throughout its lifetime.
|
||||||
chanID := f.nextPendingChanID()
|
chanID := f.nextPendingChanID()
|
||||||
|
|
||||||
fndgLog.Infof("Target sat/kw for pendingID(%x): %v", chanID,
|
fndgLog.Infof("Target commit tx sat/kw for pendingID(%x): %v", chanID,
|
||||||
int64(feePerKw))
|
int64(commitFeePerKw))
|
||||||
|
|
||||||
// If a pending channel map for this peer isn't already created, then
|
// If a pending channel map for this peer isn't already created, then
|
||||||
// we create one, ultimately allowing us to track this pending
|
// we create one, ultimately allowing us to track this pending
|
||||||
@ -2089,7 +2091,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||||||
MaxValueInFlight: maxValue,
|
MaxValueInFlight: maxValue,
|
||||||
ChannelReserve: chanReserve,
|
ChannelReserve: chanReserve,
|
||||||
HtlcMinimum: ourContribution.MinHTLC,
|
HtlcMinimum: ourContribution.MinHTLC,
|
||||||
FeePerKiloWeight: uint32(feePerKw),
|
FeePerKiloWeight: uint32(commitFeePerKw),
|
||||||
CsvDelay: uint16(remoteCsvDelay),
|
CsvDelay: uint16(remoteCsvDelay),
|
||||||
MaxAcceptedHTLCs: maxHtlcs,
|
MaxAcceptedHTLCs: maxHtlcs,
|
||||||
FundingKey: ourContribution.MultiSigKey,
|
FundingKey: ourContribution.MultiSigKey,
|
||||||
|
4
mock.go
4
mock.go
@ -141,7 +141,9 @@ func (m *mockWalletController) NewRawKey() (*btcec.PublicKey, error) {
|
|||||||
func (m *mockWalletController) FetchRootKey() (*btcec.PrivateKey, error) {
|
func (m *mockWalletController) FetchRootKey() (*btcec.PrivateKey, error) {
|
||||||
return m.rootKey, nil
|
return m.rootKey, nil
|
||||||
}
|
}
|
||||||
func (*mockWalletController) SendOutputs(outputs []*wire.TxOut) (*chainhash.Hash, error) {
|
func (*mockWalletController) SendOutputs(outputs []*wire.TxOut,
|
||||||
|
_ btcutil.Amount) (*chainhash.Hash, error) {
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
pilot.go
7
pilot.go
@ -85,7 +85,12 @@ func (c *chanController) OpenChannel(target *btcec.PublicKey,
|
|||||||
|
|
||||||
// With the connection established, we'll now establish our connection
|
// With the connection established, we'll now establish our connection
|
||||||
// to the target peer, waiting for the first update before we exit.
|
// to the target peer, waiting for the first update before we exit.
|
||||||
updateStream, errChan := c.server.OpenChannel(-1, target, amt, 0)
|
feePerWeight, err := c.server.cc.feeEstimator.EstimateFeePerWeight(3)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
updateStream, errChan := c.server.OpenChannel(-1, target, amt, 0,
|
||||||
|
feePerWeight)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
|
@ -877,15 +877,18 @@ func (u *utxoNursery) sweepCsvSpendableOutputsTxn(txWeight uint64,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Using the txn weight estimate, compute the required txn fee.
|
// Using the txn weight estimate, compute the required txn fee.
|
||||||
feePerWeight := u.cfg.Estimator.EstimateFeePerWeight(1)
|
feePerWeight, err := u.cfg.Estimator.EstimateFeePerWeight(6)
|
||||||
txFee := btcutil.Amount(txWeight * feePerWeight)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
txFee := btcutil.Amount(txWeight) * feePerWeight
|
||||||
|
|
||||||
// Sweep as much possible, after subtracting txn fees.
|
// Sweep as much possible, after subtracting txn fees.
|
||||||
sweepAmt := int64(totalSum - txFee)
|
sweepAmt := int64(totalSum - txFee)
|
||||||
|
|
||||||
// Create the sweep transaction that we will be building. We use version
|
// Create the sweep transaction that we will be building. We use
|
||||||
// 2 as it is required for CSV. The txn will sweep the amount after fees
|
// version 2 as it is required for CSV. The txn will sweep the amount
|
||||||
// to the pkscript generated above.
|
// after fees to the pkscript generated above.
|
||||||
sweepTx := wire.NewMsgTx(2)
|
sweepTx := wire.NewMsgTx(2)
|
||||||
sweepTx.AddTxOut(&wire.TxOut{
|
sweepTx.AddTxOut(&wire.TxOut{
|
||||||
PkScript: pkScript,
|
PkScript: pkScript,
|
||||||
|
Loading…
Reference in New Issue
Block a user