refactor: keep duration calculations typed #35820

Closed
l0rinc wants to merge 13 commits from l0rinc/compile-time-chrono-hardening into master AGit
l0rinc commented 2026-07-27 05:06:59 +00:00 (Migrated from github.com)

Problem: Several fixed-duration calculations use raw integer time counts, leaving their units implicit and allowing unrelated integer values to be mixed.

Fix: Use std::chrono types through calculations where the surrounding APIs already support them, including GUI formatting, peer bans, scheduler forwarding, block timestamps, and target-spacing arithmetic.
Where carrying chrono through an integer interface would broaden the change or make the result harder to read, this PR leaves the expression unchanged or keeps the conversion simply duration / 1s.
The remaining integer interfaces receive the same values, and characterization tests pin the PoW timing and inclusive assumevalid threshold.

**Problem:** Several fixed-duration calculations use raw integer time counts, leaving their units implicit and allowing unrelated integer values to be mixed. **Fix:** Use `std::chrono` types through calculations where the surrounding APIs already support them, including GUI formatting, peer bans, scheduler forwarding, block timestamps, and target-spacing arithmetic. Where carrying chrono through an integer interface would broaden the change or make the result harder to read, this PR leaves the expression unchanged or keeps the conversion simply `duration / 1s`. The remaining integer interfaces receive the same values, and characterization tests pin the PoW timing and inclusive assumevalid threshold.
DrahtBot commented 2026-07-27 05:07:07 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK janb84

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36398 (wallet: only rebroadcast transactions originating from the wallet by mzumsande)
  • #35906 (First steps towards a stateless, side-effect free validation library by purpleKarrot)
  • #35716 (wallet: Replace mapWallet and wtxOrdered with a boost::multi_index by achow101)
  • #35570 (refactor: Change some validation.cpp methods to return BlockValidationState by optout21)
  • #35557 (kernel, validation: Add btck_chainstate_manager_set_clock_time by ryanofsky)
  • #35502 (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt)
  • #26022 (Add util::ResultPtr class by ryanofsky)
  • #25665 (refactor: Add util::Result failure types and ability to merge result values by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/35820 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35820.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35820#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [janb84](https://github.com/bitcoin/bitcoin/pull/35820#pullrequestreview-4786803820) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36398](https://github.com/bitcoin/bitcoin/pull/36398) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36398.svg"></sub> (wallet: only rebroadcast transactions originating from the wallet by mzumsande) * [#35906](https://github.com/bitcoin/bitcoin/pull/35906) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35906.svg"></sub> (First steps towards a stateless, side-effect free validation library by purpleKarrot) * [#35716](https://github.com/bitcoin/bitcoin/pull/35716) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35716.svg"></sub> (wallet: Replace mapWallet and wtxOrdered with a boost::multi_index by achow101) * [#35570](https://github.com/bitcoin/bitcoin/pull/35570) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35570.svg"></sub> (refactor: Change some validation.cpp methods to return BlockValidationState by optout21) * [#35557](https://github.com/bitcoin/bitcoin/pull/35557) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35557.svg"></sub> (kernel, validation: Add btck_chainstate_manager_set_clock_time by ryanofsky) * [#35502](https://github.com/bitcoin/bitcoin/pull/35502) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35502.svg"></sub> (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt) * [#26022](https://github.com/bitcoin/bitcoin/pull/26022) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/26022.svg"></sub> (Add util::ResultPtr class by ryanofsky) * [#25665](https://github.com/bitcoin/bitcoin/pull/25665) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/25665.svg"></sub> (refactor: Add util::Result failure types and ability to merge result values by ryanofsky) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
janb84 (Migrated from github.com) reviewed 2026-07-27 12:38:25 +00:00
janb84 (Migrated from github.com) left a comment

Concept ACK 7bb44a4b757c1d84091cd5518b5fa2abeb90168c

I like the clarity / readability this changes gives. It will even provide less proficient in C++ users to read consensus code.

Maybe split commit in kernel/consensus touching and the rest. In that way it's easy to ACK / review the consensus relevant changes.

Some NIT suggestions to use std::chrono::<<duration>> can be done on more places but I have limited the NITS to hear the current thinking first :)

Concept ACK 7bb44a4b757c1d84091cd5518b5fa2abeb90168c I like the clarity / readability this changes gives. It will even provide less proficient in C++ users to read consensus code. Maybe split commit in kernel/consensus touching and the rest. In that way it's easy to ACK / review the consensus relevant changes. Some NIT suggestions to use `std::chrono::<<duration>>` can be done on more places but I have limited the NITS to hear the current thinking first :)
janb84 (Migrated from github.com) commented 2026-07-27 12:33:29 +00:00

NIT: why not go one step further for even more clarity ?

static constexpr int STALE_RELAY_AGE_LIMIT{TicksSeconds(std::chrono::days{30})};

Note: not to use std::chrono::month{1};

NIT: why not go one step further for even more clarity ? ```suggestion static constexpr int STALE_RELAY_AGE_LIMIT{TicksSeconds(std::chrono::days{30})}; ``` Note: not to use std::chrono::month{1};
janb84 (Migrated from github.com) commented 2026-07-27 12:34:10 +00:00
static constexpr int HISTORICAL_BLOCK_AGE{TicksSeconds(std::chrono::weeks{1})};
```suggestion static constexpr int HISTORICAL_BLOCK_AGE{TicksSeconds(std::chrono::weeks{1})}; ```
Lines 788-791
janb84 (Migrated from github.com) commented 2026-07-27 12:18:04 +00:00

Just to unify this section I would opt for using std::chrono for every line. (not Blocking bike-shedding NIT)

    constexpr int HOUR_IN_SECONDS{TicksSeconds(std::chrono::hours{1})};
    constexpr int DAY_IN_SECONDS{TicksSeconds(std::chrono::days{1})};
    constexpr int WEEK_IN_SECONDS{TicksSeconds(std::chrono::weeks{1})};
    constexpr int YEAR_IN_SECONDS{TicksSeconds(std::chrono::years{1})};
Just to unify this section I would opt for using `std::chrono` for every line. (not Blocking bike-shedding NIT) ```suggestion constexpr int HOUR_IN_SECONDS{TicksSeconds(std::chrono::hours{1})}; constexpr int DAY_IN_SECONDS{TicksSeconds(std::chrono::days{1})}; constexpr int WEEK_IN_SECONDS{TicksSeconds(std::chrono::weeks{1})}; constexpr int YEAR_IN_SECONDS{TicksSeconds(std::chrono::years{1})}; ```
stickies-v commented 2026-07-27 13:07:08 +00:00 (Migrated from github.com)

~0, some minor clarity improvements here and there but for the most part I don't see the point as this doesn't add any actual type safety or clarity. I don't find 14 * 24 * 60 * 60; // two weeks harder to read than TicksSeconds(2 * 7 * 24h);

~0, some minor clarity improvements here and there but for the most part I don't see the point as this doesn't add any actual type safety or clarity. I don't find `14 * 24 * 60 * 60; // two weeks` harder to read than `TicksSeconds(2 * 7 * 24h);`
l0rinc commented 2026-07-28 01:36:14 +00:00 (Migrated from github.com)

Thanks for the review and feedback.

I agree that 14 * 24 * 60 * 60; // two weeks is readable in isolation - the main benefit is moving units from comments into expressions and (where possible), into types.

E.g. MIN_BLOCKS_TO_KEEP - 3600 / nPowTargetSpacing needed a (1 hour) comment (proving that others didn't consider them trivial), while MIN_BLOCKS_TO_KEEP - 1h / PowTargetSpacing() is self-describing and keeps both operands typed.

Likewise, 8 * 60 * 60; // in seconds becomes TicksSeconds(8h), making the conversion and units explicit.

The branch is now split by risk, with exact-value coverage for the consensus-sensitive changes.

Thanks for the review and feedback. I agree that `14 * 24 * 60 * 60; // two weeks` is readable in isolation - the main benefit is moving units from comments into expressions and (where possible), into types. E.g. `MIN_BLOCKS_TO_KEEP - 3600 / nPowTargetSpacing` needed a `(1 hour)` comment (proving that others didn't consider them trivial), while `MIN_BLOCKS_TO_KEEP - 1h / PowTargetSpacing()` is self-describing and keeps both operands typed. Likewise, `8 * 60 * 60; // in seconds` becomes `TicksSeconds(8h)`, making the conversion and units explicit. The branch is now split by risk, with exact-value coverage for the consensus-sensitive changes.
DrahtBot commented 2026-07-28 01:38:45 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/30320524467/job/90155255838
LLM reason (✨ experimental): CI failed because IWYU detected missing/incorrect includes and forced an error (“Failure generated from IWYU” / exit status 1).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `iwyu`: https://github.com/bitcoin/bitcoin/actions/runs/30320524467/job/90155255838</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU detected missing/incorrect includes and forced an error (“Failure generated from IWYU” / exit status 1).</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
maflcko (Migrated from github.com) reviewed 2026-07-28 18:04:47 +00:00
maflcko (Migrated from github.com) left a comment

Tend to agree with stickies. The changes as-is also violate the util/time.h docs.

Tend to agree with stickies. The changes as-is also violate the util/time.h docs.
maflcko (Migrated from github.com) commented 2026-07-28 18:03:43 +00:00

This seems like a step in the wrong direction. The docstring of TicksSeconds also says that it should be avoided in code.

the correct approach would be to write constexpr auto ...{90min}; and then use proper chrono types below: std::chrono::seconds secs{blockDate.secsTo(currentDate)};

This seems like a step in the wrong direction. The docstring of `TicksSeconds` also says that it should be avoided in code. the correct approach would be to write `constexpr auto ...{90min};` and then use proper chrono types below: `std::chrono::seconds secs{blockDate.secsTo(currentDate)};`
maflcko commented 2026-07-28 18:25:47 +00:00 (Migrated from github.com)

Follow-up to #35792.

Also, the pull description seems wrong. I fail to see how any of the changes here are related to ODR?

> Follow-up to [#35792](https://github.com/bitcoin/bitcoin/pull/35792). Also, the pull description seems wrong. I fail to see how any of the changes here are related to ODR?
l0rinc commented 2026-07-29 06:06:06 +00:00 (Migrated from github.com)

I fail to see how any of the changes here are related to ODR?

They're not, I noticed these raw duration expressions while reviewing #35792's changes, which is why I originally described this as a follow-up.
Since that wording can read as grouping the two changes, I removed it from the PR description.

The docstring of TicksSeconds also says that it should be avoided in code.

Thanks for the suggestion, I reworked the branch so durations remain typed where the surrounding APIs already support chrono, and I like it a lot better this way.
Where carrying chrono farther would broaden the change or make call sites harder to read, I left the expression unchanged or converted only where an existing interface still takes integer seconds.

> I fail to see how any of the changes here are related to ODR? They're not, I noticed these raw duration expressions while reviewing #35792's changes, which is why I originally described this as a follow-up. Since that wording can read as grouping the two changes, I removed it from the PR description. > The docstring of TicksSeconds also says that it should be avoided in code. Thanks for the suggestion, I reworked the branch so durations remain typed where the surrounding APIs already support chrono, and I like it a lot better this way. Where carrying chrono farther would broaden the change or make call sites harder to read, I left the expression unchanged or converted only where an existing interface still takes integer seconds.
maflcko (Migrated from github.com) reviewed 2026-07-29 06:21:50 +00:00
maflcko (Migrated from github.com) commented 2026-07-29 06:21:50 +00:00

not sure what exactly this is trying to enforce or harden. A plain 300 /* ms */ seems more readable and direct than a count_milliseconds(300ms) or the alternative used in other parts of this pull: 300ms / 1ms.

I think the chrono types should only be used when the type adds some compile-time checks. And I don't think replacing a 300-raw-int literal with a 300-chrono-literal, and a cast to int is adding any checks.

not sure what exactly this is trying to enforce or harden. A plain `300 /* ms */` seems more readable and direct than a `count_milliseconds(300ms)` or the alternative used in other parts of this pull: `300ms / 1ms`. I think the chrono types should only be used when the type adds some compile-time checks. And I don't think replacing a 300-raw-int literal with a 300-chrono-literal, and a cast to int is adding any checks.
l0rinc (Migrated from github.com) reviewed 2026-07-29 06:35:34 +00:00
l0rinc (Migrated from github.com) commented 2026-07-29 06:35:34 +00:00

Sure, I’ve reverted the ones that were arguably noisier than the original code. Thanks for the pushback!

Sure, I’ve reverted the ones that were arguably noisier than the original code. Thanks for the pushback!
l0rinc (Migrated from github.com) reviewed 2026-07-29 06:38:30 +00:00
l0rinc (Migrated from github.com) commented 2026-07-29 06:38:30 +00:00

think the chrono types should only be used when the type adds some compile-time checks.

I'd argue it's also valuable when we can remove comments that had to explain the values (e.g. 14 * 24 * 60 * 60; // two weeks) or when we can use the literals in range checks, e.g. if (delta_seconds <= 0 || delta_seconds > 3600) {.

> think the chrono types should only be used when the type adds some compile-time checks. I'd argue it's also valuable when we can remove comments that had to explain the values (e.g. `14 * 24 * 60 * 60; // two weeks`) or when we can use the literals in range checks, e.g. `if (delta_seconds <= 0 || delta_seconds > 3600) {`.
DrahtBot commented 2026-08-14 17:50:15 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
l0rinc commented 2026-08-18 00:51:05 +00:00 (Migrated from github.com)
Rebased after https://github.com/bitcoin/bitcoin/pull/35852
DrahtBot commented 2026-08-31 16:52:46 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-09-24 17:22:42 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/36026083226/job/107722840641
LLM reason (✨ experimental): CI failed because the IWYU check detected required include changes (edited /src/rpc/node.cpp and other file), causing it to exit non-zero.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `iwyu`: https://github.com/bitcoin/bitcoin/actions/runs/36026083226/job/107722840641</sub> <sub>LLM reason (✨ experimental): CI failed because the IWYU check detected required include changes (edited `/src/rpc/node.cpp` and other file), causing it to exit non-zero.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
First-time contributor

1 suggestion

🔵 Suggestion

Assumevalid test does not pin the exact two-week threshold

Location: test/functional/feature_assumevalid.py:190 (head).

The test catches a threshold below two weeks and a changed <= comparison, but a larger threshold still passes.

Details and suggested fix

Node 2 receives 2017 headers, placing block 1 exactly two weeks of equivalent work behind the best header. The test expects script verification to remain enabled, so it catches a lower threshold or changing <= to <. But the nearest case that expects verification to be skipped places block 1 1,320,600 seconds behind; any threshold from two weeks up to that value still passes. For example, a mistaken 15-day threshold would go undetected. Such a mistake would make the node check more scripts, so this is a test-precision gap, not a safety problem. Send node 2 one additional header and check both sides of the boundary: block 1 should disable script verification at 2017 blocks behind, and block 2 should enable it at exactly 2016 blocks behind. Update the getchaintips lookup to self.blocks[BURIED_HEADER_COUNT]; block 102 remains checked, so the existing rejection assertions still hold.


Reviewed: 261fff951c5c · Full review report · Previous reports

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:87bdde6e11c8200ebab55606962dbcbbed1f25d8bebf674c6c6e659db1fe52cc:8f5adaa231eb1aff4d179f52d5ea908b8cc3066455d0b32a1baa87e2b34c9f86 --> <!-- ralph-base:9bf4815b94b9eaf8807f4e569091778da6c338d5 --> <!-- ralph-head:261fff951c5c7751794516b73429ba4bcb633df0 --> <!-- ralph-case:ccd730f84c2bf505e84a905bcc61652766e15bb745cbb0fd817816a16df2521f --> 1 suggestion **🔵 Suggestion** **Assumevalid test does not pin the exact two-week threshold** Location: [`test/functional/feature_assumevalid.py:190`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/261fff951c5c7751794516b73429ba4bcb633df0/test/functional/feature_assumevalid.py#L190>) (head). The test catches a threshold below two weeks and a changed `<=` comparison, but a larger threshold still passes. <details> <summary>Details and suggested fix</summary> Node 2 receives 2017 headers, placing block 1 exactly two weeks of equivalent work behind the best header. The test expects script verification to remain enabled, so it catches a lower threshold or changing `<=` to `<`. But the nearest case that expects verification to be skipped places block 1 1,320,600 seconds behind; any threshold from two weeks up to that value still passes. For example, a mistaken 15-day threshold would go undetected. Such a mistake would make the node check more scripts, so this is a test-precision gap, not a safety problem. Send node 2 one additional header and check both sides of the boundary: block 1 should disable script verification at 2017 blocks behind, and block 2 should enable it at exactly 2016 blocks behind. Update the `getchaintips` lookup to `self.blocks[BURIED_HEADER_COUNT]`; block 102 remains checked, so the existing rejection assertions still hold. </details> <!-- Review tier: sensitive --> --- Reviewed: [`261fff951c5c`](<https://git.fish.foo/bitcoin/bitcoin/commit/261fff951c5c7751794516b73429ba4bcb633df0>) · [Full review report](<https://review.fish.foo/traces/35820-261fff951c5c7751794516b73429ba4bcb633df0-1663-3.html>) · [Previous reports](<https://review.fish.foo/traces/35820/>)
sedited commented 2026-11-06 14:00:33 +00:00 (Migrated from github.com)

This has not received review for some time now and the response to the changes has been somewhat lukewarm. I'm also not entirely convinced that std::chrono::weeks{2} / 1s is more readable/better than 14 * 24 * 60 * 60; // two weeks. The division by 1s is still something that a casual reader would have to read up on imo. Maybe this should be reconsidered?

This has not received review for some time now and the response to the changes has been somewhat lukewarm. I'm also not entirely convinced that `std::chrono::weeks{2} / 1s` is more readable/better than `14 * 24 * 60 * 60; // two weeks`. The division by `1s` is still something that a casual reader would have to read up on imo. Maybe this should be reconsidered?
maflcko commented 2026-11-06 14:11:55 +00:00 (Migrated from github.com)

Yeah, I like the concept of moving toward chrono types, but if the casts are just "normalized" or "hidden" via /1s, it seems more confusing than helpful. I think it is fine to have some casts, but they should be verbose and use Ticks or TicksSinceEpoch, so that they either act as explicit documentation, or can be removed in the future.

So I think stuff like this is fine to use:

    int blockcount = std::chrono::days{30} / chainman.GetParams().GetConsensus().PowTargetSpacing();

However, this is not:

        consensus.nPowTargetSpacing = 10min / 1s;

I'd be happy to review a pull with the first type of changes, but the second one can be left for now as-is.

Yeah, I like the concept of moving toward chrono types, but if the casts are just "normalized" or "hidden" via `/1s`, it seems more confusing than helpful. I think it is fine to have some casts, but they should be verbose and use `Ticks` or `TicksSinceEpoch`, so that they either act as explicit documentation, or can be removed in the future. So I think stuff like this is fine to use: ```cpp int blockcount = std::chrono::days{30} / chainman.GetParams().GetConsensus().PowTargetSpacing(); ``` However, this is not: ```cpp consensus.nPowTargetSpacing = 10min / 1s; ``` I'd be happy to review a pull with the first type of changes, but the second one can be left for now as-is.
l0rinc commented 2026-11-06 19:47:54 +00:00 (Migrated from github.com)

Up for grabs

Up for grabs
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!35820
No description provided.