From 0c9d4f1e85073d7d51a5bdbdf49e285f4853d9cb Mon Sep 17 00:00:00 2001 From: Yorke Rhodes Date: Mon, 21 Oct 2024 14:38:12 -0400 Subject: [PATCH] Add events and custom errors for scheduling --- solidity/contracts/isms/hook/OptimisticIsm.sol | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/solidity/contracts/isms/hook/OptimisticIsm.sol b/solidity/contracts/isms/hook/OptimisticIsm.sol index 3e22a01db..d2047ca0f 100644 --- a/solidity/contracts/isms/hook/OptimisticIsm.sol +++ b/solidity/contracts/isms/hook/OptimisticIsm.sol @@ -31,6 +31,10 @@ contract OptimisticIsm is IInterchainSecurityModule { mapping(bytes32 => uint48) public preverifiedMessages; + event MessageQueued(bytes32 indexed messageId, uint48 readyAt); + + error MessageNotReadyUntil(uint48 readyAt); + uint48 public immutable optimisticWindow; constructor(uint48 _optimisticWindow) { @@ -47,6 +51,7 @@ contract OptimisticIsm is IInterchainSecurityModule { "OptimisticIsm: message already preverified" ); preverifiedMessages[messageId] = uint48(block.timestamp); + emit MessageQueued(messageId, block.timestamp + optimisticWindow); } function verify( @@ -55,6 +60,11 @@ contract OptimisticIsm is IInterchainSecurityModule { ) external view returns (bool) { uint48 timestamp = preverifiedMessages[message.id()]; require(timestamp > 0, "OptimisticIsm: message not preverified"); - return timestamp + optimisticWindow < block.timestamp; + + uint48 readyAt = timestamp + optimisticWindow; + if (readyAt > block.timestamp) { + revert MessageNotReadyUntil(readyAt); + } + return true; } }