From 670251db132df1191546961d5513a91e4c9b2aee Mon Sep 17 00:00:00 2001 From: turbocrime <134443988+turbocrime@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:39:22 -0700 Subject: [PATCH] use nanoseconds for ibc timeout (#814) also closes #812 --- apps/minifront/src/state/ibc.ts | 8 ++++++-- packages/ui/components/ui/tx/view/isc20-withdrawal.tsx | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/minifront/src/state/ibc.ts b/apps/minifront/src/state/ibc.ts index 778ee21611..393c833ade 100644 --- a/apps/minifront/src/state/ibc.ts +++ b/apps/minifront/src/state/ibc.ts @@ -94,8 +94,12 @@ export const createIbcSendSlice = (): SliceCreator => (set, get) = const getTimeout = async ( chain: Chain, ): Promise<{ timeoutTime: bigint; timeoutHeight: Height }> => { - const twoDaysInMilliseconds = 2 * 24 * 60 * 60 * 1000; // 2 days * 24 hours/day * 60 minutes/hour * 60 seconds/minute * 1000 milliseconds/second - const timeoutTime = BigInt(Date.now() + twoDaysInMilliseconds); + // timeout 2 days from now, in nanoseconds since epoch + const twoDaysMs = BigInt(2 * 24 * 60 * 60 * 1000); // 2 days * 24 hours/day * 60 minutes/hour * 60 seconds/minute * 1000 milliseconds per second + // truncate resolution at seconds, to obfuscate clock skew + const lowPrecisionNowMs = BigInt(Math.floor(Date.now() / 1000) * 1000); // ms/1000 to second, floor, second*1000 to ms + // (now + two days) as nanoseconds + const timeoutTime = (lowPrecisionNowMs + twoDaysMs) * 1_000_000n; // 1 million nanoseconds per millisecond const { clientStates } = await ibcClient.clientStates({}); const unpacked = clientStates diff --git a/packages/ui/components/ui/tx/view/isc20-withdrawal.tsx b/packages/ui/components/ui/tx/view/isc20-withdrawal.tsx index 0dfa4d8f4f..1ef4b3aedd 100644 --- a/packages/ui/components/ui/tx/view/isc20-withdrawal.tsx +++ b/packages/ui/components/ui/tx/view/isc20-withdrawal.tsx @@ -42,7 +42,7 @@ export const Ics20WithdrawalComponent = ({ value }: { value: Ics20Withdrawal }) )} - {new Date(Number(value.timeoutTime)).toString()} + {new Date(Number(BigInt(value.timeoutTime) / 1_000_000n)).toString()} }