From af43315e94287d97ebcd8e3f11b8f7653da21a16 Mon Sep 17 00:00:00 2001 From: deepface19 <59292798+deepface19@users.noreply.github.com> Date: Thu, 21 Mar 2024 10:27:02 +0000 Subject: [PATCH] optimization constant time --- contracts/XCounter.sol | 3 ++- contracts/XCounterUC.sol | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/contracts/XCounter.sol b/contracts/XCounter.sol index 33ff2c1..0580388 100644 --- a/contracts/XCounter.sol +++ b/contracts/XCounter.sol @@ -9,6 +9,7 @@ contract XCounter is CustomChanIbcApp { uint64 public counter; mapping (uint64 => address) public counterMap; + uint64 public immutable CONST_TIME = 1e9; constructor(IbcDispatcher _dispatcher) CustomChanIbcApp(_dispatcher) {} @@ -37,7 +38,7 @@ contract XCounter is CustomChanIbcApp { bytes memory payload = abi.encode(msg.sender); // setting the timeout timestamp at 10h from now - uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * 1000000000); + uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * CONST_TIME); // calling the Dispatcher to send the packet dispatcher.sendPacket(channelId, payload, timeoutTimestamp); diff --git a/contracts/XCounterUC.sol b/contracts/XCounterUC.sol index fa8b52c..af4f015 100644 --- a/contracts/XCounterUC.sol +++ b/contracts/XCounterUC.sol @@ -9,6 +9,8 @@ contract XCounterUC is UniversalChanIbcApp { uint64 public counter; mapping(uint64 => address) public counterMap; + uint64 public immutable CONST_TIME = 1e9; + constructor(address _middleware) UniversalChanIbcApp(_middleware) {} // application specific logic @@ -32,7 +34,7 @@ contract XCounterUC is UniversalChanIbcApp { increment(); bytes memory payload = abi.encode(msg.sender, counter); - uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * 1000000000); + uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * CONST_TIME); IbcUniversalPacketSender(mw).sendUniversalPacket( channelId, IbcUtils.toBytes32(destPortAddr), payload, timeoutTimestamp