Skip to content

Commit

Permalink
pool: Simplify code calculating rewards payments.
Browse files Browse the repository at this point in the history
The code to calculate payment amounts was overly complicated and
duplicated 4 times. This change simplifies it and adds some comments.
  • Loading branch information
jholdstock committed Nov 8, 2023
1 parent 85d38d7 commit 794bb7b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions pool/paymentmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,29 +643,28 @@ func (pm *PaymentMgr) generatePayoutTxDetails(ctx context.Context, txC txCreator

// Generate the outputs paying dividends as well as pool fees.
for _, pmt := range pmtSet {
// If this payment is for pool fees, use the provided pool fee
// address. If not, it is a miner dividend payment and their address
// is retrieved from the database.
var addr string
if pmt.Account == PoolFeesK {
_, ok := outputs[feeAddr.String()]
if !ok {
outputs[feeAddr.String()] = pmt.Amount
tOut += pmt.Amount
continue
addr = feeAddr.String()
} else {
acc, err := pm.cfg.db.fetchAccount(pmt.Account)
if err != nil {
return nil, nil, nil, 0, err
}
outputs[feeAddr.String()] += pmt.Amount
tOut += pmt.Amount
continue
addr = acc.Address
}

acc, err := pm.cfg.db.fetchAccount(pmt.Account)
if err != nil {
return nil, nil, nil, 0, err
}
_, ok := outputs[acc.Address]
// Create an output for this address if one doesn't already exist.
_, ok := outputs[addr]
if !ok {
outputs[acc.Address] = pmt.Amount
tOut += pmt.Amount
continue
outputs[addr] = dcrutil.Amount(0)
}
outputs[acc.Address] += pmt.Amount

// Add this payment to the output and update the running total.
outputs[addr] += pmt.Amount
tOut += pmt.Amount
}
}
Expand Down

0 comments on commit 794bb7b

Please sign in to comment.