Commit Graph

1485 Commits

Author SHA1 Message Date
Tobin C. Harding 3173ef9dbb Remove unnecessary explicit reference
Clippy emits various warnings of type:

  warning: this expression creates a reference which is immediately
  dereferenced by the compiler

As suggested, remove the unnecessary explicit reference.
2022-07-26 08:46:59 +10:00
Andrew Poelstra 9f0ff6f0a4
Merge rust-bitcoin/rust-bitcoin#1121: Use `u8::try_from`
517059e148 Use u8::try_from (Tobin C. Harding)

Pull request description:

  Currently we use a cast to get the `u8` depth, as suggested by the TODO in the code we can now use `TryFrom` since we bumped the MSRV.

  Use `u8::try_from.expect("")` since depth (node count) is guarded by `TAPROOT_CONTROL_MAX_NODE_COUNT`.

ACKs for top commit:
  Kixunil:
    ACK 517059e148
  apoelstra:
    ACK 517059e148

Tree-SHA512: 98e58617247a05025ec13ad3d00a464cb2351c98c6d871be43b252d3982e291b7187e25780e7fe367f5a3a64fa20f3b328876a8901af4da09e675f50727a26cf
2022-07-24 22:30:02 +00:00
Tobin C. Harding 517059e148 Use u8::try_from
Currently we use a cast to get the `u8` depth, as suggested by the TODO
in the code we can now use `TryFrom` since we bumped the MSRV.

Use `u8::try_from.expect("")` since, assuming the code comment is
correct, the depth is guaranteed to be less that 127.
2022-07-24 06:41:30 +10:00
Andrew Poelstra 0469838648
Merge rust-bitcoin/rust-bitcoin#1119: Use `listener.accept()`
b1faf63e82 Use listener.accept() (Tobin C. Harding)

Pull request description:

  During test network simulation we only accept a single connection, we can simplify the code by using `accept`.

  Done as a follow up to review suggestion:

  https://github.com/rust-bitcoin/rust-bitcoin/pull/1042#discussion_r898013799

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

Tree-SHA512: b2ead15d3108db3e01d9faab5e3521403dad6a0f4c3cf505f88fefd020110c520a89b9406484c10b04c9a34073c8abc465941577b17b5a193b54502c23b14c61
2022-07-22 20:35:41 +00:00
Tobin C. Harding b1faf63e82 Use listener.accept()
During test network simulation we only accept a single connection, we
can simplify the code by using `accept`.

Done as a follow up to review suggestion:

https://github.com/rust-bitcoin/rust-bitcoin/pull/1042#discussion_r898013799
2022-07-22 13:29:05 +10:00
Arturo Marquez aeede12604
Infallible conversions: `Hash` -> `Message`
Replace all instances of
`secp256k1::Message::from_slice(_).expect(_)` with
`secp256k1::Message::from(_)`.

Also adds an implementation of ThirtyTwoByteHash for
TapSighashHash.

Solves https://github.com/rust-bitcoin/rust-bitcoin/issues/824
2022-07-21 11:26:53 -05:00
Tobin C. Harding 21a1cc791c Use pub(crate) for macros instead of macro_use
For internal macros used only in this crate we do not need to use
`macro_use` and pollute the top level namespace now that we have edition
2018. We can add a `pub(crate) use` statement to each and then path
imports work for the macros like normal types.
2022-07-20 11:25:54 +10:00
Tobin C. Harding 23ee0930c7 Remove extern crate
Now we have edition 2018 we do not need to use `macro_use` or `extern
crate`; `pub use` works with macros. Notable exceptions are `alloc` and
`test`. Also leave the serde rename because touching it opens a can of
worms.
2022-07-20 11:25:54 +10:00
Tobin C. Harding da8b1b5439 Remove unused extern crate test
Recently we removed the "unstable" feature, I missed the duplicate
`extern crate test` when doing so :(

Since we no longer have the "unstable" feature this line of code is
never compiled in.

Remove the unused ``extern crate test`, we have the correct line further
up the file `#[cfg(bench)] extern crate test;`.
2022-07-20 11:24:33 +10:00
Tobin C. Harding 01a8cc6848 Remove extern crate bitcoin_hashes
Now we have edition 2018 we do not need to use `macro_use` or `extern
crate`; `pub use` works with macros.

Remove the extern crate statement and replace it with a pub use
statement. Requires fixing up various imports statements and also
requires importing `sha256t_hash_newtype` macro directly instead of
using a qualified path to it.
2022-07-20 11:23:59 +10:00
Tobin C. Harding ee9a3ec6a1 Enable formatter for "src"
Remove the ignore for the "src" directory, this enables the formatter
for all source files in the `src/` directory.
2022-07-19 13:43:12 +10:00
Tobin C. Harding 743b197124 Add use for Unexpected
In preparation for running the formatter on `src/` and a function local
use statement for `$crate::serde:🇩🇪:Unexpected`, this shortens the
line of code that uses this type preventing the formatter for later
munging that line.
2022-07-19 13:43:12 +10:00
Tobin C. Harding fd217e72c3 Use f instead of formatter
The local variable `formatter` can be shortened to `f` with no loss of
clarity since it is so common.

Done in preparation for running `rustfmt` on `src`.
2022-07-19 13:43:12 +10:00
Tobin C. Harding 7b50a96ade Do not format prelude module
In preparation for running the formatter on all source files at the root
of the crate; skip formatting `prelude` module because we use
unconventional import statements so they to save writing a million
compiler attributes.
2022-07-19 13:43:12 +10:00
Tobin C. Harding 01471f7e65 Shield hash_newtypes from rustfmt
In preparation for running the formatter on root level modules and a
submodule that holds all the macro calls in `hash_types` so we can
configure rustfmt to skip formatting them.
2022-07-19 13:43:12 +10:00
Tobin C. Harding 65d19d9044 Refactor compile_error message
In preparation for enabling rustfmt on `lib.rs` refactor the
`compile_error` call so that the formatter does not touch it.
2022-07-19 13:43:12 +10:00
Andrew Poelstra 0c22359618
Merge rust-bitcoin/rust-bitcoin#1001: Remove leading colons
73bc2bb058 Remove leading colons from ::core::cmp::Ordering (Tobin C. Harding)
bffe0e840d Remove _most_ leading double colons (Tobin C. Harding)

Pull request description:

  Leading double colons are a relic of edition 2015. Attempt to remove _all_ leading double colons (assuming I didn't miss any).

  - Patch 1 is done mechanically so it can be repeated by reviewers, just search-and-replace ' ::' with '::' (note the leading space).
  - Patch 2 does a single other instance of leading `::`

ACKs for top commit:
  apoelstra:
    ACK 73bc2bb058
  sanket1729:
    utACK 73bc2bb058.

Tree-SHA512: 8f7aafdda1aed5b69dcc83f544e65085dfec6590765839f0a6f259b99872805d1f00602fd9deac05c80a5cac3bc222d454dde0117dff4484e5cd34ea930fdfa1
2022-07-19 01:39:04 +00:00
Andrew Poelstra cd790dc7e9
Merge rust-bitcoin/rust-bitcoin#1068: Implement human-readable serde for `Witness`
a1df62a3d9 Witness human-readable serde test (Dr Maxim Orlovsky)
68577dfb50 Witness human-readable serde (Dr Maxim Orlovsky)
93b66c55b3 Witness serde: test binary encoding to be backward-compatible (Dr Maxim Orlovsky)
b409ae78a4 witness: Refactor import statements (Tobin C. Harding)
e23d3a815c Remove unnecessary whitespace (Tobin C. Harding)
ac55b1017e Add whitespace between functions (Tobin C. Harding)

Pull request description:

  This is dr-orlovsky's [PR](https://github.com/rust-bitcoin/rust-bitcoin/pull/899) picked up at his permission in the discussion thread.

  I went through the review comments and implemented everything except the perf optimisations. Also includes a patch at the front of the PR that adds a unit test that can be run to see the "before and after", not sure if we want it in, perhaps it should be removed before merge.

  This PR implicitly fixes 942.

  To test this PR works as advertised run `cargo test display_transaction --features=serde -- --nocapture` after creating a unit test as follows:
  ```rust

      // Used to verify that parts of a transaction pretty print.
      // `cargo test display_transaction --features=serde -- --nocapture`
      #[cfg(feature = "serde")]
      #[test]
      fn serde_display_transaction() {
          let tx_bytes = Vec::from_hex(
              "02000000000101595895ea20179de87052b4046dfe6fd515860505d6511a9004cf12a1f93cac7c01000000\
              00ffffffff01deb807000000000017a9140f3444e271620c736808aa7b33e370bd87cb5a078702483045022\
              100fb60dad8df4af2841adc0346638c16d0b8035f5e3f3753b88db122e70c79f9370220756e6633b17fd271\
              0e626347d28d60b0a2d6cbb41de51740644b9fb3ba7751040121028fa937ca8cba2197a37c007176ed89410\
              55d3bcb8627d085e94553e62f057dcc00000000"
          ).unwrap();
          let tx: Transaction = deserialize(&tx_bytes).unwrap();
          let ser = serde_json::to_string_pretty(&tx).unwrap();
          println!("{}", ser);
      }
  ```

  Fixes: #942

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

Tree-SHA512: d0ef5b8cbf1cf8456eaaea490a793f1ac7dfb18067c4019a2c3a1bdd9627a231a4dd0a0151a4df9af2b32b909d4b384a5bec1dd3e38d44dc6a23f9c40aa4f1f9
2022-07-18 19:06:39 +00:00
Andrew Poelstra 5d9f564510
Merge rust-bitcoin/rust-bitcoin#1093: Add new type for sequence
e34bc538c3 Add new type for sequence (Noah Lanson)

Pull request description:

  #1082

  Created a new type for txin sequence field with methods to create sequences with relative time locks from block height or time units.

ACKs for top commit:
  Kixunil:
    ACK e34bc538c3
  tcharding:
    ACK e34bc538c3
  apoelstra:
    ACK e34bc538c3

Tree-SHA512: 6605349d0312cc36ef9a4632f954e59265b3ba5cfd437aa88a37672fe479688aa4a3eff474902f8cc55848efe55caf3f09f321b3a62417842bfc3ec365c40688
2022-07-17 23:04:16 +00:00
Andrew Poelstra bd8d9af18a
Merge rust-bitcoin/rust-bitcoin#1092: Create configuration conditional "bench"
f3b2120ec9 Create configuration conditional bench (Tobin C. Harding)
f60c92ca58 Add informative error message to DO_BENCH (Tobin C. Harding)
c6d5a12b60 Add cargo/rustc sanity calls (Tobin C. Harding)
34d5a3141d Put triple ticks on their own line (Tobin C. Harding)

Pull request description:

  Currently we are unable to build with all features enabled with a non-nightly toolchain, this is because of the use of

      `#![cfg_attr(all(test, feature = "unstable"), feature(test))]`

  which causes the following error when building:

   error[E0554]: `#![feature]` may not be used on the stable release channel

  The "unstable" feature is used to guard bench mark modules, this is widely suggested online but there is a better way.

  When running the bench marks use the following incantation:

      `RUSTFLAGS='--cfg=bench' cargo bench`

  This creates a configuration conditional "bench" that can be used to guard the bench mark modules.

  ```
  #[cfg(bench)]
  mod benches {
      ...
  }
  ```

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

Tree-SHA512: 7ec2a501a30bfe2ce72601077cd675cf5e5ac2f0f93f97fc7e83cb7401606b69ae909b35bfc0ace8bd1ea771ca4fba70e2ad9ac9ba26f2b6e371494cf694c0a8
2022-07-17 23:03:37 +00:00
Noah Lanson e34bc538c3 Add new type for sequence 2022-07-16 10:49:03 +10:00
Tobin C. Harding ef7fef001c Derive Hash on a bunch of types
In preparation for being able to derive `Hash` on all types in
`miniscript`, derive `Hash` on all of the required types.
2022-07-15 10:00:32 +10:00
Andrew Poelstra 9cfa9bd9df
Merge rust-bitcoin/rust-bitcoin#1049: Implement std::error::Error for ParseAmount
5ce34011f2 Implement std::error::Error for ParseAmount (Tobin C. Harding)

Pull request description:

  The `ParseAmountError` does not implement `std::error::Error`, must have been missed when we did the rest.

  Implement `std::error::Error` for `ParseAmount`.

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

Tree-SHA512: 8dafc472b7c23b54d856344e786e0f22e8e179f30f6c1011fbf5f8f0c6b1b5d74ed8e4f2638e5f8246f04dbb429e60027db6fe584d51a78957a6e904feb9e8a3
2022-07-14 13:24:35 +00:00
Tobin C. Harding f3b2120ec9 Create configuration conditional bench
Currently we are unable to build with all features enabled with a
non-nightly toolchain, this is because of the use of

    `#![cfg_attr(all(test, feature = "unstable"), feature(test))]`

which causes the following error when building:

 error[E0554]: `#![feature]` may not be used on the stable release
 channel

The "unstable" feature is used to guard bench mark modules, this is
widely suggested online but there is a better way.

When running the bench marks use the following incantation:

    `RUSTFLAGS='--cfg=bench' cargo bench`

This creates a configuration conditional "bench" that can be used to
guard the bench mark modules.

    #[cfg(bench)]
    mod benches {
        ...
    }
2022-07-14 10:21:01 +10:00
Andrew Poelstra ed00c2aab9
Merge rust-bitcoin/rust-bitcoin#1065: Upgrade `bitcoin_hashes` dependency
1e46eeaa88 Upgrade to bitcoin_hashes v0.11.0 (Tobin C. Harding)

Pull request description:

  We just released a new version of `bitcoin_hashes`, upgrade the dependency to v0.11.0

ACKs for top commit:
  apoelstra:
    ACK 1e46eeaa88
  Kixunil:
    ACK 1e46eeaa88

Tree-SHA512: 32173349c280c255681ebf15a1aa98a28b7016bb813ca907ac55a9797d9d17e1da344e2d8e74c02c2c80d2e6873a03f522c2d55b289b65d7ac55f402b19d689b
2022-07-13 15:46:22 +00:00
Andrew Poelstra 758dbfa1da
Merge rust-bitcoin/rust-bitcoin#1084: Add PublicKey::to_sort_key method for use with sorting by key
24f0441d54 Add PublicKey::to_sort_key method for use with sorting by key (junderw)

Pull request description:

  Replaces #524

  See previous PR for reasoning.

  This solution is a little more straightforward. The name and documentation should be enough to prevent misuse.

  We can also impl a to_sort_key for any CompressedKey added later. (or just impl Ord in a BIP67 compliant way)

  TODO:

  - [x] Add more sorting test vectors. Ideas of edge cases to test are welcome.

ACKs for top commit:
  apoelstra:
    ACK 24f0441d54
  tcharding:
    ACK 24f0441d54
  Kixunil:
    ACK 24f0441d54

Tree-SHA512: 92d68cccaf32e224dd7328edeb3481dd7dcefb2f9090b7381e135e897c21f79ade922815cc766c5adb7ba751b71b51a773d103af6ba13fc081e1f5bfb846b201
2022-07-13 13:02:00 +00:00
Tobin C. Harding 1e46eeaa88 Upgrade to bitcoin_hashes v0.11.0 2022-07-13 09:38:05 +10:00
Dr Maxim Orlovsky a1df62a3d9 Witness human-readable serde test 2022-07-13 09:28:14 +10:00
Dr Maxim Orlovsky 68577dfb50 Witness human-readable serde
Previous implementations of Witness (and Vec<Vec<u8>>) serde serialization
didn't support human-readable representations. This resulted in long unreadable
JSON/YAML byte arrays, which were especially ugly when pretty-printed (a line
per each byte).

Co-authored-by: Tobin C. Harding <me@tobin.cc>
2022-07-13 09:28:14 +10:00
Dr Maxim Orlovsky 93b66c55b3 Witness serde: test binary encoding to be backward-compatible
This also removes tests for JSON backward-compatible encoding. Human-readable 
encoding will be changed in the next commit and this will break backward 
compatibility, thus that part of the test is removed.
2022-07-13 09:23:50 +10:00
Andrew Poelstra a24b223ae4
Merge rust-bitcoin/rust-bitcoin#1094: Remove extern crate core statement
35edcaa4ca Remove extern crate core statement (Tobin C. Harding)

Pull request description:

  Now that we have an MSRV of 1.41.1 we no longer need `extern crate core`, remove it.

ACKs for top commit:
  apoelstra:
    ACK 35edcaa4ca
  Kixunil:
    ACK 35edcaa4ca

Tree-SHA512: 0efa0f05d3e9f797c493757fce6ca7703dd8439dbce4e9ff8113494fc71691ab4171c6f0fb5239b57ff5f0e223d48b057265a3df79898a399ca455040580aab2
2022-07-12 23:00:12 +00:00
Andrew Poelstra 4965495354
Merge rust-bitcoin/rust-bitcoin#1066: Upgrade to secp256k1 v0.23.0
36f29d4357 Upgrade to secp256k1 v0.23.0 (Tobin C. Harding)

Pull request description:

  We recently released a new version of `rust-secp256k1`, upgrade to use it.

ACKs for top commit:
  apoelstra:
    ACK 36f29d4357
  Kixunil:
    ACK 36f29d4357

Tree-SHA512: 46a909dec8bc59daa78acdb76824d93f4f1da0e9736cf6ca443d3bbadfa43867e720293bb7c4919cb0658e75ec59daeffea080611f0e7eed4df439ddac0305de
2022-07-12 14:03:49 +00:00
Andrew Poelstra 3f27131823
Merge rust-bitcoin/rust-bitcoin#1091: Add custom error for invalid parsing of address types
19ba7ecc03 Add custom error for unknown address type parsing (Arturo Marquez)

Pull request description:

  Adds a custom error `UnknownAddressType(_)` which is returned in cases where an unknown address type tries to be parsed via
  `FromStr`. This provides more context for the error, since it contains the `String` that tried to be parsed.

  Closes https://github.com/rust-bitcoin/rust-bitcoin/issues/1064

ACKs for top commit:
  Kixunil:
    ACK 19ba7ecc03
  dunxen:
    ACK 19ba7ec
  tcharding:
    ACK 19ba7ecc03
  apoelstra:
    ACK 19ba7ecc03

Tree-SHA512: 2f94eb2e122c1acafcb8c852f7bfe22cb3725806541ae40f82d3a882011fb911ce8fc430153ebea4066f43c5a51813359a4c9b95d2a9077ce8f6dcaa58eee6fd
2022-07-12 01:17:41 +00:00
Tobin C. Harding 36f29d4357 Upgrade to secp256k1 v0.23.0
We recently released a new version of `rust-secp256k1`, upgrade to use
it.
2022-07-12 09:22:55 +10:00
Tobin C. Harding 35edcaa4ca Remove extern crate core statement
Now that we have an MSRV of 1.41.1 we no longer need `extern crate
core`, remove it.
2022-07-12 09:05:14 +10:00
Andrew Poelstra 5d06177644
Merge rust-bitcoin/rust-bitcoin#1076: Introduce SPDX license identifiers
91ff2f628c Introduce SPDX license identifiers (Tobin C. Harding)

Pull request description:

  When `rust-bitcoin` was started in 2014 the SPDX license list and short identifiers where not a thing. Now that we have short identifiers and they are gaining popularity in other projects we can consider using them.

  - Add links to the SPDX website in the readme
  - Shorten the author section to a single line
  - Remove all the licence information in each file and replace it with an
  SPDX ID (see https://spdx.dev/ids/#how)

  Of note:

  - If the author of a file is explicitly listed, maintain this information
  - If the 'author' is listed as the generic 'Rust Bitcoin developers' just remove the attribution, this is implicit. This does loose the date info but that can be seen at any time from the git index using

    `git log --follow --format=%ad --date default <FILE> | tail -1`

  apoelstra, please confirm that I'm not treading on your toes here, especially, are you ok with the new 'written by' string format?

  ### Ref
  - https://spdx.dev/ids/#how
  - https://spdx.org/licenses/CC0-1.0.html
  - https://spdx.dev/ids/

ACKs for top commit:
  apoelstra:
    ACK 91ff2f628c
  sanket1729:
    ACK 91ff2f628c. I am also in IDGAF camp, but I like more red lines in diff.
  Kixunil:
    ACK 91ff2f628c

Tree-SHA512: ca8aac00f015c18ec18de83dfeb50dd6f4f840653c7def85daa2436a339021ada5f3c34ad0cdf6b18e3e39c45a6d58a8313742e4001d467785b10eee7fdbc938
2022-07-11 15:11:03 +00:00
Arturo Marquez 19ba7ecc03
Add custom error for unknown address type parsing
Adds a custom error `UnknownAddressType(_)` which is returned in
cases where an unknown address type tries to be parsed via
`FromStr`. This provides more context for the error.

For more info see [1].

[1] - `https://github.com/rust-bitcoin/rust-bitcoin/issues/1064`
2022-07-11 08:56:56 -05:00
Tobin C. Harding 73bc2bb058 Remove leading colons from ::core::cmp::Ordering
Leading double colons are a relic of edition 2015. Remove the leading
double colon from `Option<::core::cmp::Ordering>`.
2022-07-11 15:20:05 +10:00
Tobin C. Harding bffe0e840d Remove _most_ leading double colons
Leading double colons are a relic of edition 2015. Remove all leading
double colons that follow a space, done like this so that reviewers can
do the same and verify the diff. Done with

search-and-replace ' ::' '::'

And, for the record:

```bash
function search-and-replace() {
    if (($# != 2))
    then
        echo "Usage: $0 <this> <that>"
        return
    fi

    local this="$1"
    local that="$2"

    for file in $(git grep -l "$this")
    do
        perl -pi -e "s/$this/$that/g" "$file"
    done
}
```
2022-07-11 15:20:05 +10:00
Tobin C. Harding b409ae78a4 witness: Refactor import statements
Re-order the import statements in `witness` module to separate `crate`
imports from dependency imports.
2022-07-11 11:51:50 +10:00
Tobin C. Harding e23d3a815c Remove unnecessary whitespace
No need for a line of whitespace immediately starting an impl block.
2022-07-11 11:51:50 +10:00
Tobin C. Harding ac55b1017e Add whitespace between functions
As is customary leave a line of white space between functions.
2022-07-11 11:51:50 +10:00
Andrew Poelstra 97c680db8c
Merge rust-bitcoin/rust-bitcoin#1081: Use `to_hex` when available
32cfd93933 Use to_hex when available (Tobin C. Harding)

Pull request description:

  We have a bunch of calls to `format!("{:x}", foo)` for types that implement `ToHex`. The code is terser with no loss of clarity if we use the trait method and call `to_hex()`.

ACKs for top commit:
  apoelstra:
    ACK 32cfd93933
  Kixunil:
    ACK 32cfd93933

Tree-SHA512: 87cb6660708c11dfafb56bd6e2ea2634043b2226d51903a20806c1ba51c6e7c4f0e4cc25e49f820b5b1236600af7da2a20893c49a5b8845d7652b143fd0ec388
2022-07-08 16:59:19 +00:00
junderw 24f0441d54
Add PublicKey::to_sort_key method for use with sorting by key 2022-07-07 18:05:53 +09:00
junderw 6adb2c64d9
Remove redundant compile_error 2022-07-04 22:34:40 +09:00
Tobin C. Harding 64152ff6fc Remove unused lifetimes
We somehow have two lifetimes that are unused and causing clippy
warnings, remove them.
2022-07-01 11:56:50 +10:00
Andrew Poelstra 30baeea738
Merge rust-bitcoin/rust-bitcoin#1014: Use fragment-specifier literal
4d2291930b Use fragment-specifier literal (Tobin C. Harding)

Pull request description:

  Currently we are using the fragment-specifier `expr` in a bunch of
  macros for captures that are only used for literals. If we use `literal`
  instead it allows the compiler to give slightly more specific error
  messages.

  The benefits of this change are minor. Of note, this patch found one
  unusual macro call site (removed unnecessary `&`).

  The macros changed are all internal macros, this is not a breaking change.

ACKs for top commit:
  Kixunil:
    ACK 4d2291930b
  apoelstra:
    ACK 4d2291930b

Tree-SHA512: 51c109fe3a884191bf623508555c1d5ad337a3f3b48538d18aec13e581f2c5fbbd055be49600ced19f38541412c34090bd8bac61fd05d5aa9702c96ff521364f
2022-06-30 15:01:50 +00:00
Tobin C. Harding 32cfd93933 Use to_hex when available
We have a bunch of calls to `format!("{:x}", foo)` for types that
implement `ToHex`. The code is terser with no loss of clarity if we use
the trait method and call `to_hex()`.
2022-06-30 16:59:18 +10:00
Andrew Poelstra 05f7545aeb
Merge rust-bitcoin/rust-bitcoin#1075: Remove Uninhabited
a8e62f249b Remove Uninhabited (Tobin C. Harding)

Pull request description:

  Last release, before we had access to `non_exhaustive` we added some fancy types to enable conditionally having a `bitcoinconsensus::Error`.

  Now that we have bumped the MSRV and have already added `non_exhaustive` to the `Error` type in question, we can use a compiler attribute to conditionally include the `bitcoinconsensus` error.

  Remove `Uninhabited` and its usage.

  For more context see the [original attempt ](https://github.com/rust-bitcoin/rust-bitcoin/pull/1025)at using `Infallible` (last comment in discussion thread).

ACKs for top commit:
  Kixunil:
    ACK a8e62f249b
  dunxen:
    ACK a8e62f2
  apoelstra:
    ACK a8e62f249b

Tree-SHA512: 8c03c44d7533af1a9a1185b7f9e0fa2c52369eaac8a45f0e2199e7e1bbd08ba2bfa23d829d2c2abf7f45fe8cc26ccad02f2e1a6d408d2c0fbca23140cafe3801
2022-06-29 19:37:07 +00:00
Andrew Poelstra f401cdc99e
Merge rust-bitcoin/rust-bitcoin#1035: Take Writer/Reader by `&mut` in consensus en/decoding
1fea098dfb Support unsized `R` and `W` in consensus encode/decode (Dawid Ciężarkiewicz)
a24a3b0194 Forward `consensus_decode` to `consensus_decode_from_finite_reader` (Dawid Ciężarkiewicz)
9c754ca4de Take Writer/Reader by `&mut` in consensus en/decoding (Dawid Ciężarkiewicz)

Pull request description:

  Fix #1020 (see more relevant discussion there)

  This definitely makes the amount of generics compiler
  has to generate by avoding generating the same functions
  for `R`, `&mut R`, `&mut &mut R` and so on.

  old:

  ```
  > ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
  -rwxrwxr-x 1 dpc dpc 9947832 Jun  2 22:42 target/release/deps/bitcoin-07a9dabf1f3e0266
  > strip target/release/deps/bitcoin-07a9dabf1f3e0266
  > ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
  -rwxrwxr-x 1 dpc dpc 4463024 Jun  2 22:46 target/release/deps/bitcoin-07a9dabf1f3e0266
  ```

  new:

  ```

  > ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
  -rwxrwxr-x 1 dpc dpc 9866800 Jun  2 22:44 target/release/deps/bitcoin-07a9dabf1f3e0266
  > strip target/release/deps/bitcoin-07a9dabf1f3e0266
  > ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
  -rwxrwxr-x 1 dpc dpc 4393392 Jun  2 22:45 target/release/deps/bitcoin-07a9dabf1f3e0266
  ```

  In the unit-test binary itself, it saves ~100KB of data.

  I did not expect much performance gains, but turn out I was wrong(*):

  old:

  ```
  test blockdata::block::benches::bench_block_deserialize                 ... bench:   1,072,710 ns/iter (+/- 21,871)
  test blockdata::block::benches::bench_block_serialize                   ... bench:     191,223 ns/iter (+/- 5,833)
  test blockdata::block::benches::bench_block_serialize_logic             ... bench:      37,543 ns/iter (+/- 732)
  test blockdata::block::benches::bench_stream_reader                     ... bench:   1,872,455 ns/iter (+/- 149,519)
  test blockdata::transaction::benches::bench_transaction_deserialize     ... bench:         136 ns/iter (+/- 3)
  test blockdata::transaction::benches::bench_transaction_serialize       ... bench:          51 ns/iter (+/- 8)
  test blockdata::transaction::benches::bench_transaction_serialize_logic ... bench:           5 ns/iter (+/- 0)
  test blockdata::transaction::benches::bench_transaction_size            ... bench:           3 ns/iter (+/- 0)
  ```

  new:

  ```
  test blockdata::block::benches::bench_block_deserialize                 ... bench:   1,028,574 ns/iter (+/- 10,910)
  test blockdata::block::benches::bench_block_serialize                   ... bench:     162,143 ns/iter (+/- 3,363)
  test blockdata::block::benches::bench_block_serialize_logic             ... bench:      30,725 ns/iter (+/- 695)
  test blockdata::block::benches::bench_stream_reader                     ... bench:   1,437,071 ns/iter (+/- 53,694)
  test blockdata::transaction::benches::bench_transaction_deserialize     ... bench:          92 ns/iter (+/- 2)
  test blockdata::transaction::benches::bench_transaction_serialize       ... bench:          17 ns/iter (+/- 0)
  test blockdata::transaction::benches::bench_transaction_serialize_logic ... bench:           5 ns/iter (+/- 0)
  test blockdata::transaction::benches::bench_transaction_size            ... bench:           4 ns/iter (+/- 0)
  ```

  (*) - I'm benchmarking on a noisy laptop. Take this with a grain of salt. But I think
  at least it doesn't make anything slower.

  While doing all this manual labor that will probably generate conflicts,
  I took a liberty of changing generic type names and variable names to
  `r` and `R` (reader) and `w` and `W` for writer.

ACKs for top commit:
  RCasatta:
    ACK 1fea098dfb tested in downstream lib, space saving in compiled code confirmed
  apoelstra:
    ACK 1fea098dfb

Tree-SHA512: bc11994791dc97cc468dc9d411b9abf52ad475f23adf5c43d563f323bae0da180c8f57f2f17c1bb7b9bdcf523584b0943763742b81362880206779872ad7489f
2022-06-29 19:29:42 +00:00