Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimization constant time #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contracts/XCounter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation of timeoutTimestamp seems to misunderstand the purpose of CONST_TIME. Multiplying block.timestamp + timeoutSeconds by CONST_TIME does not align with the typical use of a timeout timestamp. If CONST_TIME is meant to represent a constant duration, it should likely be added to, not multiplied by, the current timestamp and timeout period.

- uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * CONST_TIME);
+ uint64 timeoutTimestamp = uint64(block.timestamp + (timeoutSeconds * CONST_TIME));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * CONST_TIME);
uint64 timeoutTimestamp = uint64(block.timestamp + (timeoutSeconds * CONST_TIME));


// calling the Dispatcher to send the packet
dispatcher.sendPacket(channelId, payload, timeoutTimestamp);
Expand Down
4 changes: 3 additions & 1 deletion contracts/XCounterUC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation of timeoutTimestamp seems to misunderstand the purpose of CONST_TIME. Multiplying block.timestamp + timeoutSeconds by CONST_TIME does not align with the typical use of a timeout timestamp. If CONST_TIME is meant to represent a constant duration, it should likely be added to, not multiplied by, the current timestamp and timeout period.

- uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * CONST_TIME);
+ uint64 timeoutTimestamp = uint64(block.timestamp + (timeoutSeconds * CONST_TIME));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * CONST_TIME);
uint64 timeoutTimestamp = uint64(block.timestamp + (timeoutSeconds * CONST_TIME));


IbcUniversalPacketSender(mw).sendUniversalPacket(
channelId, IbcUtils.toBytes32(destPortAddr), payload, timeoutTimestamp
Expand Down