fix(batch-mining): 修正阶段划分逻辑
preMineDays 表示该批次比最后批次提前多少天开始挖矿 阶段天数 = 当前批次的preMineDays - 下一批次的preMineDays(差值) 例如:批次1(3天)、批次2(2天)、批次3(1天)、批次4(0天) - 阶段1:只有批次1,持续 3-2=1 天 - 阶段2:批次1+2,持续 2-1=1 天 - 阶段3:批次1+2+3,持续 1-0=1 天 - 最后阶段:所有批次一起挖剩余天数 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
2358b3ea17
commit
9e9c791283
|
|
@ -350,18 +350,18 @@ export class BatchMiningService {
|
||||||
/**
|
/**
|
||||||
* 构建挖矿阶段
|
* 构建挖矿阶段
|
||||||
*
|
*
|
||||||
* 根据批次的"提前天数"构建各挖矿阶段:
|
* preMineDays 的含义:该批次比最后一批提前多少天开始挖矿
|
||||||
* - preMineDays 表示该批次比下一批次提前开始的天数
|
* - 批次1的 preMineDays=3 意味着批次1比最后批次提前3天开始
|
||||||
* - 批次1的 preMineDays=3 意味着批次1比批次2提前3天,所以批次1先独挖3天
|
* - 批次2的 preMineDays=2 意味着批次2比最后批次提前2天开始
|
||||||
* - 批次2的 preMineDays=2 意味着批次2比批次3提前2天,所以批次1+2一起挖2天
|
* - 批次3的 preMineDays=1 意味着批次3比最后批次提前1天开始
|
||||||
* - 批次3的 preMineDays=1 意味着批次3比批次4提前1天,所以批次1+2+3一起挖1天
|
* - 批次4的 preMineDays=0 意味着批次4是最后一批
|
||||||
* - 批次4的 preMineDays=0 意味着批次4是最后一批,所有批次一起挖剩余天数
|
|
||||||
*
|
*
|
||||||
* 正确的阶段划分:
|
* 阶段划分(按 preMineDays 从大到小排序批次,计算相邻批次的差值):
|
||||||
* - 阶段1: 只有批次1,持续批次1的 preMineDays 天(在批次2加入之前)
|
* - 假设批次按 preMineDays 排序后为: 批次1(3), 批次2(2), 批次3(1), 批次4(0)
|
||||||
* - 阶段2: 批次1+2,持续批次2的 preMineDays 天(在批次3加入之前)
|
* - 阶段1: 只有批次1,持续 3-2=1 天
|
||||||
* - 阶段3: 批次1+2+3,持续批次3的 preMineDays 天(在批次4加入之前)
|
* - 阶段2: 批次1+2,持续 2-1=1 天
|
||||||
* - 最后阶段: 所有批次一起挖 (totalMiningDays - 所有提前天数之和)
|
* - 阶段3: 批次1+2+3,持续 1-0=1 天
|
||||||
|
* - 最后阶段: 所有批次一起挖剩余天数
|
||||||
*/
|
*/
|
||||||
private buildMiningPhases(
|
private buildMiningPhases(
|
||||||
items: BatchMiningItem[],
|
items: BatchMiningItem[],
|
||||||
|
|
@ -395,22 +395,37 @@ 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 从大到小处理批次
|
||||||
// 关键:先用当前批次的 preMineDays 创建阶段,然后下一批次加入
|
for (let i = 0; i < batchesByPreMineDays.length; i++) {
|
||||||
for (let i = 0; i < sortedBatches.length; i++) {
|
const currentBatch = batchesByPreMineDays[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);
|
||||||
|
|
||||||
// 该阶段持续天数 = 当前批次的 preMineDays(当前批次比下一批次提前的天数)
|
if (phaseDays > 0) {
|
||||||
// 如果 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) {
|
||||||
|
|
@ -421,14 +436,14 @@ export class BatchMiningService {
|
||||||
phaseNumber: currentPhase,
|
phaseNumber: currentPhase,
|
||||||
startDate: new Date(),
|
startDate: new Date(),
|
||||||
endDate: new Date(),
|
endDate: new Date(),
|
||||||
daysInPhase: currentPreMineDays,
|
daysInPhase: phaseDays,
|
||||||
participatingContribution,
|
participatingContribution,
|
||||||
participatingBatches: [...participatingBatches],
|
participatingBatches: [...participatingBatches],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.log(`[buildMiningPhases] 阶段${currentPhase}: ${currentPreMineDays}天, 批次[${participatingBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`);
|
this.logger.log(`[buildMiningPhases] 阶段${currentPhase}: ${phaseDays}天, 批次[${participatingBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`);
|
||||||
currentPhase++;
|
currentPhase++;
|
||||||
usedDays += currentPreMineDays;
|
usedDays += phaseDays;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue