lnwallet/btcwallet: properly pass in FeeEstimator to btcwallet

This commit fixes a bug wherein the wallet would use the default relay
fee to craft transactions. On testnet, this might be insufficient or be
rejected all together in a mainnet setting. Therefore, we now pass in
the FeeEstimator interface and ensure that it’s consulted in order to
set the relay fee the wallet will use to craft transactions.

Note that this is a hold over until we have true dynamic fee
calculation within lnd which can then be extended to the internal
wallets.
This commit is contained in:
Olaoluwa Osuntokun 2017-06-07 17:01:17 -07:00
parent 5adbc7fae3
commit dc40662770
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
3 changed files with 21 additions and 6 deletions

View File

@ -83,9 +83,10 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB) (*chainControl
estimator := lnwallet.StaticFeeEstimator{FeeRate: 50} estimator := lnwallet.StaticFeeEstimator{FeeRate: 50}
walletConfig := &btcwallet.Config{ walletConfig := &btcwallet.Config{
PrivatePass: []byte("hello"), PrivatePass: []byte("hello"),
DataDir: homeChainConfig.ChainDir, DataDir: homeChainConfig.ChainDir,
NetParams: activeNetParams.Params, NetParams: activeNetParams.Params,
FeeEstimator: estimator,
} }
cc := &chainControl{ cc := &chainControl{

View File

@ -108,6 +108,14 @@ func New(cfg Config) (*BtcWallet, error) {
return nil, err return nil, err
} }
// Using the passed fee estimator, we'll compute the relay fee for all
// transactions made which will be scaled up according to the size of a
// particular transaction.
//
// TODO(roasbeef): hook in dynamic relay fees
relayFee := cfg.FeeEstimator.EstimateFeePerByte(3) * 1000
wallet.SetRelayFee(btcutil.Amount(relayFee))
return &BtcWallet{ return &BtcWallet{
cfg: &cfg, cfg: &cfg,
wallet: wallet, wallet: wallet,
@ -123,7 +131,7 @@ func New(cfg Config) (*BtcWallet, error) {
// //
// This is a part of the WalletController interface. // This is a part of the WalletController interface.
func (b *BtcWallet) Start() error { func (b *BtcWallet) Start() error {
// Establish an RPC connection in additino to starting the goroutines // Establish an RPC connection in addition to starting the goroutines
// in the underlying wallet. // in the underlying wallet.
if err := b.chain.Start(); err != nil { if err := b.chain.Start(); err != nil {
return err return err
@ -465,7 +473,7 @@ func (b *BtcWallet) ListTransactionDetails() ([]*lnwallet.TransactionDetail, err
txDetails := make([]*lnwallet.TransactionDetail, 0, txDetails := make([]*lnwallet.TransactionDetail, 0,
len(txns.MinedTransactions)+len(txns.UnminedTransactions)) len(txns.MinedTransactions)+len(txns.UnminedTransactions))
// For both confirmed and unconfirme dtransactions, create a // For both confirmed and unconfirmed transactions, create a
// TransactionDetail which re-packages the data returned by the base // TransactionDetail which re-packages the data returned by the base
// wallet. // wallet.
for _, blockPackage := range txns.MinedTransactions { for _, blockPackage := range txns.MinedTransactions {

View File

@ -3,6 +3,7 @@ package btcwallet
import ( import (
"path/filepath" "path/filepath"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/roasbeef/btcd/chaincfg" "github.com/roasbeef/btcd/chaincfg"
"github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil" "github.com/roasbeef/btcutil"
@ -67,6 +68,11 @@ type Config struct {
// notifications for received funds, etc. // notifications for received funds, etc.
ChainSource chain.Interface ChainSource chain.Interface
// FeeEstimator is an instance of the fee estimator interface which
// will be used by the wallet to dynamically set transaction fees when
// crafting transactions.
FeeEstimator lnwallet.FeeEstimator
// NetParams is the net parameters for the target chain. // NetParams is the net parameters for the target chain.
NetParams *chaincfg.Params NetParams *chaincfg.Params
} }
@ -78,7 +84,7 @@ func networkDir(dataDir string, chainParams *chaincfg.Params) string {
// For now, we must always name the testnet data directory as "testnet" // For now, we must always name the testnet data directory as "testnet"
// and not "testnet3" or any other version, as the chaincfg testnet3 // and not "testnet3" or any other version, as the chaincfg testnet3
// paramaters will likely be switched to being named "testnet3" in the // parameters will likely be switched to being named "testnet3" in the
// future. This is done to future proof that change, and an upgrade // future. This is done to future proof that change, and an upgrade
// plan to move the testnet3 data directory can be worked out later. // plan to move the testnet3 data directory can be worked out later.
if chainParams.Net == wire.TestNet3 { if chainParams.Net == wire.TestNet3 {