Skip to content

Commit

Permalink
use nanoseconds for ibc timeout (#814)
Browse files Browse the repository at this point in the history
also closes #812
  • Loading branch information
turbocrime authored Mar 21, 2024
1 parent 9609ae9 commit 670251d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions apps/minifront/src/state/ibc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ export const createIbcSendSlice = (): SliceCreator<IbcSendSlice> => (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
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/ui/tx/view/isc20-withdrawal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const Ics20WithdrawalComponent = ({ value }: { value: Ics20Withdrawal })
)}

<ActionDetails.Row label='Timeout Time'>
{new Date(Number(value.timeoutTime)).toString()}
{new Date(Number(BigInt(value.timeoutTime) / 1_000_000n)).toString()}
</ActionDetails.Row>
</ActionDetails>
}
Expand Down

0 comments on commit 670251d

Please sign in to comment.