fix(batch-mining): 修正grandTotalAmount重复累加问题
用户可能在多个批次中出现,之前按批次累加batchTotalAmount会导致 同一用户的收益被重复计算。改为直接累加所有用户的amount(去重)。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
18e9749ad8
commit
f44af3a2ed
|
|
@ -273,7 +273,6 @@ export class BatchMiningService {
|
|||
}
|
||||
|
||||
// 构建返回结果
|
||||
let grandTotalAmount = new Decimal(0);
|
||||
const batchResults: BatchMiningPreviewResult['batches'] = [];
|
||||
|
||||
// 计算用户总算力(用于显示)
|
||||
|
|
@ -283,6 +282,17 @@ export class BatchMiningService {
|
|||
}
|
||||
this.logger.log(`[preview] 用户总算力: ${totalUserContribution.toFixed(2)}`);
|
||||
|
||||
// 计算 grandTotalAmount:所有用户的收益总和(去重)
|
||||
let grandTotalAmount = new Decimal(0);
|
||||
const processedUsers = new Set<string>();
|
||||
for (const [accountSequence, amount] of userAmounts) {
|
||||
if (!processedUsers.has(accountSequence)) {
|
||||
processedUsers.add(accountSequence);
|
||||
grandTotalAmount = grandTotalAmount.plus(amount);
|
||||
}
|
||||
}
|
||||
this.logger.log(`[preview] 计算的总金额: ${grandTotalAmount.toFixed(8)} (${processedUsers.size}个用户)`);
|
||||
|
||||
for (const batchNum of sortedBatches) {
|
||||
const batchItems = batchGroups.get(batchNum)!;
|
||||
const batchContribution = batchContributions.get(batchNum)!;
|
||||
|
|
@ -330,8 +340,6 @@ export class BatchMiningService {
|
|||
cumulativeNetworkContribution: cumulativeContribution.toFixed(10),
|
||||
batchTotalAmount: batchTotalAmount.toFixed(8),
|
||||
});
|
||||
|
||||
grandTotalAmount = grandTotalAmount.plus(batchTotalAmount);
|
||||
}
|
||||
|
||||
const result = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue