From 80277c0517157d037bfa3caae77d2bfbe3d61b3c Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 13 Feb 2018 14:54:54 +0100 Subject: [PATCH] htlcswitch: use fee rate types instead of btcutil.Amount for fee rates --- htlcswitch/link.go | 17 ++++++++--------- htlcswitch/switch.go | 8 ++++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index e78eab0f9..89887a677 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -18,7 +18,6 @@ import ( "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" "github.com/roasbeef/btcd/chaincfg/chainhash" - "github.com/roasbeef/btcutil" ) 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 // this is the native rate used when computing the fee for commitment // transactions, and the second-level HTLC transactions. -func (l *channelLink) sampleNetworkFee() (btcutil.Amount, error) { - // We'll first query for the sat/weight recommended to be confirmed - // within 3blocks. - feePerWeight, err := l.cfg.FeeEstimator.EstimateFeePerWeight(3) +func (l *channelLink) sampleNetworkFee() (lnwallet.SatPerKWeight, error) { + // We'll first query for the sat/vbyte recommended to be confirmed + // within 3 blocks. + feePerVSize, err := l.cfg.FeeEstimator.EstimateFeePerVSize(3) if err != nil { return 0, err } // 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 "+ "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 // match that of the network fee. We'll only update our commitment fee if the // network fee is +/- 10% to our network fee. -func shouldAdjustCommitFee(netFee, chanFee btcutil.Amount) bool { +func shouldAdjustCommitFee(netFee, chanFee lnwallet.SatPerKWeight) bool { switch { // 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. @@ -1148,7 +1147,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) { case *lnwire.UpdateFee: // We received fee update from peer. If we are the initiator we // 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 { l.fail("error receiving fee update: %v", err) return @@ -1348,7 +1347,7 @@ func (l *channelLink) HandleChannelUpdate(message lnwire.Message) { // updateChannelFee updates the commitment fee-per-kw on this channel by // 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, feePerKw) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index fb46465d2..f1656f12e 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -81,7 +81,7 @@ type ChanClose struct { // This value is only utilized if the closure type is CloseRegular. // This will be the starting offered fee when the fee negotiation // 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 // 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, // then the last parameter should be the ideal fee-per-kw that will be used as // a starting point for close negotiation. -func (s *Switch) CloseLink(chanPoint *wire.OutPoint, - closeType ChannelCloseType, - targetFeePerKw btcutil.Amount) (chan *lnrpc.CloseStatusUpdate, chan error) { +func (s *Switch) CloseLink(chanPoint *wire.OutPoint, closeType ChannelCloseType, + targetFeePerKw lnwallet.SatPerKWeight) (chan *lnrpc.CloseStatusUpdate, + chan error) { // TODO(roasbeef) abstract out the close updates. updateChan := make(chan *lnrpc.CloseStatusUpdate, 2)