chainfee: create new chainfee package extracting fees from lnwallet

In this commit, we create a new chainfee package, that houses all fee
related functionality used within the codebase. The creation of this new
package furthers our long-term goal of extracting functionality from the
bloated `lnwallet` package into new distinct packages. Additionally,
this new packages resolves a class of import cycle that could arise if a
new package that was imported by something in `lnwallet` wanted to use
the existing fee related functions in the prior `lnwallet` package.
This commit is contained in:
Olaoluwa Osuntokun committed 2019-10-31 16:41:57 -07:00
1 parent fcf81ed8ff
commit 777ed104a3
47 files changed
+536 -400

No files matched your search

@@ -16,6 +16,7 @@ import (
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/watchtower/blob"
"github.com/lightningnetwork/lnd/watchtower/wtdb"
@@ -86,7 +87,7 @@ func genTaskTest(
toLocalAmt int64,
toRemoteAmt int64,
blobType blob.Type,
sweepFeeRate lnwallet.SatPerKWeight,
sweepFeeRate chainfee.SatPerKWeight,
rewardScript []byte,
expSweepAmt int64,
expRewardAmt int64,
+2 -2
View File
@@ -4,7 +4,7 @@ import (
"io"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/watchtower/blob"
"github.com/lightningnetwork/lnd/watchtower/wtpolicy"
)
@@ -58,7 +58,7 @@ func ReadElement(r io.Reader, element interface{}) error {
}
e.BlobType = blob.Type(blobType)
e.SweepFeeRate = lnwallet.SatPerKWeight(sweepFeeRate)
e.SweepFeeRate = chainfee.SatPerKWeight(sweepFeeRate)
// Type is still unknown to wtdb extensions, fail.
default:
+4 -3
View File
@@ -7,6 +7,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/watchtower/blob"
)
@@ -27,11 +28,11 @@ const (
// DefaultSweepFeeRate specifies the fee rate used to construct justice
// transactions. The value is expressed in satoshis per kilo-weight.
DefaultSweepFeeRate = lnwallet.SatPerKWeight(2500)
DefaultSweepFeeRate = chainfee.SatPerKWeight(2500)
// MinSweepFeeRate is the minimum sweep fee rate a client may use in its
// policy, the current value is 4 sat/vbyte.
MinSweepFeeRate = lnwallet.SatPerKWeight(1000)
MinSweepFeeRate = chainfee.SatPerKWeight(1000)
)
var (
@@ -97,7 +98,7 @@ type TxPolicy struct {
// constructing the justice transaction. All sweep transactions created
// for this session must use this value during construction, and the
// signatures must implicitly commit to the resulting output values.
SweepFeeRate lnwallet.SatPerKWeight
SweepFeeRate chainfee.SatPerKWeight
}
// Policy defines the negotiated parameters for a session between a client and
+2 -2
View File
@@ -3,7 +3,7 @@ package wtwire
import (
"io"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/watchtower/blob"
)
@@ -34,7 +34,7 @@ type CreateSession struct {
// constructing the justice transaction. All sweep transactions created
// for this session must use this value during construction, and the
// signatures must implicitly commit to the resulting output values.
SweepFeeRate lnwallet.SatPerKWeight
SweepFeeRate chainfee.SatPerKWeight
}
// A compile time check to ensure CreateSession implements the wtwire.Message
+4 -4
View File
@@ -8,7 +8,7 @@ import (
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/watchtower/blob"
)
@@ -74,7 +74,7 @@ func WriteElement(w io.Writer, element interface{}) error {
return err
}
case lnwallet.SatPerKWeight:
case chainfee.SatPerKWeight:
var b [8]byte
binary.BigEndian.PutUint64(b[:], uint64(e))
if _, err := w.Write(b[:]); err != nil {
@@ -194,12 +194,12 @@ func ReadElement(r io.Reader, element interface{}) error {
}
*e = bytes
case *lnwallet.SatPerKWeight:
case *chainfee.SatPerKWeight:
var b [8]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
return err
}
*e = lnwallet.SatPerKWeight(binary.BigEndian.Uint64(b[:]))
*e = chainfee.SatPerKWeight(binary.BigEndian.Uint64(b[:]))
case *ErrorCode:
var b [2]byte