wallet: remove internal relayFee in favor of passing in fee rate when sending

In this commit, we do away with the internal relayFee all together.
Instead, we’ll pass in the fee rate when we’re crafting any
transactions. This allows the caller to manually dictate their desired
fee rate.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-18 15:22:46 -08:00
parent 60b23c144e
commit 7b9d880fee
2 changed files with 12 additions and 30 deletions

View file

@ -101,7 +101,9 @@ func (s secretSource) GetScript(addr btcutil.Address) ([]byte, error) {
// UTXO set and minconf policy. An additional output may be added to return // UTXO set and minconf policy. An additional output may be added to return
// change to the wallet. An appropriate fee is included based on the wallet's // change to the wallet. An appropriate fee is included based on the wallet's
// current relay fee. The wallet must be unlocked to create the transaction. // current relay fee. The wallet must be unlocked to create the transaction.
func (w *Wallet) txToOutputs(outputs []*wire.TxOut, account uint32, minconf int32) (tx *txauthor.AuthoredTx, err error) { func (w *Wallet) txToOutputs(outputs []*wire.TxOut, account uint32,
minconf int32, feeSatPerKb btcutil.Amount) (tx *txauthor.AuthoredTx, err error) {
chainClient, err := w.requireChainClient() chainClient, err := w.requireChainClient()
if err != nil { if err != nil {
return nil, err return nil, err
@ -137,7 +139,7 @@ func (w *Wallet) txToOutputs(outputs []*wire.TxOut, account uint32, minconf int3
} }
return txscript.PayToAddrScript(changeAddr) return txscript.PayToAddrScript(changeAddr)
} }
tx, err = txauthor.NewUnsignedTransaction(outputs, w.RelayFee(), tx, err = txauthor.NewUnsignedTransaction(outputs, feeSatPerKb,
inputSource, changeSource) inputSource, changeSource)
if err != nil { if err != nil {
return err return err

View file

@ -75,8 +75,6 @@ type Wallet struct {
chainClientSyncMtx sync.Mutex chainClientSyncMtx sync.Mutex
lockedOutpoints map[wire.OutPoint]struct{} lockedOutpoints map[wire.OutPoint]struct{}
relayFee btcutil.Amount
relayFeeMu sync.Mutex
// Channels for rescan processing. Requests are added and merged with // Channels for rescan processing. Requests are added and merged with
// any waiting requests, before being sent to another goroutine to // any waiting requests, before being sent to another goroutine to
@ -205,23 +203,6 @@ func (w *Wallet) ChainClient() chain.Interface {
return chainClient return chainClient
} }
// RelayFee returns the current minimum relay fee (per kB of serialized
// transaction) used when constructing transactions.
func (w *Wallet) RelayFee() btcutil.Amount {
w.relayFeeMu.Lock()
relayFee := w.relayFee
w.relayFeeMu.Unlock()
return relayFee
}
// SetRelayFee sets a new minimum relay fee (per kB of serialized
// transaction) used when constructing transactions.
func (w *Wallet) SetRelayFee(relayFee btcutil.Amount) {
w.relayFeeMu.Lock()
w.relayFee = relayFee
w.relayFeeMu.Unlock()
}
// quitChan atomically reads the quit channel. // quitChan atomically reads the quit channel.
func (w *Wallet) quitChan() <-chan struct{} { func (w *Wallet) quitChan() <-chan struct{} {
w.quitMu.Lock() w.quitMu.Lock()
@ -532,6 +513,7 @@ type (
account uint32 account uint32
outputs []*wire.TxOut outputs []*wire.TxOut
minconf int32 minconf int32
feeSatPerKB btcutil.Amount
resp chan createTxResponse resp chan createTxResponse
} }
createTxResponse struct { createTxResponse struct {
@ -562,7 +544,7 @@ out:
continue continue
} }
tx, err := w.txToOutputs(txr.outputs, txr.account, tx, err := w.txToOutputs(txr.outputs, txr.account,
txr.minconf) txr.minconf, txr.feeSatPerKB)
heldUnlock.release() heldUnlock.release()
txr.resp <- createTxResponse{tx, err} txr.resp <- createTxResponse{tx, err}
case <-quit: case <-quit:
@ -2318,16 +2300,15 @@ func (w *Wallet) TotalReceivedForAddr(addr btcutil.Address, minConf int32) (btcu
// SendOutputs creates and sends payment transactions. It returns the // SendOutputs creates and sends payment transactions. It returns the
// transaction hash upon success. // transaction hash upon success.
func (w *Wallet) SendOutputs(outputs []*wire.TxOut, account uint32, func (w *Wallet) SendOutputs(outputs []*wire.TxOut, account uint32,
minconf int32) (*chainhash.Hash, error) { minconf int32, satPerKb btcutil.Amount) (*chainhash.Hash, error) {
chainClient, err := w.requireChainClient() chainClient, err := w.requireChainClient()
if err != nil { if err != nil {
return nil, err return nil, err
} }
relayFee := w.RelayFee()
for _, output := range outputs { for _, output := range outputs {
err = txrules.CheckOutput(output, relayFee) err = txrules.CheckOutput(output, satPerKb)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2658,7 +2639,6 @@ func Open(db walletdb.DB, pubPass []byte, cbs *waddrmgr.OpenCallbacks, params *c
Manager: addrMgr, Manager: addrMgr,
TxStore: txMgr, TxStore: txMgr,
lockedOutpoints: map[wire.OutPoint]struct{}{}, lockedOutpoints: map[wire.OutPoint]struct{}{},
relayFee: txrules.DefaultRelayFeePerKb,
rescanAddJob: make(chan *RescanJob), rescanAddJob: make(chan *RescanJob),
rescanBatch: make(chan *rescanBatch), rescanBatch: make(chan *rescanBatch),
rescanNotifications: make(chan interface{}), rescanNotifications: make(chan interface{}),