@@ -7,7 +7,7 @@ import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
77import { Strings } from "@openzeppelin/contracts/utils/Strings.sol " ;
88import "./shared/Pausable.sol " ;
99import { ContextLifecycle } from "./libraries/ContextLifecycle.sol " ;
10- import { CoprocessorContext, CoprocessorContextBlockPeriods } from "./shared/Structs.sol " ;
10+ import { CoprocessorContext, CoprocessorContextTimePeriods } from "./shared/Structs.sol " ;
1111import { ContextStatus } from "./shared/Enums.sol " ;
1212import { UUPSUpgradeableEmptyProxy } from "./shared/UUPSUpgradeableEmptyProxy.sol " ;
1313
@@ -49,12 +49,12 @@ contract CoprocessorContexts is ICoprocessorContexts, Ownable2StepUpgradeable, U
4949 mapping (uint256 contextId = > mapping (address coprocessorSignerAddress = > bool isCoprocessorSigner )) isCoprocessorSigner;
5050 /// @notice The coprocessors' signer address list per context
5151 mapping (uint256 contextId = > address [] coprocessorSignerAddresses ) coprocessorSignerAddresses;
52- /// @notice The block number at which the coprocessor context is activated
53- mapping (uint256 contextId = > uint256 activationBlockNumber ) coprocessorContextActivationBlockNumber ;
54- /// @notice The block number at which the coprocessor context is deactivated
55- mapping (uint256 contextId = > uint256 deactivatedBlockNumber ) coprocessorContextDeactivatedBlockNumber ;
56- /// @notice The suspended block period for the coprocessor context
57- mapping (uint256 contextId = > uint256 suspendedBlockPeriod ) coprocessorContextSuspendedBlockPeriod ;
52+ /// @notice The block timestamp at which the coprocessor context is activated
53+ mapping (uint256 contextId = > uint256 activationBlockTimestamp ) coprocessorContextActivationBlockTimestamp ;
54+ /// @notice The block timestamp at which the coprocessor context is deactivated
55+ mapping (uint256 contextId = > uint256 deactivatedBlockTimestamp ) coprocessorContextDeactivatedBlockTimestamp ;
56+ /// @notice The suspended time period for the coprocessor context
57+ mapping (uint256 contextId = > uint256 suspendedTimePeriod ) coprocessorContextSuspendedTimePeriod ;
5858 }
5959
6060 // Storage location has been computed using the following command:
@@ -185,7 +185,7 @@ contract CoprocessorContexts is ICoprocessorContexts, Ownable2StepUpgradeable, U
185185 function addCoprocessorContext (
186186 uint256 featureSet ,
187187 Coprocessor[] calldata coprocessors ,
188- CoprocessorContextBlockPeriods calldata blockPeriods
188+ CoprocessorContextTimePeriods calldata timePeriods
189189 ) external virtual onlyOwner {
190190 CoprocessorContextsStorage storage $ = _getCoprocessorContextsStorage ();
191191 // This will revert if there is no active coprocessor context. Although this should never
@@ -204,7 +204,7 @@ contract CoprocessorContexts is ICoprocessorContexts, Ownable2StepUpgradeable, U
204204 );
205205
206206 // Emit the event that indicates that a valid coprocessor context has been suggested to be added.
207- emit NewCoprocessorContext (activeCoprocessorContext, newCoprocessorContext, blockPeriods );
207+ emit NewCoprocessorContext (activeCoprocessorContext, newCoprocessorContext, timePeriods );
208208
209209 // Set the coprocessor context to the generating state
210210 // This currently has no implications on the coprocessor contexts, except that it will check
@@ -217,18 +217,17 @@ contract CoprocessorContexts is ICoprocessorContexts, Ownable2StepUpgradeable, U
217217 // Directly pre-activate the coprocessor context
218218 ContextLifecycle.setPreActivation ($.coprocessorContextLifecycle, newCoprocessorContext.contextId);
219219
220- // Define the activation block number for the new coprocessor context
221- uint256 activationBlockNumber = block .number + blockPeriods.preActivationBlockPeriod ;
222- $.coprocessorContextActivationBlockNumber [newCoprocessorContext.contextId] = activationBlockNumber ;
220+ // Define the activation block timestamp for the new coprocessor context
221+ uint256 activationBlockTimestamp = block .timestamp + timePeriods.preActivationTimePeriod ;
222+ $.coprocessorContextActivationBlockTimestamp [newCoprocessorContext.contextId] = activationBlockTimestamp ;
223223
224- // Store the suspended block period for the previous coprocessor context
224+ // Store the suspended time period for the previous coprocessor context
225225 // This value will be considered once the new coprocessor context is activated and the old one
226226 // is suspended
227- $.coprocessorContextSuspendedBlockPeriod[activeCoprocessorContext.contextId] = blockPeriods
228- .suspendedBlockPeriod;
227+ $.coprocessorContextSuspendedTimePeriod[activeCoprocessorContext.contextId] = timePeriods.suspendedTimePeriod;
229228
230229 // Emit the event that indicates that the new coprocessor context has been pre-activated
231- emit PreActivateCoprocessorContext (newCoprocessorContext, activationBlockNumber );
230+ emit PreActivateCoprocessorContext (newCoprocessorContext, activationBlockTimestamp );
232231 }
233232
234233 /**
@@ -242,17 +241,18 @@ contract CoprocessorContexts is ICoprocessorContexts, Ownable2StepUpgradeable, U
242241 uint256 preActivationContextId = $.coprocessorContextLifecycle.preActivationContextId;
243242 if (
244243 preActivationContextId != 0 &&
245- block .number >= $.coprocessorContextActivationBlockNumber [preActivationContextId]
244+ block .timestamp >= $.coprocessorContextActivationBlockTimestamp [preActivationContextId]
246245 ) {
247246 uint256 activeContextId = getActiveCoprocessorContextId ();
248247
249- // Define the deactivation block number for the current active coprocessor context
250- uint256 deactivatedBlockNumber = block .number + $.coprocessorContextSuspendedBlockPeriod[activeContextId];
251- $.coprocessorContextDeactivatedBlockNumber[activeContextId] = deactivatedBlockNumber;
248+ // Define the deactivation block timestamp for the current active coprocessor context
249+ uint256 deactivatedBlockTimestamp = block .timestamp +
250+ $.coprocessorContextSuspendedTimePeriod[activeContextId];
251+ $.coprocessorContextDeactivatedBlockTimestamp[activeContextId] = deactivatedBlockTimestamp;
252252
253253 // Set the current active coprocessor context to the suspended state
254254 ContextLifecycle.setSuspended ($.coprocessorContextLifecycle, activeContextId);
255- emit SuspendCoprocessorContext (activeContextId, deactivatedBlockNumber );
255+ emit SuspendCoprocessorContext (activeContextId, deactivatedBlockTimestamp );
256256
257257 // Set the new active coprocessor context
258258 ContextLifecycle.setActive ($.coprocessorContextLifecycle, preActivationContextId);
@@ -261,7 +261,10 @@ contract CoprocessorContexts is ICoprocessorContexts, Ownable2StepUpgradeable, U
261261
262262 // Check if there is a suspended coprocessor context and if it is time to deactivate it
263263 uint256 suspendedContextId = _getSuspendedCoprocessorContextId ();
264- if (suspendedContextId != 0 && block .number >= $.coprocessorContextDeactivatedBlockNumber[suspendedContextId]) {
264+ if (
265+ suspendedContextId != 0 &&
266+ block .timestamp >= $.coprocessorContextDeactivatedBlockTimestamp[suspendedContextId]
267+ ) {
265268 ContextLifecycle.setDeactivated ($.coprocessorContextLifecycle, suspendedContextId);
266269 emit DeactivateCoprocessorContext (suspendedContextId);
267270 }
@@ -354,23 +357,23 @@ contract CoprocessorContexts is ICoprocessorContexts, Ownable2StepUpgradeable, U
354357 }
355358
356359 /**
357- * @dev See {ICoprocessorContexts-getCoprocessorContextActivationBlockNumber }.
360+ * @dev See {ICoprocessorContexts-getCoprocessorContextActivationBlockTimestamp }.
358361 */
359- function getCoprocessorContextActivationBlockNumber (
362+ function getCoprocessorContextActivationBlockTimestamp (
360363 uint256 contextId
361364 ) external view virtual ensureContextInitialized (contextId) returns (uint256 ) {
362365 CoprocessorContextsStorage storage $ = _getCoprocessorContextsStorage ();
363- return $.coprocessorContextActivationBlockNumber [contextId];
366+ return $.coprocessorContextActivationBlockTimestamp [contextId];
364367 }
365368
366369 /**
367- * @dev See {ICoprocessorContexts-getCoprocessorContextDeactivatedBlockNumber }.
370+ * @dev See {ICoprocessorContexts-getCoprocessorContextDeactivatedBlockTimestamp }.
368371 */
369- function getCoprocessorContextDeactivatedBlockNumber (
372+ function getCoprocessorContextDeactivatedBlockTimestamp (
370373 uint256 contextId
371374 ) external view virtual ensureContextInitialized (contextId) returns (uint256 ) {
372375 CoprocessorContextsStorage storage $ = _getCoprocessorContextsStorage ();
373- return $.coprocessorContextDeactivatedBlockNumber [contextId];
376+ return $.coprocessorContextDeactivatedBlockTimestamp [contextId];
374377 }
375378
376379 /**
0 commit comments