Commit 7d9d9138 authored by David Vorick's avatar David Vorick

more strictly follow locking conventions during defrag

parent a0739182
......@@ -18,16 +18,21 @@ const (
)
// dustValue is the quantity below which a Currency is considered to be Dust.
//
// TODO: These need to be functions of the wallet that interact with the
// transaction pool.
func dustValue() types.Currency {
return types.SiacoinPrecision
return types.SiacoinPrecision.Mul64(3)
}
// defragFee is the miner fee paid to miners when performing a defrag
// transaction.
//
// TODO: These need to be functions of the wallet that interact with the
// transaction pool.
func defragFee() types.Currency {
fee := types.SiacoinPrecision.Mul64(5)
if dustValue().Mul64(defragBatchSize).Cmp(fee) <= 0 {
return dustValue().Mul64(defragBatchSize)
}
return fee
// 35 outputs at an estimated 250 bytes needed per output means about a 10kb
// total transaction, much larger than your average transaction. So you need
// a lot of fees.
return types.SiacoinPrecision.Mul64(20)
}
......@@ -18,9 +18,6 @@ var (
// throughout scanning the outputs to determine if defragmentation is necessary
// and then proceeding to actually defrag.
func (tb *transactionBuilder) fundDefragger(fee types.Currency) (types.Currency, error) {
tb.wallet.mu.Lock()
defer tb.wallet.mu.Unlock()
// Collect a set of outputs for defragging.
var so sortedOutputs
for scoid, sco := range tb.wallet.siacoinOutputs {
......@@ -150,17 +147,20 @@ func (w *Wallet) threadedDefragWallet() {
return
}
// Create a transaction builder.
// Create a transaction builder and fund it with the outputs to be
// defragged.
fee := defragFee()
w.mu.Lock()
tbuilder := w.registerTransaction(types.Transaction{}, nil)
// Fund it using a defragging specific method.
amount, err := tbuilder.fundDefragger(fee)
w.mu.Unlock()
if err != nil {
if err != errDefragNotNeeded {
w.log.Println("Error while trying to fund the defragging transaction", err)
}
return
}
// Add the miner fee.
tbuilder.AddMinerFee(fee)
// Add the refund.
......
......@@ -609,6 +609,8 @@ func (w *Wallet) registerTransaction(t types.Transaction, parents []types.Transa
// most typical call is 'RegisterTransaction(types.Transaction{}, nil)', which
// registers a new transaction without parents.
func (w *Wallet) RegisterTransaction(t types.Transaction, parents []types.Transaction) modules.TransactionBuilder {
w.mu.Lock()
defer w.mu.Unlock()
return w.registerTransaction(t, parents)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment