Revert "fix(batch-mining): 修正阶段划分逻辑"

This reverts commit 9e9c791283.
This commit is contained in:
hailin 2026-01-21 23:34:12 -08:00
parent 9e9c791283
commit c90d88a047
1 changed files with 23 additions and 38 deletions

View File

@ -350,18 +350,18 @@ export class BatchMiningService {
/** /**
* *
* *
* preMineDays * "提前天数"
* - 1 preMineDays=3 13 * - preMineDays
* - 2 preMineDays=2 22 * - 1 preMineDays=3 12313
* - 3 preMineDays=1 31 * - 2 preMineDays=2 2321+22
* - 4 preMineDays=0 4 * - 3 preMineDays=1 3411+2+31
* - 4 preMineDays=0 4
* *
* preMineDays *
* - preMineDays 排序后为: 批次1(3), 2(2), 3(1), 4(0) * - 阶段1: 只有批次11 preMineDays 2
* - 阶段1: 只有批次1 3-2=1 * - 阶段2: 批次1+22 preMineDays 3
* - 阶段2: 批次1+2 2-1=1 * - 阶段3: 批次1+2+33 preMineDays 4
* - 阶段3: 批次1+2+3 1-0=1 * - 最后阶段: 所有批次一起挖 (totalMiningDays - )
* - 最后阶段: 所有批次一起挖剩余天数
*/ */
private buildMiningPhases( private buildMiningPhases(
items: BatchMiningItem[], items: BatchMiningItem[],
@ -395,37 +395,22 @@ export class BatchMiningService {
return phases; return phases;
} }
// 按 preMineDays 从大到小排序批次(提前天数多的批次先开始挖)
const batchesByPreMineDays = [...sortedBatches].sort((a, b) => {
const preA = batchPreMineDays.get(a) || 0;
const preB = batchPreMineDays.get(b) || 0;
return preB - preA; // 降序
});
this.logger.log(`[buildMiningPhases] 按提前天数排序后的批次: ${batchesByPreMineDays.join(', ')}`);
let currentPhase = 1; let currentPhase = 1;
let participatingBatches: number[] = []; let participatingBatches: number[] = [];
let usedDays = 0; let usedDays = 0; // 已分配的天数
// 按 preMineDays 从大到小处理批次 // 按批次顺序添加阶段
for (let i = 0; i < batchesByPreMineDays.length; i++) { // 关键:先用当前批次的 preMineDays 创建阶段,然后下一批次加入
const currentBatch = batchesByPreMineDays[i]; for (let i = 0; i < sortedBatches.length; i++) {
const currentBatch = sortedBatches[i];
const currentPreMineDays = batchPreMineDays.get(currentBatch) || 0; const currentPreMineDays = batchPreMineDays.get(currentBatch) || 0;
// 计算当前阶段的天数 = 当前批次的 preMineDays - 下一批次的 preMineDays // 先把当前批次加入参与列表
let nextPreMineDays = 0;
if (i + 1 < batchesByPreMineDays.length) {
const nextBatch = batchesByPreMineDays[i + 1];
nextPreMineDays = batchPreMineDays.get(nextBatch) || 0;
}
const phaseDays = currentPreMineDays - nextPreMineDays;
// 当前批次加入参与列表
participatingBatches.push(currentBatch); participatingBatches.push(currentBatch);
if (phaseDays > 0) { // 该阶段持续天数 = 当前批次的 preMineDays当前批次比下一批次提前的天数
// 如果 preMineDays > 0说明当前参与批次要在下一批次加入前独挖这些天
if (currentPreMineDays > 0) {
// 计算该阶段参与用户的总算力 // 计算该阶段参与用户的总算力
let participatingContribution = new Decimal(0); let participatingContribution = new Decimal(0);
for (const batch of participatingBatches) { for (const batch of participatingBatches) {
@ -436,14 +421,14 @@ export class BatchMiningService {
phaseNumber: currentPhase, phaseNumber: currentPhase,
startDate: new Date(), startDate: new Date(),
endDate: new Date(), endDate: new Date(),
daysInPhase: phaseDays, daysInPhase: currentPreMineDays,
participatingContribution, participatingContribution,
participatingBatches: [...participatingBatches], participatingBatches: [...participatingBatches],
}); });
this.logger.log(`[buildMiningPhases] 阶段${currentPhase}: ${phaseDays}天, 批次[${participatingBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`); this.logger.log(`[buildMiningPhases] 阶段${currentPhase}: ${currentPreMineDays}天, 批次[${participatingBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`);
currentPhase++; currentPhase++;
usedDays += phaseDays; usedDays += currentPreMineDays;
} }
} }