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

bug: nanoseconds #310

Closed
SgtPooki opened this issue Mar 19, 2024 · 1 comment
Closed

bug: nanoseconds #310

SgtPooki opened this issue Mar 19, 2024 · 1 comment
Labels
need/triage Needs initial labeling and prioritization

Comments

@SgtPooki
Copy link
Member

SgtPooki commented Mar 19, 2024

Nanoseconds are calculated incorrectly. See ipfs/helia-verified-fetch#19 (comment) for more details. Basically,

Some proofs (copy and paste into dev console):

  • nanoseconds are 1e9, or "One billionth of one second".
    • BigInt(1)/*<s>*/ * BigInt(1e9)/*<ns>*/ === (1000000000n)/*<ns>*/ /* 1,000,000,000/*<ns>*/
    • 1000000000/*<ns>*/ * 1e-9/*<ns-to-s>*/ === 1
  • milliseconds are "1e6" or "One millionth of one second"
    • BigInt(1)/*<s>*/ * BigInt(1e6)/*<ms>*/ === 1000000n/*<ms>*/ /* === 1,000,000/*<ms>*/
    • 1000000/*<ms>*/ * 1e-6/*<ms-to-s>*/ === 1
  • nanoseconds are 1e6 or "One millionth of one millisecond"
    • BigInt(1)/*<ms>*/ * BigInt(1e6)/*<ns>*/ === 1000000n/*<ns>*/ /* === 1,000,000/*<ms>*/
    • 1000000/*<ns>*/ * 1e-6/*<ns-to-ms>*/ === 1

const lifetimeNs = (BigInt(ms) * BigInt(100000)) + BigInt(ns ?? '0')
creates lifeTimeNs as:

function lifeTimeNs(ms, ns) {
    // BigInt(100000) === BigInt(1e5)
    return (BigInt(ms) * BigInt(100000)) + BigInt(ns ?? '0')
}
// should match BigInt(1)/*<ms>*/ * BigInt(1e6)/*<ns>*/ === 1000000n/*<ns>*/
lifeTimeNs(1) === BigInt(1e6) // false, 
// returns `100000n` instead of `1000000n`

references:

@SgtPooki SgtPooki added the need/triage Needs initial labeling and prioritization label Mar 19, 2024
Copy link

welcome bot commented Mar 19, 2024

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review.
In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment.
Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

github-actions bot pushed a commit that referenced this issue Apr 2, 2024
## [9.1.0](v9.0.0...v9.1.0) (2024-04-02)

### Features

* change default TTL and add support for custom TTL ([#1](#1)) ([#308](#308)) ([d647529](d647529)), closes [/specs.ipfs.tech/ipns/ipns-record/#ttl-uint64](https://github.com/ipfs//specs.ipfs.tech/ipns/ipns-record//issues/ttl-uint64) [#310](#310)

### Trivial Changes

* add or force update .github/workflows/js-test-and-release.yml ([#311](#311)) ([0c5f3e1](0c5f3e1))
* add or force update .github/workflows/js-test-and-release.yml ([#312](#312)) ([46a2b72](46a2b72))
* add or force update .github/workflows/js-test-and-release.yml ([#313](#313)) ([e933496](e933496))
* Update .github/workflows/stale.yml [skip ci] ([16e0e10](16e0e10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

1 participant