diff --git a/packages/inter-protocol/src/auction/scheduler.js b/packages/inter-protocol/src/auction/scheduler.js index 1fd25fdd1250..3dca74d03848 100644 --- a/packages/inter-protocol/src/auction/scheduler.js +++ b/packages/inter-protocol/src/auction/scheduler.js @@ -93,8 +93,17 @@ export const computeRoundTiming = (params, baseTime) => { startDelay, ); const endTime = TimeMath.addAbsRel(startTime, actualDuration); + const lockTime = TimeMath.subtractAbsRel(startTime, lockPeriod); - const next = { startTime, endTime, steps, endRate, startDelay, clockStep }; + const next = { + startTime, + endTime, + steps, + endRate, + startDelay, + clockStep, + lockTime, + }; return harden(next); }; @@ -144,8 +153,17 @@ export const makeScheduler = async ( auctionState = AuctionState.WAITING; auctionDriver.finalize(); - const afterNow = TimeMath.addAbsRel(time, TimeMath.toRel(1n, timerBrand)); - nextSchedule = computeRoundTiming(params, afterNow); + + // only recalculate the next schedule at this point if the lock time has + // not been reached. + const nextLock = nextSchedule.lockTime; + if (TimeMath.compareAbs(time, nextLock) < 0) { + const afterNow = TimeMath.addAbsRel( + time, + TimeMath.toRel(1n, timerBrand), + ); + nextSchedule = computeRoundTiming(params, afterNow); + } liveSchedule = undefined; E(timer).cancel(stepCancelToken); diff --git a/packages/inter-protocol/test/auction/test-computeRoundTiming.js b/packages/inter-protocol/test/auction/test-computeRoundTiming.js index 74ad93cf43f0..7bd9a0ba7ca0 100644 --- a/packages/inter-protocol/test/auction/test-computeRoundTiming.js +++ b/packages/inter-protocol/test/auction/test-computeRoundTiming.js @@ -47,6 +47,7 @@ const checkSchedule = (t, params, baseTime, rawExpect) => { endRate: rawExpect.endRate, startDelay: TimeMath.toRel(rawExpect.startDelay, brand), clockStep: TimeMath.toRel(rawExpect.clockStep, brand), + lockTime: TimeMath.toAbs(rawExpect.lockTime, brand), }; t.deepEqual(schedule, expect); }; @@ -76,6 +77,7 @@ test('simple schedule', checkSchedule, makeDefaultParams(), 100, { endRate: 6_500n, startDelay: 300, clockStep: 600, + lockTime: 3000, }); test( @@ -90,6 +92,7 @@ test( endRate: 6_500n, startDelay: 300, clockStep: 600, + lockTime: 6600, }, ); @@ -107,6 +110,7 @@ test( endRate: 6_500n, startDelay: 300, clockStep: 300, + lockTime: 3000, }, ); @@ -155,6 +159,7 @@ test( endRate: 10_500n - 2_001n, startDelay: 300, clockStep: 600, + lockTime: 3000, }, ); @@ -180,6 +185,7 @@ test( endRate: 10_500n - 5n * 10n, startDelay: 300, clockStep: 600, + lockTime: 3000, }, ); @@ -197,5 +203,6 @@ test( endRate: 10_500n - 5n * 350n, startDelay: 300, clockStep: 600, + lockTime: 3000, }, ); diff --git a/packages/inter-protocol/test/auction/test-scheduler.js b/packages/inter-protocol/test/auction/test-scheduler.js index 5fd850c85fa1..5c64a1d110b0 100644 --- a/packages/inter-protocol/test/auction/test-scheduler.js +++ b/packages/inter-protocol/test/auction/test-scheduler.js @@ -69,6 +69,7 @@ test('schedule start to finish', async t => { endRate: 6500n, startDelay: TimeMath.toRel(1n, timerBrand), clockStep: TimeMath.toRel(2n, timerBrand), + lockTime: TimeMath.toAbs(126n, timerBrand), }; t.deepEqual(schedule.nextAuctionSchedule, firstSchedule); @@ -93,6 +94,7 @@ test('schedule start to finish', async t => { endRate: 6500n, startDelay: TimeMath.toRel(1n, timerBrand), clockStep: TimeMath.toRel(2n, timerBrand), + lockTime: TimeMath.toAbs(136, timerBrand), }); t.is(fakeAuctioneer.getState().step, 1); @@ -130,6 +132,7 @@ test('schedule start to finish', async t => { endRate: 6500n, startDelay: TimeMath.toRel(1n, timerBrand), clockStep: TimeMath.toRel(2n, timerBrand), + lockTime: TimeMath.toAbs(136n, timerBrand), }; t.deepEqual(finalSchedule.nextAuctionSchedule, secondSchedule); @@ -150,6 +153,7 @@ test('schedule start to finish', async t => { endRate: 6500n, startDelay: TimeMath.toRel(1n, timerBrand), clockStep: TimeMath.toRel(2n, timerBrand), + lockTime: TimeMath.toAbs(146n, timerBrand), }); t.is(fakeAuctioneer.getState().step, 4); @@ -521,6 +525,7 @@ test('duration = freq', async t => { endRate: 50n, startDelay: TimeMath.toRel(5n, timerBrand), clockStep: TimeMath.toRel(60n, timerBrand), + lockTime: TimeMath.toAbs(345n, timerBrand), }; t.deepEqual(schedule.nextAuctionSchedule, firstSchedule); @@ -535,6 +540,7 @@ test('duration = freq', async t => { endRate: 50n, startDelay: TimeMath.toRel(5n, timerBrand), clockStep: TimeMath.toRel(60n, timerBrand), + lockTime: TimeMath.toAbs(705n, timerBrand), }; t.deepEqual(schedule.nextAuctionSchedule, secondSchedule); });