mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-11 14:48:14 +01:00
htlcswitch: use fee rate types instead of btcutil.Amount for fee rates
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||||
"github.com/roasbeef/btcutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -387,16 +386,16 @@ func (l *channelLink) EligibleToForward() bool {
|
|||||||
// chain in a timely manner. The returned value is expressed in fee-per-kw, as
|
// chain in a timely manner. The returned value is expressed in fee-per-kw, as
|
||||||
// this is the native rate used when computing the fee for commitment
|
// this is the native rate used when computing the fee for commitment
|
||||||
// transactions, and the second-level HTLC transactions.
|
// transactions, and the second-level HTLC transactions.
|
||||||
func (l *channelLink) sampleNetworkFee() (btcutil.Amount, error) {
|
func (l *channelLink) sampleNetworkFee() (lnwallet.SatPerKWeight, error) {
|
||||||
// We'll first query for the sat/weight recommended to be confirmed
|
// We'll first query for the sat/vbyte recommended to be confirmed
|
||||||
// within 3blocks.
|
// within 3 blocks.
|
||||||
feePerWeight, err := l.cfg.FeeEstimator.EstimateFeePerWeight(3)
|
feePerVSize, err := l.cfg.FeeEstimator.EstimateFeePerVSize(3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Once we have this fee rate, we'll convert to sat-per-kw.
|
// Once we have this fee rate, we'll convert to sat-per-kw.
|
||||||
feePerKw := feePerWeight * 1000
|
feePerKw := feePerVSize.FeePerKWeight()
|
||||||
|
|
||||||
log.Debugf("ChannelLink(%v): sampled fee rate for 3 block conf: %v "+
|
log.Debugf("ChannelLink(%v): sampled fee rate for 3 block conf: %v "+
|
||||||
"sat/kw", l, int64(feePerKw))
|
"sat/kw", l, int64(feePerKw))
|
||||||
@@ -407,7 +406,7 @@ func (l *channelLink) sampleNetworkFee() (btcutil.Amount, error) {
|
|||||||
// shouldAdjustCommitFee returns true if we should update our commitment fee to
|
// shouldAdjustCommitFee returns true if we should update our commitment fee to
|
||||||
// match that of the network fee. We'll only update our commitment fee if the
|
// match that of the network fee. We'll only update our commitment fee if the
|
||||||
// network fee is +/- 10% to our network fee.
|
// network fee is +/- 10% to our network fee.
|
||||||
func shouldAdjustCommitFee(netFee, chanFee btcutil.Amount) bool {
|
func shouldAdjustCommitFee(netFee, chanFee lnwallet.SatPerKWeight) bool {
|
||||||
switch {
|
switch {
|
||||||
// If the network fee is greater than the commitment fee, then we'll
|
// If the network fee is greater than the commitment fee, then we'll
|
||||||
// switch to it if it's at least 10% greater than the commit fee.
|
// switch to it if it's at least 10% greater than the commit fee.
|
||||||
@@ -1148,7 +1147,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
|||||||
case *lnwire.UpdateFee:
|
case *lnwire.UpdateFee:
|
||||||
// We received fee update from peer. If we are the initiator we
|
// We received fee update from peer. If we are the initiator we
|
||||||
// will fail the channel, if not we will apply the update.
|
// will fail the channel, if not we will apply the update.
|
||||||
fee := btcutil.Amount(msg.FeePerKw)
|
fee := lnwallet.SatPerKWeight(msg.FeePerKw)
|
||||||
if err := l.channel.ReceiveUpdateFee(fee); err != nil {
|
if err := l.channel.ReceiveUpdateFee(fee); err != nil {
|
||||||
l.fail("error receiving fee update: %v", err)
|
l.fail("error receiving fee update: %v", err)
|
||||||
return
|
return
|
||||||
@@ -1348,7 +1347,7 @@ func (l *channelLink) HandleChannelUpdate(message lnwire.Message) {
|
|||||||
|
|
||||||
// updateChannelFee updates the commitment fee-per-kw on this channel by
|
// updateChannelFee updates the commitment fee-per-kw on this channel by
|
||||||
// committing to an update_fee message.
|
// committing to an update_fee message.
|
||||||
func (l *channelLink) updateChannelFee(feePerKw btcutil.Amount) error {
|
func (l *channelLink) updateChannelFee(feePerKw lnwallet.SatPerKWeight) error {
|
||||||
|
|
||||||
log.Infof("ChannelPoint(%v): updating commit fee to %v sat/kw", l,
|
log.Infof("ChannelPoint(%v): updating commit fee to %v sat/kw", l,
|
||||||
feePerKw)
|
feePerKw)
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ type ChanClose struct {
|
|||||||
// This value is only utilized if the closure type is CloseRegular.
|
// This value is only utilized if the closure type is CloseRegular.
|
||||||
// This will be the starting offered fee when the fee negotiation
|
// This will be the starting offered fee when the fee negotiation
|
||||||
// process for the cooperative closure transaction kicks off.
|
// process for the cooperative closure transaction kicks off.
|
||||||
TargetFeePerKw btcutil.Amount
|
TargetFeePerKw lnwallet.SatPerKWeight
|
||||||
|
|
||||||
// Updates is used by request creator to receive the notifications about
|
// Updates is used by request creator to receive the notifications about
|
||||||
// execution of the close channel request.
|
// execution of the close channel request.
|
||||||
@@ -741,9 +741,9 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
|||||||
// directing the specified closure type. If the closure type if CloseRegular,
|
// directing the specified closure type. If the closure type if CloseRegular,
|
||||||
// then the last parameter should be the ideal fee-per-kw that will be used as
|
// then the last parameter should be the ideal fee-per-kw that will be used as
|
||||||
// a starting point for close negotiation.
|
// a starting point for close negotiation.
|
||||||
func (s *Switch) CloseLink(chanPoint *wire.OutPoint,
|
func (s *Switch) CloseLink(chanPoint *wire.OutPoint, closeType ChannelCloseType,
|
||||||
closeType ChannelCloseType,
|
targetFeePerKw lnwallet.SatPerKWeight) (chan *lnrpc.CloseStatusUpdate,
|
||||||
targetFeePerKw btcutil.Amount) (chan *lnrpc.CloseStatusUpdate, chan error) {
|
chan error) {
|
||||||
|
|
||||||
// TODO(roasbeef) abstract out the close updates.
|
// TODO(roasbeef) abstract out the close updates.
|
||||||
updateChan := make(chan *lnrpc.CloseStatusUpdate, 2)
|
updateChan := make(chan *lnrpc.CloseStatusUpdate, 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user