Skip to content

Commit 794bb7b

Browse files
committed
pool: Simplify code calculating rewards payments.
The code to calculate payment amounts was overly complicated and duplicated 4 times. This change simplifies it and adds some comments.
1 parent 85d38d7 commit 794bb7b

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

pool/paymentmgr.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -643,29 +643,28 @@ func (pm *PaymentMgr) generatePayoutTxDetails(ctx context.Context, txC txCreator
643643

644644
// Generate the outputs paying dividends as well as pool fees.
645645
for _, pmt := range pmtSet {
646+
// If this payment is for pool fees, use the provided pool fee
647+
// address. If not, it is a miner dividend payment and their address
648+
// is retrieved from the database.
649+
var addr string
646650
if pmt.Account == PoolFeesK {
647-
_, ok := outputs[feeAddr.String()]
648-
if !ok {
649-
outputs[feeAddr.String()] = pmt.Amount
650-
tOut += pmt.Amount
651-
continue
651+
addr = feeAddr.String()
652+
} else {
653+
acc, err := pm.cfg.db.fetchAccount(pmt.Account)
654+
if err != nil {
655+
return nil, nil, nil, 0, err
652656
}
653-
outputs[feeAddr.String()] += pmt.Amount
654-
tOut += pmt.Amount
655-
continue
657+
addr = acc.Address
656658
}
657659

658-
acc, err := pm.cfg.db.fetchAccount(pmt.Account)
659-
if err != nil {
660-
return nil, nil, nil, 0, err
661-
}
662-
_, ok := outputs[acc.Address]
660+
// Create an output for this address if one doesn't already exist.
661+
_, ok := outputs[addr]
663662
if !ok {
664-
outputs[acc.Address] = pmt.Amount
665-
tOut += pmt.Amount
666-
continue
663+
outputs[addr] = dcrutil.Amount(0)
667664
}
668-
outputs[acc.Address] += pmt.Amount
665+
666+
// Add this payment to the output and update the running total.
667+
outputs[addr] += pmt.Amount
669668
tOut += pmt.Amount
670669
}
671670
}

0 commit comments

Comments
 (0)