Commit Graph

3914 Commits

Author SHA1 Message Date
Andrew Poelstra 06dc05c55b
Merge rust-bitcoin/rust-bitcoin#2450: kani: fix Amount overflow test
343510d3a0 kani: fix Amount overflow test (Andrew Poelstra)

Pull request description:

  Our Kani CI job is currently failing. See https://github.com/rust-bitcoin/rust-bitcoin/actions/runs/7770495422/job/21190756253

  This fixes one of the issues; the other is that we're hitting a multiplication assertion in the test we added in https://github.com/rust-bitcoin/rust-bitcoin/pull/2393 which I'm unsure how to deal with.

  For reference, testing this was a bit of a PITA. I needed to

  ```
  # Ok, these steps are easy/obvious
  cargo install kani-verifier
  cargo kani
  ```

  This will give you an error located in core/panic.rs or something with the description `This is a placeholder message; Kani doesn't support message formatted at runtime` which is not super helpful. To get the actual failure, you need to write

  ```
  cargo kani --enable-unstable --concrete-playback=inplace
  ```

  which will add a weird unit test which calls into Kani to exercise the original test with a specific input value. Because it calls into Kani you can't just run it with `cargo test`. You need to run

  ```
  RUST_BACKTRACE=1 CARGO_INCREMENTAL=0 cargo kani playback -Z concrete-playback -- kani_concrete_playback_check_div_rem_8626518785677487871
  ```

  where `CARGO_INCREMENTAL=0` disables incremental compilation (this was causing rustc to flame out with a "filename too long" error because it was trying to create some intermediate file with multiple hashes and crate names in it), and the `kani_concrete_playback_123456789` thing is the name of the test that gets added (which you can easily find by reading `git diff`).

ACKs for top commit:
  tcharding:
    ACK 343510d3a0
  Kixunil:
    ACK 343510d3a0

Tree-SHA512: 398ce3c61ffa3246bd27ae5719b4ac4fda587e87b8645ec8418fdfd039e4ed78d58233faab27bc63df7e2a30bb5467660e77a6e3d3a08fe86e7ff3dd31869ec7
2024-02-06 13:19:06 +00:00
Tobin C. Harding 3c62f74684
Add public functions p2wpkh_script_code
Add two public API functions on the two public keys, both called
`p2wpkh_script_code` to do exactly as the name suggests.

Of note, I was not able to find anywhere to use these in example code,
this is because of we always use the new `p2wpkh_signature_hash`
function. The new functions may be useful for a user calling
`segwit_v0_encode_signing_data_to`. The may help document the library as
well.
2024-02-06 14:35:54 +11:00
Tobin C. Harding c084afa8b2
Print hex in Debug for Sequence
Printing the `Sequence` as a decimal is not super useful when debugging,
print it in hex instead.

Using code:

        let seq = Sequence::from_consensus(0xFFFFFFFF);
        println!("sequence: {:?}", seq);

Before applying this patch we get:

        sequence: Sequence(4294967295)

And after applying we get:

        sequence: Sequence(0xffffffff)
2024-02-06 12:25:37 +11:00
Andrew Poelstra 343510d3a0
kani: fix Amount overflow test 2024-02-05 18:52:13 +00:00
Andrew Poelstra 92a0969994
Merge rust-bitcoin/rust-bitcoin#2442: Remove non_exhaustive from struct errors with pub inner
8c17ad7fd7 Remove non_exhaustive from struct errors with pub inner (Tobin C. Harding)

Pull request description:

  Using `non_exhaustive` as well as a public inner field is incorrect, it prohibits users from creating or matching on the error and does not achieve forward comparability.

  This was never right, we shouldn't have done it.

ACKs for top commit:
  Kixunil:
    ACK 8c17ad7fd7
  apoelstra:
    ACK 8c17ad7fd7

Tree-SHA512: 41266aaea25e0e5dba22200725e71f7cc23f386f3990c9d0b831980db2cfb431791ba14d6c6b144bd7db90f2f5dc9df38856f23fade0d7aee68217c4c879d3e0
2024-02-05 15:32:10 +00:00
Andrew Poelstra f496eec487
Merge rust-bitcoin/rust-bitcoin#2448: Bump peter-evans/create-pull-request from 5 to 6
d61bb3816f Bump peter-evans/create-pull-request from 5 to 6 (dependabot[bot])

Pull request description:

  Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 5 to 6.
  <details>
  <summary>Release notes</summary>
  <p><em>Sourced from <a href="https://github.com/peter-evans/create-pull-request/releases">peter-evans/create-pull-request's releases</a>.</em></p>
  <blockquote>
  <h2>Create Pull Request v6.0.0</h2>
  <h2>Behaviour changes</h2>
  <ul>
  <li>The default values for <code>author</code> and <code>committer</code> have changed. See &quot;What's new&quot; below for details. If you are overriding the default values you will not be affected by this change.</li>
  <li>On completion, the action now removes the temporary git remote configuration it adds when using <code>push-to-fork</code>. This should not affect you unless you were using the temporary configuration for some other purpose after the action completes.</li>
  </ul>
  <h2>What's new</h2>
  <ul>
  <li>Updated runtime to Node.js 20
  <ul>
  <li>The action now requires a minimum version of <a href="https://github.com/actions/runner/releases/tag/v2.308.0">v2.308.0</a> for the Actions runner. Update self-hosted runners to v2.308.0 or later to ensure compatibility.</li>
  </ul>
  </li>
  <li>The default value for <code>author</code> has been changed to <code>${{ github.actor }} &lt;${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com&gt;</code>. The change adds the <code>${{ github.actor_id }}+</code> prefix to the email address to align with GitHub's standard format for the author email address.</li>
  <li>The default value for <code>committer</code> has been changed to <code>github-actions[bot] &lt;41898282+github-actions[bot]@users.noreply.github.com&gt;</code>. This is to align with the default GitHub Actions bot user account.</li>
  <li>Adds input <code>git-token</code>, the <a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token">Personal Access Token (PAT)</a> that the action will use for git operations. This input defaults to the value of <code>token</code>. Use this input if you would like the action to use a different token for git operations than the one used for the GitHub API.</li>
  <li><code>push-to-fork</code> now supports pushing to sibling repositories in the same network.</li>
  <li>Previously, when using <code>push-to-fork</code>, the action did not remove temporary git remote configuration it adds during execution. This has been fixed and the configuration is now removed when the action completes.</li>
  <li>If the pull request body is truncated due to exceeding the maximum length, the action will now suffix the body with the message &quot;...<em>[Pull request body truncated]</em>&quot; to indicate that the body has been truncated.</li>
  <li>The action now uses <code>--unshallow</code> only when necessary, rather than as a default argument of <code>git fetch</code>. This should improve performance, particularly for large git repositories with extensive commit history.</li>
  <li>The action can now be executed on one GitHub server and create pull requests on a <em>different</em> GitHub server. Server products include GitHub hosted (github.com), GitHub Enterprise Server (GHES), and GitHub Enterprise Cloud (GHEC). For example, the action can be executed on GitHub hosted and create pull requests on a GHES or GHEC instance.</li>
  </ul>
  <h2>What's Changed</h2>
  <ul>
  <li>Update distribution by <a href="https://github.com/actions-bot"><code>@actions-bot</code></a> in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/2086">peter-evans/create-pull-request#2086</a></li>
  <li>fix crazy-max/ghaction-import-gp parameters by <a href="https://github.com/fharper"><code>@fharper</code></a> in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/2177">peter-evans/create-pull-request#2177</a></li>
  <li>Update distribution by <a href="https://github.com/actions-bot"><code>@actions-bot</code></a> in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/2364">peter-evans/create-pull-request#2364</a></li>
  <li>Use checkout v4 by <a href="https://github.com/okuramasafumi"><code>@okuramasafumi</code></a> in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/2521">peter-evans/create-pull-request#2521</a></li>
  <li>Note about <code>delete-branch</code> by <a href="https://github.com/dezren39"><code>@dezren39</code></a> in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/2631">peter-evans/create-pull-request#2631</a></li>
  <li>98 dependency updates by <a href="https://github.com/dependabot"><code>@dependabot</code></a></li>
  </ul>
  <h2>New Contributors</h2>
  <ul>
  <li><a href="https://github.com/fharper"><code>@fharper</code></a> made their first contribution in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/2177">peter-evans/create-pull-request#2177</a></li>
  <li><a href="https://github.com/okuramasafumi"><code>@okuramasafumi</code></a> made their first contribution in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/2521">peter-evans/create-pull-request#2521</a></li>
  <li><a href="https://github.com/dezren39"><code>@dezren39</code></a> made their first contribution in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/2631">peter-evans/create-pull-request#2631</a></li>
  </ul>
  <p><strong>Full Changelog</strong>: <a href="https://github.com/peter-evans/create-pull-request/compare/v5.0.2...v6.0.0">https://github.com/peter-evans/create-pull-request/compare/v5.0.2...v6.0.0</a></p>
  <h2>Create Pull Request v5.0.2</h2>
  <p>⚙️ Fixes an issue that occurs when using <code>push-to-fork</code> and both base and head repositories are in the same org/user account.</p>
  <h2>What's Changed</h2>
  <ul>
  <li>fix: specify head repo by <a href="https://github.com/peter-evans"><code>@peter-evans</code></a> in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/2044">peter-evans/create-pull-request#2044</a></li>
  <li>20 dependency updates by <a href="https://github.com/dependabot"><code>@dependabot</code></a></li>
  </ul>
  <p><strong>Full Changelog</strong>: <a href="https://github.com/peter-evans/create-pull-request/compare/v5.0.1...v5.0.2">https://github.com/peter-evans/create-pull-request/compare/v5.0.1...v5.0.2</a></p>
  <h2>Create Pull Request v5.0.1</h2>
  <h2>What's Changed</h2>
  <ul>
  <li>fix: truncate body if exceeds max length by <a href="https://github.com/peter-evans"><code>@peter-evans</code></a> in <a href="https://redirect.github.com/peter-evans/create-pull-request/pull/1915">peter-evans/create-pull-request#1915</a></li>
  <li>12 dependency updates by <a href="https://github.com/dependabot"><code>@dependabot</code></a></li>
  </ul>
  <p><strong>Full Changelog</strong>: <a href="https://github.com/peter-evans/create-pull-request/compare/v5.0.0...v5.0.1">https://github.com/peter-evans/create-pull-request/compare/v5.0.0...v5.0.1</a></p>
  </blockquote>
  </details>
  <details>
  <summary>Commits</summary>
  <ul>
  <li><a href="b1ddad2c99"><code>b1ddad2</code></a> feat: v6 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2717">#2717</a>)</li>
  <li><a href="bb809027fd"><code>bb80902</code></a> build(deps-dev): bump <code>@types/node</code> from 18.19.8 to 18.19.10 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2712">#2712</a>)</li>
  <li><a href="e0037d470c"><code>e0037d4</code></a> build(deps): bump peter-evans/create-or-update-comment from 3 to 4 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2702">#2702</a>)</li>
  <li><a href="94b1f99e3a"><code>94b1f99</code></a> build(deps): bump peter-evans/find-comment from 2 to 3 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2703">#2703</a>)</li>
  <li><a href="69c27eaf4a"><code>69c27ea</code></a> build(deps-dev): bump ts-jest from 29.1.1 to 29.1.2 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2685">#2685</a>)</li>
  <li><a href="7ea722a0f6"><code>7ea722a</code></a> build(deps-dev): bump prettier from 3.2.2 to 3.2.4 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2684">#2684</a>)</li>
  <li><a href="5ee839affd"><code>5ee839a</code></a> build(deps-dev): bump <code>@types/node</code> from 18.19.7 to 18.19.8 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2683">#2683</a>)</li>
  <li><a href="60fc256c67"><code>60fc256</code></a> build(deps-dev): bump eslint-plugin-prettier from 5.1.2 to 5.1.3 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2660">#2660</a>)</li>
  <li><a href="0c67723361"><code>0c67723</code></a> build(deps-dev): bump <code>@types/node</code> from 18.19.5 to 18.19.7 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2661">#2661</a>)</li>
  <li><a href="4e288e851b"><code>4e288e8</code></a> build(deps-dev): bump prettier from 3.1.1 to 3.2.2 (<a href="https://redirect.github.com/peter-evans/create-pull-request/issues/2659">#2659</a>)</li>
  <li>Additional commits viewable in <a href="https://github.com/peter-evans/create-pull-request/compare/v5...v6">compare view</a></li>
  </ul>
  </details>
  <br />

  [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=peter-evans/create-pull-request&package-manager=github_actions&previous-version=5&new-version=6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

  Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

  [//]: # (dependabot-automerge-start)
  [//]: # (dependabot-automerge-end)

  ---

  <details>
  <summary>Dependabot commands and options</summary>
  <br />

  You can trigger Dependabot actions by commenting on this PR:
  - `@dependabot rebase` will rebase this PR
  - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
  - `@dependabot merge` will merge this PR after your CI passes on it
  - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
  - `@dependabot cancel merge` will cancel a previously requested merge and block automerging
  - `@dependabot reopen` will reopen this PR if it is closed
  - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
  - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

  </details>

ACKs for top commit:
  apoelstra:
    ACK d61bb3816f will merge with one ACK; appears this does not break CI

Tree-SHA512: fb05155a107500e169fd413551c970c0899bb1caea8e8ead4f9bac64f583f73d3c9145f92dfea6d97461676840e3a100e7e48ecd193e95a606c3be4c944a6035
2024-02-05 14:56:43 +00:00
dependabot[bot] d61bb3816f
Bump peter-evans/create-pull-request from 5 to 6
Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 5 to 6.
- [Release notes](https://github.com/peter-evans/create-pull-request/releases)
- [Commits](https://github.com/peter-evans/create-pull-request/compare/v5...v6)

---
updated-dependencies:
- dependency-name: peter-evans/create-pull-request
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-05 10:29:03 +00:00
Tobin C. Harding a246dc98a4
Run sighash example in CI
Somehow we forgot to run the `sighash` example in CI.
2024-02-05 17:50:52 +11:00
Tobin C. Harding 8c17ad7fd7
Remove non_exhaustive from struct errors with pub inner
Using `non_exhaustive` as well as a public inner field is incorrect, it
prohibits users from creating or matching on the error and does not
achieve forward comparability.

This was never right, we shouldn't have done it.
2024-02-05 16:26:31 +11:00
Tobin C. Harding f317d87ee6
io: Enable "alloc" from "std"
As is customary in our crates, enable the "alloc" feature from the "std"
feature. This allows simplifying the feature gating.
2024-02-05 11:58:10 +11:00
Tobin C. Harding 1d00d47b32
io: Add Changelog
Done in preparation for an initial v0.1.0 release of the new `io` crate.

Add a changelog file with a brief description of whats in the initial release.
2024-02-05 11:58:10 +11:00
Tobin C. Harding 83397c465c
io: Add documentation to all public types and functions
Add docs for all public types and add a lint to enforce this going
forwards.

Use `allow` attribute in macro, will be fixed as a subsequent patch.
2024-02-05 11:58:10 +11:00
Tobin C. Harding 2810b08b0d
io: Add code comment to feature gate
This feature gate requires a little thought to understand, add a code
comment to save the next guy some clock cycles.
2024-02-05 11:58:10 +11:00
Tobin C. Harding 4cf2bf4b40
io: Make Take::read_to_end public
Currently `Take::read_to_end` is private forcing users to use our
"custom" `read_to_limit`, for seasoned Rust hackers
`foo.take(16).read_to_end(buf)` make be more unsurprising.

Make `read_to_end` public.
2024-02-05 11:58:10 +11:00
Andrew Poelstra a3c4194c3f
Merge rust-bitcoin/rust-bitcoin#2428: Remove the remaining TODOs
c69caafefc Remove attribute comments (Tobin C. Harding)
3e83ef9276 Remove consensus error wrapper TODO (Tobin C. Harding)
bfabea94e9 Remove unwrap comment (Tobin C. Harding)
8bdaf4a34d Remove carrying_mul TODO (Tobin C. Harding)

Pull request description:

  Add issues and remove the TODOs from the code.

  Resolves: #2368

ACKs for top commit:
  apoelstra:
    ACK c69caafefc
  Kixunil:
    ACK c69caafefc

Tree-SHA512: b10a3de8da7ace890735023f8441605dd11b0227c27a2357556b8aaa8276a7f34ed220e3bcbc93aad4b35357319318ff7de27210e8f60dd90f6c55af23e21470
2024-02-02 23:39:16 +00:00
Andrew Poelstra 585af9da27
Merge rust-bitcoin/rust-bitcoin#2353: Epic CI overhaul
01a66a7fa7 CI: Check for required commands (Tobin C. Harding)
5c15ed5441 CI: Epic overhaul (Martin Habovstiak)
242aa676b3 Use env bash instead of /bin/bash (Tobin C. Harding)
422d30117c Use bash to run shell scripts (Tobin C. Harding)

Pull request description:

  The combination of some work by myself [0] and Kix [1].

  Draft so I can use github's infrastructure to test it all out.

  Includes some patches at the front to fix real issues that the new test infrastructure found - WIN.

  [0] https://github.com/rust-bitcoin/rust-bitcoin/pull/2328
  [1] https://github.com/rust-bitcoin/rust-bitcoin/pull/2343

  Coincidentally this closes 1124

  Resolve: #1124

ACKs for top commit:
  apoelstra:
    ACK 01a66a7fa7

Tree-SHA512: 026a0948a181102246702eadc3ff245c319c456b03ada9ca269141d006146f30fd8eb50377062735a06c3e369f7edac2e334587120338a3747810d999177d930
2024-02-02 23:30:29 +00:00
Tobin C. Harding 01a66a7fa7
CI: Check for required commands
Add a function to check for commands used by the `run_task` script. Move
the version printing to after the check. Also print the bash version in
use.
2024-02-02 11:35:56 +11:00
Tobin C. Harding c69caafefc
Remove attribute comments
Add an issue and remove the TODO from the code as well as the attribute
comments, leave a single comment as an explanation of why the unusual
code block.

ref: https://github.com/rust-bitcoin/rust-bitcoin/issues/2427
2024-02-02 06:22:02 +11:00
Martin Habovstiak 5c15ed5441
CI: Epic overhaul
Re-write the whole CI pipeline.

Co-developed-by: Martin Habovstiak <martin.habovstiak@gmail.com>
2024-02-02 05:57:23 +11:00
Tobin C. Harding 242aa676b3
Use env bash instead of /bin/bash
As we do in all the other shell scripts use `env` to call `bash`.
2024-02-02 05:57:23 +11:00
Tobin C. Harding 422d30117c
Use bash to run shell scripts
Use `bash` instead of `sh` to run shell scripts.

We would like to support Nix users who do not typically have any shell
other than `sh` at a known path, therefore use `/usr/bin/env bash`.
2024-02-02 05:55:51 +11:00
Andrew Poelstra 7b937acf17
Merge rust-bitcoin/rust-bitcoin#2403: Make crate level attributes uniform
0997382772 io: Enable alloc from std (Tobin C. Harding)
ba1166a63b Make crate level attributes uniform (Tobin C. Harding)

Pull request description:

  Make the trait level attributes uniform across all released crates in the repo. Excludes things that are obviously not needed, eg, bench stuff if there is not bench code.

  - Remove `uninhabited_references` - this is allow by default now.
  - Remove `unconditional_recursion` and mark the single false positive we have with an `allow`.

  Note, this does not add `missing_docs` to the `io` crate. There is an open PR at the moment to add that along with the required docs.

ACKs for top commit:
  apoelstra:
    ACK 0997382772
  Kixunil:
    ACK 0997382772

Tree-SHA512: ef1f638aca171536287cce369be98998e871d26468ad2d8c39d9004db610b406471809c283540a4a19bcede78b12b8976a1bb37e5d431fbff8c8a3e53a64d4e3
2024-02-01 14:17:16 +00:00
Andrew Poelstra 05e21a2f39
Merge rust-bitcoin/rust-bitcoin#2430: Fix kani test
4383202f23 CI: Add a job to build kani proofs (Tobin C. Harding)
96d3bbd065 Fix kani test (Tobin C. Harding)

Pull request description:

  Recently (in #2379) we patched the `ParseAmountError` but we don't check kani code on every pull request so we broke it.

  Fix kani test to use the new `OutOfRangeError`.

  EDIT: Attempt, as a separate patch, to add a job that runs on each PR to build the kani test code.

  Close: #2424

ACKs for top commit:
  Kixunil:
    ACK 4383202f23
  apoelstra:
    ACK 4383202f23

Tree-SHA512: dcddcb0d52201efb3246733e9f164f5acde22df256fc4985b23050628ab9ae9c20a80ecd4ab468558b0a8708dacf6f7af099e8303cf4f73e1557e454c351aa34
2024-02-01 14:00:07 +00:00
Tobin C. Harding 4383202f23
CI: Add a job to build kani proofs
Currently we do not build the code in the kani tests when PRs are
pushed, instead we run the verifier once a day. We should at least check
the code builds on each PR. One way to do this is to build the proofs
without running them, `kani --only-codegen` does that.
2024-02-01 15:44:38 +11:00
Tobin C. Harding 96d3bbd065
Fix kani test
Recently (in #2379) we patched the `ParseAmountError` but we don't check
kani code on every pull request so we broke it.

Fix kani test to use the new `OutOfRangeError`.

Close: #2424
2024-02-01 15:13:50 +11:00
Tobin C. Harding 3e83ef9276
Remove consensus error wrapper TODO
Add an issue and remove the TODO from the code.

ref: https://github.com/rust-bitcoin/rust-bitcoin/issues/2429
2024-02-01 15:00:46 +11:00
Tobin C. Harding bfabea94e9
Remove unwrap comment
Add an issue and remove the TODO from the code.

ref: https://github.com/rust-bitcoin/rust-bitcoin/issues/2426
2024-02-01 12:32:42 +11:00
Tobin C. Harding 8bdaf4a34d
Remove carrying_mul TODO
Add an issue and remove the TODO from the code.

ref: https://github.com/rust-bitcoin/rust-bitcoin/issues/2425
2024-02-01 12:28:43 +11:00
Andrew Poelstra 8efaf4a300
Merge rust-bitcoin/rust-bitcoin#2417: Improve lock time errors
93dba898c2 Improve lock time errors (Martin Habovstiak)

Pull request description:

  The errors returned from various lock time functions had several issues. Among the obvious - `Error` being returned from all operations even when some of its variants were unreachable, there were subtle issues around error messages:

  * `ParseIntError` didn't contain information whether the parsed object is `Height` or `Time`.
  * Logically overflow and out-of-bounds should be the same thing but produced different error messages.
  * Mentioning integers is too technical for a user, talking about upper and lower bound is easier to understand.
  * When minus sign is present `std` reports it as invalid digit which is less helpful than saying negative numbers are not allowed.

  It is also possible that `ParseIntError` will need to be removed from public API during crate smashing or stabilization, so avoiding it may be better.

  This commit significantly refactors the errors. It adds separate types for parsing `Height` and `Time`. Notice that we don't compose them from `ParseIntError` and `ConversionError` - that's not helpful because they carry information that wouldn't be used when displaying which is wasteful. Keeping errors small can be important.

  It's also worth noting that exposing the inner representation could cause confusion since the same thing: out of bounds can be represented as an overflow or as a conversion error. So for now we conservatively hide the details and even pretend there's no `source` in case of overflow. This can be expanded in the future if needed.

  The returned errors are now minimal. `LockTime` parsing errors are currentlly unchanged.

  I can add `LockTime` changes in the same commit or separate within this PR if you want. Just wanted to push something for review before I go to sleep.

ACKs for top commit:
  apoelstra:
    ACK 93dba898c2
  tcharding:
    ACK 93dba898c2

Tree-SHA512: 68b60b413b1a1a0fc3648970d37f43e8b1b79f197ded053d83cfc1cf4fab4bed77d77841c2ae4d066b6436ee7187723c5d8cf934193c04c03520e797b7f7e82d
2024-01-31 21:00:55 +00:00
Martin Habovstiak 93dba898c2 Improve lock time errors
The errors returned from various lock time functions had several issues.
Among the obvious - `Error` being returned from all operations even when
some of its variants were unreachable, there were subtle issues around
error messages:

* `ParseIntError` didn't contain information whether the parsed object
   is `Height` or `Time`.
* Logically overflow and out-of-bounds should be the same thing but
  produced different error messages.
* Mentioning integers is too technical for a user, talking about upper
  and lower bound is easier to understand.
* When minus sign is present `std` reports it as invalid digit which is
  less helpful than saying negative numbers are not allowed.

It is also possible that `ParseIntError` will need to be removed from
public API during crate smashing or stabilization, so avoiding it may be
better.

This commit significantly refactors the errors. It adds separate types
for parsing `Height` and `Time`. Notice that we don't compose them from
`ParseIntError` and `ConversionError` - that's not helpful because they
carry information that wouldn't be used when displaying which is
wasteful. Keeping errors small can be important.

It's also worth noting that exposing the inner representation could
cause confusion since the same thing: out of bounds can be represented
as an overflow or as a conversion error. So for now we conservatively
hide the details and even pretend there's no `source` in case of
overflow. This can be expanded in the future if needed.

The returned errors are now minimal. `LockTime` parsing errors are
currentlly unchanged.
2024-01-31 15:13:56 +01:00
Tobin C. Harding 0997382772
io: Enable alloc from std
It is less surprising if the "alloc" feature is enabled from the "std"
feature.

Enable "alloc" in "std" and simplify the feature gating.
2024-01-31 11:32:46 +11:00
Tobin C. Harding ba1166a63b
Make crate level attributes uniform
Make the trait level attributes uniform across all released crates in
the repo. Excludes things that are obviously not needed, eg, bench stuff
if there is not bench code.

- Remove `uninhabited_references` - this is allow by default now.
- Remove `unconditional_recursion` and mark the single false positive we
  have with an `allow`.

Note, this does not add `missing_docs` to the `io` crate. There is an
open PR at the moment to add that along with the required docs.
2024-01-31 11:32:46 +11:00
Andrew Poelstra 34c4039963
Merge rust-bitcoin/rust-bitcoin#2416: just: Reduce docs commands
bd4f14ee51 just: Reduce docs commands (Tobin C. Harding)

Pull request description:

  `cargo --doc` works from the workspace root, no need to run the docs builds individually.

  ## More context

  `cargo test` does not run docs tests if run from the workspace root as it does when run in a crate directory.

ACKs for top commit:
  sanket1729:
    utACK bd4f14ee51
  Kixunil:
    ACK bd4f14ee51

Tree-SHA512: f4003edcaf9bbc22cfcdcd142665fbb924b6a74af9145ee38d9f14275660e849d53b2f8d10ee45bf5b6c8e3b5123ead762da3fbc5f84714a55d2fe5273950270
2024-01-30 00:18:45 +00:00
Andrew Poelstra f0548c9318
Merge rust-bitcoin/rust-bitcoin#2414: Use nightly toolchain in pre-commit hook
13c8a709f1 Use nightly toolchain in pre-commit hook (Tobin C. Harding)

Pull request description:

  We use the nightly toolchain to run `clippy` now, update the git pre-commit hook to mirror this.

ACKs for top commit:
  apoelstra:
    ACK 13c8a709f1

Tree-SHA512: 46700641b81a1e5a2e39ff67ca0d31afaedfb58e008bf453c13f0312b2c6936ae38c58548934cae40abc9de0dc1ec4ce4bba4b8142b204d774612bd9721679c9
2024-01-29 22:29:38 +00:00
Tobin C. Harding bd4f14ee51
just: Reduce docs commands
`cargo --doc` works from the workspace root, no need to run the docs
builds individually.
2024-01-30 09:00:56 +11:00
Tobin C. Harding 13c8a709f1
Use nightly toolchain in pre-commit hook
We use the nightly toolchain to run `clippy` now, update the git
pre-commit hook to mirror this.
2024-01-30 07:19:12 +11:00
Andrew Poelstra 34d98356cd
Merge rust-bitcoin/rust-bitcoin#2410: Use `unsigned_abs` instead of manual code
dda83707a2 Use `unsigned_abs` instead of manual code (Martin Habovstiak)

Pull request description:

  The code originally used `if` and incorrectly casted the value into `usize` rather than `u64`. This change replaces the whole thing with `unsigned_abs`.

  Closes #1247

ACKs for top commit:
  apoelstra:
    ACK dda83707a2
  tcharding:
    ACK dda83707a2

Tree-SHA512: c57bf440705c69917206aab36bbbe5b048ed52d7a96ebd055416b8a249fc3f7ba32ebff3d2251b971e7ef999ff8169ac3db8e599ab38cf0776ecc030447a9a4a
2024-01-28 23:25:46 +00:00
Andrew Poelstra d883c3d5a2
Merge rust-bitcoin/rust-bitcoin#2408: Provide `Amount` & co in no-alloc
ac26171c32 Clean up `no_std` usage (Martin Habovstiak)
fce03cec85 Provide `Amount` & co in no-alloc (Martin Habovstiak)

Pull request description:

  Using the crate without allocation was previously disabled making the
  crate empty without the feature. This chage makes it more fine-grained:
  it only disables string and float conversions which use allocator. We
  could later provide float conversions by using a sufficiently-long
  `ArrayString`.

  Note that this is API-breaking because we disallow calling the methods of the sealed `SerdeAmount` trait. However I think it should've been obvious that the thing is internal and calling them is not a great idea. (BTW I only learned this trick recently).

  Closes #2389

ACKs for top commit:
  apoelstra:
    ACK ac26171c32 maaybe `private` should be renamed to `internal_api` or something
  tcharding:
    ACK ac26171c32

Tree-SHA512: 2ca2ff11c3c362f868c3993b5698ace32e6ce2cf2e8028bc43fe65797eb2239b4841c1c722a0184a7c8f4afea3b475b1a049dd77fa30358cb742d60463018e9f
2024-01-28 23:18:41 +00:00
Martin Habovstiak dda83707a2 Use `unsigned_abs` instead of manual code
The code originally used `if` and incorrectly casted the value into
`usize` rather than `u64`. This change replaces the whole thing with
`unsigned_abs`.

Closes #1247
2024-01-27 20:49:15 +01:00
Andrew Poelstra a38cdd520f
Merge rust-bitcoin/rust-bitcoin#2326: Improve the `justfile`
61f8bab65f just: Add quick and dirty CI command (Tobin C. Harding)
e185fe46df just: Lint with nightly toolchain (Tobin C. Harding)

Pull request description:

  Improve the `justfile` by doing:

  - Update linter toolchain
  - Add `just sane` to run a minimal set of checks/tests that can be used pre-push but is not as slow as using `DO_FEATURE_MATRIX=true contrib/test.sh`.

ACKs for top commit:
  apoelstra:
    ACK 61f8bab65f
  Kixunil:
    ACK 61f8bab65f

Tree-SHA512: 730874f0381db9ae30052ad6511805f76ae5c13c4c5cc5ad272430cf7e67cfbe7b288aa6dc47035ff5e8e42e03d3e4a3bf9d3e9a072c9aa922f9df62c43850b3
2024-01-27 16:49:01 +00:00
Martin Habovstiak ac26171c32 Clean up `no_std` usage
Previously the crate used negative reasoning to enable `std` which was
hard to understand, required the `prelude` module and wasn't really
needed because it's only needed when a crate wants to add `alloc`
feature-backwards compatibly and this crate always had the feature.

This cleans up usage to unconditionally use `#[no_std]` and then just
add `extern crate` on top as needed by activated features.
2024-01-27 13:25:40 +01:00
Martin Habovstiak fce03cec85 Provide `Amount` & co in no-alloc
Using the crate without allocation was previously disabled making the
crate empty without the feature. This chage makes it more fine-grained:
it only disables string and float conversions which use allocator. We
could later provide float conversions by using a sufficiently-long
`ArrayString`.
2024-01-27 12:46:55 +01:00
Tobin C. Harding 61f8bab65f
just: Add quick and dirty CI command
Add a command that attempts to cove a reasonable useful subset of our CI
checks in order to hasten development.
2024-01-27 14:10:58 +11:00
Andrew Poelstra e2b9555070
Merge rust-bitcoin/rust-bitcoin#2370: Improve units
7bf478373a Model `TooBig` and `Negative` as `OutOfRange` (Martin Habovstiak)
54cbbf804f Express `i64::MAX + 1` as `i64::MIN.unsigned_abs()` (Martin Habovstiak)
b562a18914 Move denomination error out of `ParseAmountError` (Martin Habovstiak)
5e6c65bc1a Clean up `unsigned_abs` (Martin Habovstiak)

Pull request description:

  Closes #2265
  Closes #2266

  Disclaimer: I did this in December and don't remember why I haven't pushed it. Maybe because it's somehow broken but I don't see how so please review a bit more carefully just in case.

ACKs for top commit:
  tcharding:
    ACK 7bf478373a
  apoelstra:
    ACK 7bf478373a

Tree-SHA512: 1f6e9adae9168bd045c9b09f06d9a69efd47ccc7709ac9ecaf48cb86e265b448b9b52a199ac5e6838d5029f5bc7514c5d7deb15a4d7c8a4606a353f390745570
2024-01-26 13:18:57 +00:00
Andrew Poelstra 2971740fd4
Merge rust-bitcoin/rust-bitcoin#2399: Use `Magic::BITCOIN` in unit tests
6ddb5cce37 Use Magic::BITCOIN in unit tests (Tobin C. Harding)

Pull request description:

  We are currently calling `From` to create the magic bytes, this is unnecessary since `Magic` provides consts.

  Refactor only, no logic changes.

ACKs for top commit:
  Kixunil:
    ACK 6ddb5cce37
  apoelstra:
    ACK 6ddb5cce37

Tree-SHA512: 20e2e017683f123309e3c0876bba42d86a9411bb225f07c486716184fc79837e04a832338ec8b18874ac76791260f6a4620b932ede92c8b222dac08d468cef8a
2024-01-25 15:38:22 +00:00
Andrew Poelstra 6bd8375959
Merge rust-bitcoin/rust-bitcoin#2402: Remove TODOs
5eb2de1660 Remove TODO about rand trait (Tobin C. Harding)
66cc007c2b p2p: Remove TODO comments (Tobin C. Harding)
0b5fb45ea0 consensus: Remove HEX_BUF_SIZE todo (Tobin C. Harding)
579668892a consensus: Remove TODO (Tobin C. Harding)
53beb9db30 Remove ancient todos in test code (Tobin C. Harding)
abe2241828 units: Remove "alloc" TODO (Tobin C. Harding)
5386ef0fd2 psbt: Delete TODO comments (Tobin C. Harding)
14c8a2232b examples: Remove TODO (Tobin C. Harding)

Pull request description:

  Done while working on #2368.  There are 5 left. Do we want to leave the MSRV ones in there?

  ```bash
  bitcoin/src/blockdata/weight.rs:66:                 // TODO replace with panic!() when MSRV = 1.57+
  bitcoin/src/consensus/serde.rs:101:    // TODO: statically prove impossible cases
  bitcoin/src/pow.rs:445:            // TODO: Use `carrying_mul` when stabilized: https://github.com/rust-lang/rust/issues/85532
  units/src/amount.rs:595:        // TODO replace whith unwrap() when available in const context.
  units/src/amount.rs:599:                // TODO replace with panic!() when MSRV = 1.57+
  ```

ACKs for top commit:
  Kixunil:
    ACK 5eb2de1660
  apoelstra:
    ACK 5eb2de1660

Tree-SHA512: 285b1711a6e6fba126e2c4159b25454c7f894122b76fde1d3d29e57b2ec0a6e90230e46ac79d70aa133da177c75d267fc5a13489b69881862649de771027ec8e
2024-01-25 15:06:28 +00:00
Andrew Poelstra 2de220ec6a
Merge rust-bitcoin/rust-bitcoin#2097: Add `Witness::p2tr_key_spend` function
6715e93e89 Add Witness::p2tr_key_spend function (Tobin C. Harding)

Pull request description:

  Add a function for creating the witness when doing a key path spend for a P2TR output.

  This mirrors what we did for P2WPKH when adding `Witness::p2wpkh`.

  Includes update to the taproot signing example to use the new constructor.

ACKs for top commit:
  Kixunil:
    ACK 6715e93e89
  apoelstra:
    ACK 6715e93e89

Tree-SHA512: aab51329e8fda471442bb9cebd6327636548dd157bb9842fe66993fcdd211bb04b2b829aa9d5962dd619f5c0b73d19644a44529c1a5958df1a6bc892147b44f5
2024-01-25 13:34:06 +00:00
Tobin C. Harding 5eb2de1660
Remove TODO about rand trait
This TODO applies to the whole codebase, remove it and add an issue.

  https://github.com/rust-bitcoin/rust-bitcoin/issues/2401
2024-01-25 17:10:41 +11:00
Tobin C. Harding 66cc007c2b
p2p: Remove TODO comments
Remove three TODOs and create an issue:

  https://github.com/rust-bitcoin/rust-bitcoin/issues/2400
2024-01-25 17:07:07 +11:00
Tobin C. Harding 0b5fb45ea0
consensus: Remove HEX_BUF_SIZE todo
Remove the todo, replace it with a comment stating that we guessed the
size and add an issue to measure and improve the value.

  https://github.com/rust-bitcoin/rust-bitcoin/issues/2391
2024-01-25 16:59:56 +11:00