Skip to content

Commit 8606320

Browse files
committed
fix: added falback to maxExitEpoch
1 parent 01c1a21 commit 8606320

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/waiting-time/waiting-time.service.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ export class WaitingTimeService {
9090
const additionalStETH = parseEther(amount || '0');
9191
const queueStETH = unfinalized.add(additionalStETH);
9292

93-
const latestEpoch = this.validators.getMaxExitEpoch();
93+
const maxExitEpoch = this.getMaxExitEpoch();
9494

9595
const { frame, type } = await this.calculateWithdrawalFrame({
9696
unfinalized: queueStETH,
9797
vaultsBalance,
9898
buffer,
9999
requestTimestamp: Date.now(),
100-
latestEpoch,
100+
latestEpoch: maxExitEpoch.toString(),
101101
});
102102
const ms = this.genesisTimeService.timeToWithdrawalFrame(frame, Date.now());
103103
const finalizationIn = validateTimeResponseWithFallback(ms) + GAP_AFTER_REPORT;
@@ -132,7 +132,7 @@ export class WaitingTimeService {
132132
const nextCalculationAt = this.queueInfo.getNextUpdate().toISOString();
133133
const request = requests.find((item) => item.id.eq(BigNumber.from(requestId)));
134134

135-
const maxExitEpoch = this.validators.getMaxExitEpoch();
135+
const maxExitEpoch = this.getMaxExitEpoch();
136136
const currentEpoch = this.genesisTimeService.getCurrentEpoch();
137137

138138
const queueStETH = calculateUnfinalizedEthToRequestId(requests, request);
@@ -325,7 +325,7 @@ export class WaitingTimeService {
325325
private async checkInPastCase(args: CheckInPastCaseArgs) {
326326
const { request, vaultsBalance, buffer, type, frame } = args;
327327

328-
const maxExitEpoch = this.validators.getMaxExitEpoch();
328+
const maxExitEpoch = this.getMaxExitEpoch();
329329
const requests = this.queueInfo.getRequests();
330330
const requestTimestamp = request.timestamp.toNumber() * 1000;
331331
const queueStETH = calculateUnfinalizedEthToRequestId(requests, request);
@@ -477,14 +477,14 @@ export class WaitingTimeService {
477477

478478
public calculateRequestTimeSimple(unfinalizedETH: BigNumber): number {
479479
const currentEpoch = this.genesisTimeService.getCurrentEpoch();
480-
const latestEpoch = this.validators.getMaxExitEpoch();
480+
const maxExitEpoch = this.getMaxExitEpoch();
481481
const totalValidators = this.validators.getActiveValidatorsCount();
482482

483483
const churnLimit = Math.max(MIN_PER_EPOCH_CHURN_LIMIT, totalValidators / CHURN_LIMIT_QUOTIENT);
484484

485485
const lidoQueueInEpoch = unfinalizedETH.div(MIN_ACTIVATION_BALANCE.mul(Math.floor(churnLimit)));
486486
const sweepingMean = this.validators.getSweepMeanEpochs();
487-
const potentialExitEpoch = BigNumber.from(latestEpoch).add(lidoQueueInEpoch).add(sweepingMean);
487+
const potentialExitEpoch = BigNumber.from(maxExitEpoch).add(lidoQueueInEpoch).add(sweepingMean);
488488

489489
const waitingTime = potentialExitEpoch
490490
.sub(currentEpoch)
@@ -494,4 +494,12 @@ export class WaitingTimeService {
494494

495495
return Math.round(waitingTime.toNumber());
496496
}
497+
498+
// returns max exit epoch of validators with fallback to current epoch if max exit epoch already passed
499+
public getMaxExitEpoch() {
500+
const maxExitEpoch = this.validators.getMaxExitEpoch();
501+
const currentEpoch = this.genesisTimeService.getCurrentEpoch();
502+
503+
return Math.max(+maxExitEpoch, currentEpoch + MAX_SEED_LOOKAHEAD + 1);
504+
}
497505
}

0 commit comments

Comments
 (0)