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:
parent
5adbc7fae3
commit
dc40662770
@ -83,9 +83,10 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB) (*chainControl
|
||||
|
||||
estimator := lnwallet.StaticFeeEstimator{FeeRate: 50}
|
||||
walletConfig := &btcwallet.Config{
|
||||
PrivatePass: []byte("hello"),
|
||||
DataDir: homeChainConfig.ChainDir,
|
||||
NetParams: activeNetParams.Params,
|
||||
PrivatePass: []byte("hello"),
|
||||
DataDir: homeChainConfig.ChainDir,
|
||||
NetParams: activeNetParams.Params,
|
||||
FeeEstimator: estimator,
|
||||
}
|
||||
|
||||
cc := &chainControl{
|
||||
|
@ -108,6 +108,14 @@ func New(cfg Config) (*BtcWallet, error) {
|
||||
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{
|
||||
cfg: &cfg,
|
||||
wallet: wallet,
|
||||
@ -123,7 +131,7 @@ func New(cfg Config) (*BtcWallet, error) {
|
||||
//
|
||||
// This is a part of the WalletController interface.
|
||||
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.
|
||||
if err := b.chain.Start(); err != nil {
|
||||
return err
|
||||
@ -465,7 +473,7 @@ func (b *BtcWallet) ListTransactionDetails() ([]*lnwallet.TransactionDetail, err
|
||||
txDetails := make([]*lnwallet.TransactionDetail, 0,
|
||||
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
|
||||
// wallet.
|
||||
for _, blockPackage := range txns.MinedTransactions {
|
||||
|
@ -3,6 +3,7 @@ package btcwallet
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/roasbeef/btcd/chaincfg"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcutil"
|
||||
@ -67,6 +68,11 @@ type Config struct {
|
||||
// notifications for received funds, etc.
|
||||
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 *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"
|
||||
// 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
|
||||
// plan to move the testnet3 data directory can be worked out later.
|
||||
if chainParams.Net == wire.TestNet3 {
|
||||
|
Loading…
Reference in New Issue
Block a user