chains+server: if not in simnet mode, use BtcdFeeEstimator

This commit is contained in:
Olaoluwa Osuntokun 2017-11-23 13:36:12 -06:00
parent 5a51600f95
commit ad364ae9a1
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
3 changed files with 28 additions and 2 deletions

@ -22,6 +22,7 @@ import (
"github.com/lightningnetwork/lnd/routing/chainview" "github.com/lightningnetwork/lnd/routing/chainview"
"github.com/roasbeef/btcd/chaincfg/chainhash" "github.com/roasbeef/btcd/chaincfg/chainhash"
"github.com/roasbeef/btcd/rpcclient" "github.com/roasbeef/btcd/rpcclient"
"github.com/roasbeef/btcutil"
"github.com/roasbeef/btcwallet/chain" "github.com/roasbeef/btcwallet/chain"
"github.com/roasbeef/btcwallet/walletdb" "github.com/roasbeef/btcwallet/walletdb"
) )
@ -268,6 +269,27 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
} }
walletConfig.ChainSource = chainRPC walletConfig.ChainSource = chainRPC
// If we're not in simnet mode, then we'll attempt to use a
// proper fee estimator for testnet.
if !cfg.Bitcoin.SimNet && !cfg.Litecoin.SimNet {
ltndLog.Infof("Initializing btcd backed fee estimator")
// Finally, we'll re-initialize the fee estimator, as
// if we're using btcd as a backend, then we can use
// live fee estimates, rather than a statically coded
// value.
fallBackFeeRate := btcutil.Amount(25)
cc.feeEstimator, err = lnwallet.NewBtcdFeeEstimator(
*rpcConfig, fallBackFeeRate,
)
if err != nil {
return nil, nil, err
}
if err := cc.feeEstimator.Start(); err != nil {
return nil, nil, err
}
}
} }
wc, err := btcwallet.New(*walletConfig) wc, err := btcwallet.New(*walletConfig)

@ -841,7 +841,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
// TODO(roasbeef): actually get the active channel // TODO(roasbeef): actually get the active channel
// instead too? // instead too?
// * so only need to grab from database // * so only need to grab from database
peer.WipeChannel(channel) peer.WipeChannel(channel.ChannelPoint())
} else { } else {
chanID := lnwire.NewChanIDFromOutPoint(channel.ChannelPoint()) chanID := lnwire.NewChanIDFromOutPoint(channel.ChannelPoint())
r.server.htlcSwitch.RemoveLink(chanID) r.server.htlcSwitch.RemoveLink(chanID)

@ -20,6 +20,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing" "github.com/lightningnetwork/lnd/routing"
"github.com/roasbeef/btcd/blockchain"
"github.com/roasbeef/btcd/btcec" "github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash" "github.com/roasbeef/btcd/chaincfg/chainhash"
"github.com/roasbeef/btcd/connmgr" "github.com/roasbeef/btcd/connmgr"
@ -329,7 +330,7 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
closureType htlcswitch.ChannelCloseType) { closureType htlcswitch.ChannelCloseType) {
// TODO(conner): Properly respect the update and error channels // TODO(conner): Properly respect the update and error channels
// returned by CloseLink. // returned by CloseLink.
s.htlcSwitch.CloseLink(chanPoint, closureType) s.htlcSwitch.CloseLink(chanPoint, closureType, 0)
} }
s.breachArbiter = newBreachArbiter(&BreachConfig{ s.breachArbiter = newBreachArbiter(&BreachConfig{
@ -454,6 +455,7 @@ func (s *server) Stop() error {
s.cc.wallet.Shutdown() s.cc.wallet.Shutdown()
s.cc.chainView.Stop() s.cc.chainView.Stop()
s.connMgr.Stop() s.connMgr.Stop()
s.cc.feeEstimator.Stop()
// Disconnect from each active peers to ensure that // Disconnect from each active peers to ensure that
// peerTerminationWatchers signal completion to each peer. // peerTerminationWatchers signal completion to each peer.
@ -1435,6 +1437,8 @@ type openChanReq struct {
pushAmt lnwire.MilliSatoshi pushAmt lnwire.MilliSatoshi
fundingFeePerWeight btcutil.Amount
// TODO(roasbeef): add ability to specify channel constraints as well // TODO(roasbeef): add ability to specify channel constraints as well
updates chan *lnrpc.OpenStatusUpdate updates chan *lnrpc.OpenStatusUpdate