Skip to content

bip-0327: use a portable monotonic clock in the reference self-test - #2278

Open
fametrano wants to merge 1 commit into
bitcoin:masterfrom
fametrano:bip327-portable-monotonic-clock
Open

bip-0327: use a portable monotonic clock in the reference self-test#2278
fametrano wants to merge 1 commit into
bitcoin:masterfrom
fametrano:bip327-portable-monotonic-clock

Conversation

@fametrano

Copy link
Copy Markdown
Contributor

bip-0327/reference.py's self-test reads time.clock_gettime_ns(time.CLOCK_MONOTONIC) for extra_in. Both symbols are documented "Availability: Unix" in CPython, so python3 reference.py raises AttributeError on Windows.

time.monotonic_ns() is the portable monotonic clock CPython documents for measuring elapsed time, available on all platforms since 3.7. It returns the same nanosecond int, so .to_bytes(8, 'big') is unaffected.

Not tested on Windows; verified against CPython's platform-availability docs.

reference.py reads time.clock_gettime_ns(time.CLOCK_MONOTONIC) to vary
extra_in across signing iterations. Both symbols are documented
"Availability: Unix", so `python3 reference.py` raises AttributeError on
Windows.

time.monotonic_ns() is the portable monotonic clock CPython documents for
measuring elapsed time, available on all platforms since 3.7. Not tested
on Windows.
@murchandamus

Copy link
Copy Markdown
Member

I’m a bit on the fence regarding maintenance updates to the reference implementations, as this repository is not intended to maintain living code, but allows attaching reference implementations o illustrate how features could be implemented. From the linked report, it sounds like this is fixes a crash, though.

Since Python 3.7 has been out since 2018, this seems low-risk and benign, so SGTM. Will wait for a few days to see if the owners have an opinion.
cc: @jonasnick, @real-or-random, @robot-dreams

@murchandamus murchandamus added the Fixups Minor fixups not worth bothering the BIP author(s) for label Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fixups Minor fixups not worth bothering the BIP author(s) for

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants