fix(batch-mining): 移除多余的最后阶段
根据需求:总天数 = 所有批次的 preMineDays 之和 - 阶段1: 只有第一批,分配第一批的 preMineDays 天 - 阶段2: 第一批+第二批,分配第二批的 preMineDays 天 - 依次类推... 没有额外的"最后阶段",不再使用 maxTotalMiningDays Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c90d88a047
commit
d98e22f151
|
|
@ -374,42 +374,33 @@ export class BatchMiningService {
|
|||
return phases;
|
||||
}
|
||||
|
||||
// 获取每个批次的提前天数和总挖矿天数
|
||||
// 获取每个批次的提前天数
|
||||
const batchPreMineDays = new Map<number, number>();
|
||||
let maxTotalMiningDays = 0;
|
||||
for (const item of items) {
|
||||
if (!batchPreMineDays.has(item.batch)) {
|
||||
batchPreMineDays.set(item.batch, item.preMineDays);
|
||||
}
|
||||
// 使用最大的总挖矿天数(第一批次的用户应该有最长的挖矿时间)
|
||||
if (item.totalMiningDays && item.totalMiningDays > maxTotalMiningDays) {
|
||||
maxTotalMiningDays = item.totalMiningDays;
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.log(`[buildMiningPhases] 各批次提前天数: ${JSON.stringify(Object.fromEntries(batchPreMineDays))}`);
|
||||
this.logger.log(`[buildMiningPhases] 最大总挖矿天数: ${maxTotalMiningDays}`);
|
||||
|
||||
if (maxTotalMiningDays <= 0) {
|
||||
this.logger.warn('[buildMiningPhases] 总挖矿天数<=0,无法计算');
|
||||
return phases;
|
||||
}
|
||||
|
||||
let currentPhase = 1;
|
||||
let participatingBatches: number[] = [];
|
||||
let usedDays = 0; // 已分配的天数
|
||||
let totalDays = 0;
|
||||
|
||||
// 按批次顺序添加阶段
|
||||
// 关键:先用当前批次的 preMineDays 创建阶段,然后下一批次加入
|
||||
// 阶段1: 只有第一批,分配第一批的 preMineDays 天
|
||||
// 阶段2: 第一批+第二批,分配第二批的 preMineDays 天
|
||||
// 阶段3: 第一批+第二批+第三批,分配第三批的 preMineDays 天
|
||||
// ...依次类推,总天数 = 所有 preMineDays 之和
|
||||
for (let i = 0; i < sortedBatches.length; i++) {
|
||||
const currentBatch = sortedBatches[i];
|
||||
const currentPreMineDays = batchPreMineDays.get(currentBatch) || 0;
|
||||
|
||||
// 先把当前批次加入参与列表
|
||||
// 当前批次加入参与列表
|
||||
participatingBatches.push(currentBatch);
|
||||
|
||||
// 该阶段持续天数 = 当前批次的 preMineDays(当前批次比下一批次提前的天数)
|
||||
// 如果 preMineDays > 0,说明当前参与批次要在下一批次加入前独挖这些天
|
||||
// 该阶段持续天数 = 当前批次的 preMineDays
|
||||
if (currentPreMineDays > 0) {
|
||||
// 计算该阶段参与用户的总算力
|
||||
let participatingContribution = new Decimal(0);
|
||||
|
|
@ -428,31 +419,11 @@ export class BatchMiningService {
|
|||
|
||||
this.logger.log(`[buildMiningPhases] 阶段${currentPhase}: ${currentPreMineDays}天, 批次[${participatingBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`);
|
||||
currentPhase++;
|
||||
usedDays += currentPreMineDays;
|
||||
totalDays += currentPreMineDays;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加最后阶段:所有批次一起挖(剩余天数)
|
||||
const remainingDays = maxTotalMiningDays - usedDays;
|
||||
if (remainingDays > 0) {
|
||||
// 所有批次都参与
|
||||
let participatingContribution = new Decimal(0);
|
||||
for (const batch of sortedBatches) {
|
||||
participatingContribution = participatingContribution.plus(batchContributions.get(batch) || 0);
|
||||
}
|
||||
|
||||
phases.push({
|
||||
phaseNumber: currentPhase,
|
||||
startDate: new Date(),
|
||||
endDate: new Date(),
|
||||
daysInPhase: remainingDays,
|
||||
participatingContribution,
|
||||
participatingBatches: [...sortedBatches],
|
||||
});
|
||||
|
||||
this.logger.log(`[buildMiningPhases] 阶段${currentPhase}(最终): ${remainingDays}天, 所有批次[${sortedBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`);
|
||||
}
|
||||
|
||||
this.logger.log(`[buildMiningPhases] 总天数: ${totalDays}`);
|
||||
return phases;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue