Commit Graph

1952 Commits

Author SHA1 Message Date
merge-script 05c28cf31d
Merge rust-bitcoin/rust-bitcoin#3915: Add FIFTY_BTC const to the amount types
e0028239cf api: Run just check-api (Tobin C. Harding)
5eb5941215 Add FIFTY_BTC const to the amount types (Tobin C. Harding)

Pull request description:

  The mining reward for the first epoc is 50 bitcoin. For mainnet this is old news but for regtest it is still relevant.

  Add and use a new const `FIFTY_BTC` to the `Amount` type. To keep the amount types uniform also add it to the `SignedAmount`.

ACKs for top commit:
  storopoli:
    ACK e0028239cf
  jamillambert:
    ACK e0028239cf
  apoelstra:
    ACK e0028239cf207660deb2873a92bacfa1315af634; successfully ran local tests

Tree-SHA512: 623ed8b1f5fe8dd95309179308fea83d68be4349becf6305769b0378cc9032961df2c062dc2bf702fec5e2394e8abb7360d2be6f19b6cf505db8769a5ae39e16
2025-01-20 02:42:45 +00:00
Fmt Bot fec6a7669e 2025-01-19 automated rustfmt nightly 2025-01-19 01:19:33 +00:00
Tobin C. Harding 5eb5941215
Add FIFTY_BTC const to the amount types
The mining reward for the first epoc is 50 bitcoin. For mainnet this is
old news but for regtest it is still relevant.

Add and use a new const `FIFTY_BTC` to the `Amount` type. To keep the
amount types uniform also add it to the `SignedAmount`.
2025-01-17 10:08:09 +11:00
merge-script 6bc12e9363
Merge rust-bitcoin/rust-bitcoin#3864: Update for ParsePublicKeyError Display and Error impl
b11ace359a Fix up ParsePublickeyError (Innocent Onyemaenu)

Pull request description:

  Resolves #3835

  In #945fcd09 we forgot to Update impl for ParsePublicKeyError Display and Error traits

ACKs for top commit:
  tcharding:
    ACK b11ace359a
  apoelstra:
    ACK b11ace359a52d9137b8fe5919d9825d61e3e9fad; successfully ran local tests; thanks!!

Tree-SHA512: 5c4e5e113605bc5b9c3c0d2ca65a0fdae80726a0f2f791255cc1d6567812a9132ff4f5bd8f30276fef916469d5fd29f6d72ddf4adb6340e52f4e0198ac4fb371
2025-01-16 01:37:12 +00:00
Innocent Onyemaenu b11ace359a Fix up ParsePublickeyError
In #3847 we added an `InvalidCharError` into one of the variants of
`ParsePublicKeyError` but we forgot to update the trait
implementations.

Fix the `error::Error` and `Display` implementations for
`ParsePublicKeyError`. While we are at it match on `*self` as is
typical in this codebase.

 With this applied #3835 is fully resolved.

 Close: #3835
2025-01-15 21:00:55 +01:00
Tobin C. Harding 39523ea1f5
units: Remove InputString from the public API
Currently `InputString` is in the public API of `units` because of the
trait bound on `parse::int()`. We can just do the monomorphisisation
manually to remove it.

This patch renames `int` to have three different names, one for `&str`
one for `String`, and one for `Box<str>`.
2025-01-15 08:09:38 +11:00
Tobin C. Harding 668056fb36
Use Amount in examples
Use the `Amount` type as parameter in examples code instead of a `u64`.

Done as part of preparation for enforcing MAX_MONEY.
2025-01-14 09:48:48 +11:00
Fmt Bot 8bdd67a368 2025-01-12 automated rustfmt nightly 2025-01-12 01:23:13 +00:00
merge-script 93cd9a4f74
Merge rust-bitcoin/rust-bitcoin#3891: typo: `Address::is_valid_for_network`
1e0c065740 typo: Address::is_valid_for_network (Jose Storopoli)

Pull request description:

  I believe this is a typo.

ACKs for top commit:
  apoelstra:
    ACK 1e0c065740266a8ad207a95f4d964394ba3f07d7; successfully ran local tests
  tcharding:
    ACK 1e0c065740

Tree-SHA512: aff71b91dc707c0c6c723e35510d284fd9a60895b7f12828819eb0d4520216491a2cf054b59872ac4be175d566674a32bde8c170f43beb6fc15dd19e6be12e45
2025-01-11 16:01:15 +00:00
merge-script 6a4ca4e61a
Merge rust-bitcoin/rust-bitcoin#3878: bitcoin: Add an example of doing I/O to encode/decode
706a135de6 bitcoin: Add an example of doing I/O to encode/decode (Tobin C. Harding)

Pull request description:

  In an effort to improve the documentation on `bitcoin_io` add an example in `bitcoin` crate that demonstrates a few things:

  - Encode/Decode a `rust-bitcoin` type to/from a stdlib type.
  - Encode to a custom type by implementing `bitcoin_io` traits.
  - Encode to a foreign custom type by using the `bitcoin_io::bridge::FromStd` wrapper.

  Later we can link to this example online in the `bitcoin_io` docs.

ACKs for top commit:
  apoelstra:
    ACK 706a135de6ca2be0231c2f62f4f2b156e08c9a49; successfully ran local tests

Tree-SHA512: cd3ff4067d5b86031255cb31fe17dea3fd22479699d32efad93c359de465ef6250f29aa4c43ce4218ae623fa6c355661960c11908a729a895655319141b82852
2025-01-11 14:46:13 +00:00
Jose Storopoli 1e0c065740
typo: Address::is_valid_for_network
I believe this is a typo.
2025-01-10 11:11:43 -03:00
merge-script 653ea702d6
Merge rust-bitcoin/rust-bitcoin#3792: Add BIP324 V2 p2p network message support
e09bdb5f98 Add BIP324 V2 p2p network message support (Nick Johnson)

Pull request description:

  Migrating over the BIP324's library's V2 network message encoding and decoding. As discussed over in https://github.com/rust-bitcoin/rust-bitcoin/discussions/2959, this is probably the natural home for it and also cleans up some gross copy/pasta of some of the encoding/decoding chain logic.

  This patch adds `V2NetworkMessage` which wraps a `NetworkMessage`, but handles the V2 encoding and decoding. It is a parallel of the existing `RawNetworkMessage` (which mentioned before, may be better described as `V1NetworkMessage` https://github.com/rust-bitcoin/rust-bitcoin/issues/3157). A priority of this patch was to not re-invent any wheels and try to use the existing patterns as much as possible.

ACKs for top commit:
  tcharding:
    ACK e09bdb5f98
  apoelstra:
    ACK e09bdb5f98ea516382a04283373ad97a41d57c2b; successfully ran local tests; nice!

Tree-SHA512: a5078d4d3deb04c2e06ea513bbc8c97d0e6d5da5b029847a97b3f90bf55a263858dd16d88299f853aa3c468f7b9bceb3973c5652a49d3e96df3e91181b455f29
2025-01-09 18:46:39 +00:00
merge-script 9a8e61393c
Merge rust-bitcoin/rust-bitcoin#3858: Bound `Address` parsing on `NetworkValidationUnchecked`
29a71de928 Bound Address parsing on NetworkValidationUnchecked (Tobin C. Harding)
cf455d3a06 Fix typo in prifixes (Tobin C. Harding)

Pull request description:

  Currently it is not possible for downstream to use a generic on the `Address` type in structs in conjuncture with
  derives (`serde::Deserialize` and `Display`) because our impls are only done for `NetworkUnchecked` (as they should be).

  However, as observed by dpc, if we add a secondary marker trait and use it to bound the impls, implementing the new marker for `NetworkUnchecked` then downstream can use derives by way of

  ```
      #[derive(Serialize, Deserialize)]
      struct Foo<V>
          where V: NetworkValidation,
      {
          #[serde(bound(deserialize = "V: NetworkValidationUnchecked"))]
          address: Address<V>,
      }
  ```

  This is cool as hell because the `Address` type is currently a royal PITA.

  Patch 1 is trivial cleanup.

  To get past a build error in `FromStr` I used this little trick
  ```rust
              // We know that `U` is only ever `NetworkUnchecked` but the compiler does not.
              Ok(Address(address.0, PhantomData::<U>))
  ```

  Resolve: #3760
  and
  Close: #3856

ACKs for top commit:
  apoelstra:
    ACK 29a71de92817bccd49b42b1055cc570832e6b959; successfully ran local tests

Tree-SHA512: 7c158dddb9fdbaaa1e48204bbf915b18ced56f5d82ce82630db6c0b52161bcf43b3ac413fa990a23975743c56917985b2666a74f9067221f003f2dcf080f827e
2025-01-09 16:36:13 +00:00
merge-script 2056abd086
Merge rust-bitcoin/rust-bitcoin#3875: Change all occurrences of "IO" to "I/O"
316d8bcb01 Change all occurrences of "IO" to "I/O" (Jamil Lambert, PhD)

Pull request description:

  Fixes #3871

ACKs for top commit:
  tcharding:
    ACK 316d8bcb01
  apoelstra:
    ACK 316d8bcb01504420a14854d2be122d1c8cffb4a9; successfully ran local tests; lgtm

Tree-SHA512: 437a95a1c36bcd4ae27aaacdfc5e0f3463e522a222c4a6ef2c3e234be4a24be2b600687bd58b300bf2b0a0d6596ab008f60903c91646458228eb34cf510908d6
2025-01-08 22:12:24 +00:00
merge-script 72aceb32db
Merge rust-bitcoin/rust-bitcoin#3880: Derive `Clone`on consensus errors
2f91092d77 Derive Clone on consensus errors (Tobin C. Harding)

Pull request description:

  All error types in the repo use either [0]:

  - `#[derive(Debug, Clone, PartialEq, Eq)]``
  - `#[derive(Debug)]`

  However the `consensus` error types do not have `Clone` derived.

  Derive `Clone` on `consensus::ParseError` and `consensus::Error`.

  [0] Excluding `PushBytesError`, fixed in #3879

ACKs for top commit:
  apoelstra:
    ACK 2f91092d773e1618314b62c9e3eae17c08e1f5ad; successfully ran local tests; lgtm

Tree-SHA512: 2cae6faae97b63de311538c33eb7d1914330672744ca073bc6ea5c11ebd40a40ff3de9a38f1f5b101ff27798416d685a708599c298a6f82d7f5804575c2cb2c1
2025-01-08 20:27:32 +00:00
merge-script 31a5e71d57
Merge rust-bitcoin/rust-bitcoin#3879: Remove Copy from `PushBytesError`
0870cd1660 Remove Copy from PushBytesError (Tobin C. Harding)

Pull request description:

  The `PushBytesError` is the only error type in the codebase to derive `Copy`. Without thinking too hard this is unusual - remove it.

  Thinking a bit harder it makes the code less maintainable because we must commit to implementing `Copy`.

ACKs for top commit:
  apoelstra:
    ACK 0870cd1660edd21739cc94075e4b3a1c7f1a7d15; successfully ran local tests; lgtm

Tree-SHA512: c71db5de634dfe2bd76336e5c31fab496f2a472a8dd164034233544c15bd89c84ff986e476fa9b7b05d01aa5332dd4bc93f63a93bf7a21e9a0ec67fc145739b2
2025-01-08 19:03:12 +00:00
merge-script 515a66b854
Merge rust-bitcoin/rust-bitcoin#3839: Use `_unchecked` to construct amounts
a7c44cebf9 Use _unchecked to construct amounts (Tobin C. Harding)
09df951760 Use sat variable in tests (Tobin C. Harding)
4a5b2c60c6 Use ssat variable in tests (Tobin C. Harding)

Pull request description:

  We have a `_unchecked` constructor now for both `Amount` and `SignedAmount`. Soon we would like to start enforcing the `MAX_MONEY` invariant in both amount types. To make that change easier do a few refactorings:

  - Patch 1 and 2 introduce local variables for amount constructors.
  - Patch 3 replaces the local variables introduce in  (1) and (2) with macros
  - Patch 4 uses `_unchecked` constructor for hard coded integers

  The strange patch separation is done intentionally so we don't inadvertently reduce test coverage by using the wrong constructor. I made this mistake already in a previous PR, lesson learned.

  Note please, the macro introduced in patch 3 is in preparation for enforcing `MAX_MONEY`. The macros allow us to panic (`from_sat().unwrap()`) instead of using the `_unchecked` version.

ACKs for top commit:
  apoelstra:
    ACK a7c44cebf9975c4eeba56a65c0ea65be90e5c7f3; successfully ran local tests

Tree-SHA512: 55c2428ae231882542a4cfa724675341f7b493d158f4bec26277d3eefb04d9597cc29b05dce859661a96855fa6f4bac250d53c3dfa9f86a9611d43387ee18667
2025-01-08 04:08:39 +00:00
Tobin C. Harding 2f91092d77
Derive Clone on consensus errors
All error types in the repo use either [0]:

- `#[derive(Debug, Clone, PartialEq, Eq)]``
- `#[derive(Debug)]`

However the `consensus` error types do not have `Clone` derived.

Derive `Clone` on `consensus::ParseError` and `consensus::Error`.

[0] Excluding `PushBytesError`, fixed in #3879
2025-01-08 10:34:47 +11:00
Tobin C. Harding 0870cd1660
Remove Copy from PushBytesError
The `PushBytesError` is the only error type in the codebase to derive
`Copy`. Without thinking too hard this is unusual - remove it.

Thinking a bit harder it makes the code less maintainable because
we must commit to implementing `Copy`.
2025-01-08 10:32:51 +11:00
Tobin C. Harding 706a135de6
bitcoin: Add an example of doing I/O to encode/decode
In an effort to improve the documentation on `bitcoin_io` add an example
in `bitcoin` crate that demonstrates a few things:

- Encode/Decode a `rust-bitcoin` type to/from a stdlib type.
- Encode to a custom type by implementing `bitcoin_io` traits.
- Encode to a foreign custom type by using the `bitcoin_io::bridge::FromStd` wrapper.

Later we can link to this example online in the `bitcoin_io` docs.
2025-01-08 10:18:00 +11:00
Jamil Lambert, PhD 316d8bcb01
Change all occurrences of "IO" to "I/O" 2025-01-07 12:37:47 +00:00
Nick Johnson e09bdb5f98 Add BIP324 V2 p2p network message support
BIP324 introduced the second version of p2p network messages which
are designed to be used with the new encrypted transport. This patch
adds a V2NetworkMessage type which wraps a NetworkMessage and handles
the V2 encoding and decoding. It is a parallel of the existing
RawNetworkMessage type (which may be better described as
V1NetworkMessage). A priority of this patch was to not re-invent any
wheels and try to use the existing patterns as much as possible.
2025-01-06 20:38:57 -08:00
merge-script 70a879279b
Merge rust-bitcoin/rust-bitcoin#3859: Remove usage of impl_from_infallible in crates
f94c7185fd Remove usage of impl_from_infallible in crates (Shing Him Ng)

Pull request description:

  Fixes #3843

  tcharding Copied your commit message from the other `impl_from_infallible` commit 😄

ACKs for top commit:
  apoelstra:
    ACK f94c7185fdd62e1ed98ed4016486406146c4d4f3; successfully ran local tests; nice!
  tcharding:
    ACK f94c7185fd

Tree-SHA512: 8c58c2c87f6892855d74a3306e1027a37394961f0a26b7bd88cc1654a190dda37234e7dde51a419dcd2f1bd1dd1ccceec16bbbc6fbdd5418ad21f10531b402b3
2025-01-06 14:15:17 +00:00
Tobin C. Harding 29a71de928
Bound Address parsing on NetworkValidationUnchecked
Currently it is not possible for downstream to use a generic on the
`Address` type in structs in conjuncture with
derives (`serde::Deserialize` and `Display`) because our impls are only
done for `NetworkUnchecked` (as they should be).

However, as observed by dpc, if we add a secondary marker trait and use
it to bound the impls, implementing the new marker for
`NetworkUnchecked` then downstream can use derives by way of

```
    #[derive(Serialize, Deserialize)]
    struct Foo<V>
        where V: NetworkValidation,
    {
        #[serde(bound(deserialize = "V: NetworkValidationUnchecked"))]
        address: Address<V>,
    }
```

This is cool as hell because the `Address` type is currently a royal PITA.
2025-01-06 17:34:08 +11:00
Tobin C. Harding a7c44cebf9
Use _unchecked to construct amounts
We have a `_unchecked` constructor now for both `Amount` and
`SignedAmount`. In preparation for enforcing the `MAX_MONEY` invariant
use the `_unchecked` constructor throughout the codebase to construct
amounts from hard coded integer values.
2025-01-06 13:14:21 +11:00
merge-script 33d70529bd
Merge rust-bitcoin/rust-bitcoin#3854: Add parenthesis to explicitly show precedence
2c9fda4135 Add parenthesis to explicitly show precedence (Tobin C. Harding)

Pull request description:

  Recent clippy nightly update introduces warnings about precedence. While ours are, IMO, clear the lint docs have some cases that are not so I don't think we should ignore this lint. Specifically I could easily miss this one

    1 << 2 + 3 equals 32, while (1 << 2) + 3 equals 7

  ref: https://rust-lang.github.io/rust-clippy/master/#/precede

  Add parenthesis to explicitly show precedence. Refactor only no logic changes.

ACKs for top commit:
  apoelstra:
    ACK 2c9fda413572e251fe3fd07f679b6c786da137b3; successfully ran local tests; yeah, these all seem reasonable

Tree-SHA512: 67b8cb56c0b271d41db58f9297e4be43410c04bf7bc2308789624084e5e9fee325a2eb3be7e56bd6b3904cf19c7a8b1b426e7adef7f4af18ea8c9d24b77a9db9
2025-01-05 21:37:46 +00:00
merge-script f3e56f1c95
Merge rust-bitcoin/rust-bitcoin#3857: Automated nightly rustfmt (2025-01-05)
762f6630fe 2025-01-05 automated rustfmt nightly (Fmt Bot)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  apoelstra:
    ACK 762f6630fe22e54e5a8b2839054e2e09a5a2db64; successfully ran local tests

Tree-SHA512: 5be013a53697ab2c3f5bb6da8c1c45124d4fee696a655544bb7fad3d28606638a639932d05a990d7e1ae7d91bcc85eb9bc136145a241b39b9089b2e7dc10f5a5
2025-01-05 18:41:02 +00:00
merge-script 8458ca5167
Merge rust-bitcoin/rust-bitcoin#3850: Fix typo in MerkleBlock::from_block_with_predicate comment
d5de89259b Fix typo in MerkleBlock::from_block_with_predicate comment (Jesus Christ)

Pull request description:

  - Corrected a grammatical error by adding "are" to the comment in MerkleBlock::from_block_with_predicate.

ACKs for top commit:
  clarkmoody:
    ACK d5de89259b
  apoelstra:
    ACK d5de89259b64ed6d4756973073f06172d1d14090; successfully ran local tests
  storopoli:
    ACK d5de89259b

Tree-SHA512: 55595e8858e90ee5ab5ef7d592cf2c47dc593f303f3f60040f1612d92abcf4a4d0f9c9ad3bf7eece54f3078a3ab8ff92b36357be58db0919888e239a8a5c1a6b
2025-01-05 16:08:50 +00:00
Shing Him Ng f94c7185fd Remove usage of impl_from_infallible in crates
Rust macros, while at times useful, are a maintenance nightmare. And
we have been bitten by calling macros from other crates multiple times
in the past.

In a push to just use less macros remove the usage of the
`impl_from_infallible` macro in the bitcoin, units, and internals crates
and just write the code.
2025-01-04 23:46:12 -06:00
Tobin C. Harding cf455d3a06
Fix typo in prifixes
Close: #3856
2025-01-05 12:36:56 +11:00
Fmt Bot 762f6630fe 2025-01-05 automated rustfmt nightly 2025-01-05 01:22:00 +00:00
Tobin C. Harding 2c9fda4135
Add parenthesis to explicitly show precedence
Recent clippy nightly update introduces warnings about precedence. While
ours are, IMO, clear the lint docs have some cases that are not so I
don't think we should ignore this lint. Specifically I could easily miss
this one

  1 << 2 + 3 equals 32, while (1 << 2) + 3 equals 7

ref: https://rust-lang.github.io/rust-clippy/master/#/precede

Add parenthesis to explicitly show precedence. Refactor only no logic
changes.
2025-01-04 15:25:00 +11:00
merge-script 72cc88d907
Merge rust-bitcoin/rust-bitcoin#3847: ParsePublicKeyError using hex::InvalidCharError
945fcd0920 fix ParsePublicKeyError using hex::InvalidCharError (Innocent Onyemaenu)

Pull request description:

  Replaced the InvalidChar variant u8 with hex::InvalidCharError

  Resolves #3835

  changed InvalidChar variant of the ParsePublicKeyError from `u8` to `hex::InvalidCharError`

  ```
  pub enum ParsePublicKeyError {
      ...
      /// Hex decoding error.
      InvalidChar(hex::InvalidCharError),
      ...
  }

  Also,

  modified the test cases to accommodate the new variant

  Why:
  - hex::InvalidCharError includes both the invalid character and its position.
  - This improves debugging and makes error messages more actionable.

ACKs for top commit:
  apoelstra:
    ACK 945fcd09209120ef8869a2e4165e866328cc9bd5; successfully ran local tests; I like it
  clarkmoody:
    utACK 945fcd0920

Tree-SHA512: c13446c099cb02b4f253f9cc559a860aff3288a2cc5eac96d3cf910bf63e78957741bbdff69b936b16b36e46b366841a5c94876d16cbc0c41aea2a70866a6e45
2025-01-04 01:05:04 +00:00
merge-script 3b2363b2c6
Merge rust-bitcoin/rust-bitcoin#3846: Remove `test_` prefix from unit tests
85e04315d5 Remove test_ prefix from unit tests (Tobin C. Harding)

Pull request description:

  There is a loose convention in Rust to not use `test_` prefix. The reason being that `cargo test` outputs 'test <test name>' using the prefix makes the output stutter.

  This patch smells a bit like code-churn but having the prefix in some places and not others is confusing to new contributors and is leading me to explain this many times now. Lets just fix it.

  Remove the prefix unless doing so breaks the code.

ACKs for top commit:
  shinghim:
    ACK 85e04315d5
  apoelstra:
    ACK 85e04315d5eb90075ce55bf18fab8876a4583def; successfully ran local tests

Tree-SHA512: d90ae5ef75cc5e5a8f43f60819544f1a447f13cbe660ba71e84b8f27bfcc04a11d3afde0ed56e4eea5c73ebc3925024b800a1b995f73142cab892f97a414f14a
2025-01-04 00:23:46 +00:00
Jesus Christ d5de89259b
Fix typo in MerkleBlock::from_block_with_predicate comment
- Corrected a grammatical error by adding "are" to the comment in MerkleBlock::from_block_with_predicate.
2025-01-03 21:00:13 +00:00
Innocent Onyemaenu 945fcd0920 fix ParsePublicKeyError using hex::InvalidCharError
What:
- Replaced the InvalidChar variant u8 with hex::InvalidCharError

Why:
- hex::InvalidCharError includes both the invalid character and its position.
- This improves debugging and makes error messages more actionable.
2025-01-03 15:33:26 +01:00
Tobin C. Harding 85e04315d5
Remove test_ prefix from unit tests
There is a loose convention in Rust to not use `test_` prefix. The
reason being that `cargo test` outputs 'test <test name>' using the
prefix makes the output stutter.

This patch smells a bit like code-churn but having the prefix in some
places and not others is confusing to new contributors and is leading me
to explain this many times now. Lets just fix it.

Remove the prefix unless doing so breaks the code.
2025-01-02 10:06:50 +11:00
Tobin C. Harding fd8d563b87
Remove macro debug_from_display
Rust macros, while at times useful, are a maintenance nightmare. And
we have been bitten by calling macros from other crates multiple times
in the past.

In a push to just use less macros remove the `debug_from_display`
macro and just write the code.

This is an API breaking change to `internals` but an internal change
only to any of the _real_ crates.
2025-01-02 07:31:13 +11:00
merge-script 21d435cf84
Merge rust-bitcoin/rust-bitcoin#3836: Update to rust-ordered 0.4.0
1a8f5b19fb Update to rust-ordered 0.4.0 (Tobin C. Harding)

Pull request description:

  We just released a version of `ordered` that makes `ArbitraryOrd` object safe - use it.

  Upgrade to the latest version of `rust-ordered` - `v0.4.0`.

ACKs for top commit:
  apoelstra:
    ACK 1a8f5b19fbc37c74bbdd7dcee55b3294046ef88e; successfully ran local tests

Tree-SHA512: 823962a9e6b956126c7ff7a63b780431e358a9f0713f30e3801de3febea1e1e569b8ba3f6e3c0dc3c38759ac233c3d0ddea2223588cd796db6849fae8b599e04
2025-01-01 16:52:11 +00:00
merge-script 16b522043d
Merge rust-bitcoin/rust-bitcoin#3789: Add hash data to Inventory's Error variant
72e97c637f Add a hash value to Inventory's Error variant (Nick Johnson)

Pull request description:

  I am working on adding BIP324 V2 p2p network message support to the p2p module and ran into a little snag. I can post a draft branch of that work if helpful, but the general strategy is to add a `V2NetworkMessage` which operates in parallel with the existing `RawNetworkMessage` type (which is a bit of misnomer and may be better described in the future as `V1NetworkMessage`, see #3157). This allows both p2p message types to hook into the existing `Encodable`/`Decodeable` chain.

  But the `Error` variant of the `Inventory` type message does not have symmetrical encoding and decoding paths. Encoding writes out a zero'd 32 bytes while decoding ignores it completely. And while it is not clear to me if there is [requirement written down](https://en.bitcoin.it/wiki/Protocol_documentation#Inventory_Vectors) anywhere, [bitcoin core does appear to always expect a hash](c1252b14d7/src/protocol.h (L499)) even with the `Error` variant where it is meaningless.

  I believe rust-bitcoin's handling of this was never a problem before because the top level `RawNetworkPackage` pulls all the required bytes off a reader before decoding them. But this is not as easy to do with the v2 p2p network messages since the length is decoded at the transport level, not the message itself. I believe it is preferable for the Decoders to *not* assume that all bytes have been pulled off already given their input stream interface. Maybe somewhat surprisingly, this is the only issue I have run into so far adding the v2 encoding and decoding paths. As it is now, the code panics with an `Unconsumed` because it hasn't pulled the dummy zero bytes off the reader.

  This patch adds the 32 byte array to the Error variant in order to make its Encoding and Decoding paths symmetrical. This also allows a reader to discard the 32 bytes when decoding a message while cleanly keeping things hooked up with the `Decodeable` chain. The hash is still not exposed to the caller.

  This is *a way* to solve my issue, but not sure if it will cause more confusion than its worth. I tried a few other strategies, but preferred this one due to how well it hooks into `Decodeable`.

ACKs for top commit:
  apoelstra:
    ACK 72e97c637fa0916be75aef28ea8169ffbbe2c4f5; successfully ran local tests
  tcharding:
    ACK 72e97c637f

Tree-SHA512: 20cb9fec0768e0fdf7c7f520a00e1a37f5ef0583e2ebc7d47583249c6829c47826d83694a56338efa5844a9fe264a77f6d04c0c46c85f8732c7585515723d7ce
2024-12-31 14:08:25 +00:00
Tobin C. Harding 1a8f5b19fb
Update to rust-ordered 0.4.0
We just released a version of `ordered` that makes `ArbitraryOrd` object
safe - use it.

Upgrade to the latest version of `rust-ordered` - `v0.4.0`.
2024-12-31 10:42:24 +11:00
Tobin C. Harding 20b798175c
Update to latest rust-ordered
I just went to town on the `rust-ordered` crate to get it ready for
releasing a `1.0` version. None of the changes effect our usage here in
`rust-bitcoin`.

Upgrade to the latest version of `rust-ordered` - `v0.3.0`.
2024-12-30 08:35:01 +11:00
merge-script 779768eff9
Merge rust-bitcoin/rust-bitcoin#3769: Change method return type for to_unsigned()
e13355318e Add From impl (yancy)
364e9ff775 Change method return type (yancy)
fdf3336ed5 Add unchecked variant (yancy)

Pull request description:

  Any SignedAmount can now be cast to Amount since the range is the same.  Specifically, the range for SignedAmount is (- 21 million, 21 million) while the range for Amount is (0, 21 million).  Therefore any value from Amount can be cast to a SignedAmount and it will work.  Note it's not the same and still requires checking when going from SignedAmount to Amount since Amount can't handle the negative range.

ACKs for top commit:
  tcharding:
    ACK e13355318e

Tree-SHA512: c016b51bdd87a12eb09d9c1a82699dad1e866bf96bd3235eeb131f216f02422acb992ddb3a8135af00bbc10e240178fde5e37fb7860d9e6eaf433cf917d4d16a
2024-12-29 14:58:47 +00:00
yancy 364e9ff775 Change method return type
Any SignedAmount can now be cast to Amount since the range is the same.
Specifically, the range for SignedAmount is (- 21 million, 21 million)
while the range for Amount is (0, 21 million).  Therefore any value from
Amount can be cast to a SignedAmount and it will work.  Note it's not
the same and still requires checking when going from SignedAmount to
Amount since Amount can't handle the negative range.

As a side effect of changing the return type, TryFrom is no longer valid
and does not compile.  Therefore in addition to changing the return
type, TryFrom is also removed.
2024-12-24 11:31:49 -06:00
merge-script 2de44ab2a6
Merge rust-bitcoin/rust-bitcoin#3798: refactor: use amount type
774f066879 refactor: Change from u64 to Amount (yancy)

Pull request description:

  Separate out refactor commit from https://github.com/rust-bitcoin/rust-bitcoin/pull/3794.  Can be merged independently.

ACKs for top commit:
  tcharding:
    ACK 774f066879
  apoelstra:
    ACK 774f066879c8ad1af81c7e46b404fa63682a0b4c; successfully ran local tests

Tree-SHA512: 9ec5121d823ee3ec506eee5b5187bd496221bd3576afcaa6daf647099720d87b58b69521f29ae9537f123e2958771bc867b123da3f2ba941cba403a6c98e46de
2024-12-24 14:53:03 +00:00
yancy 774f066879 refactor: Change from u64 to Amount
The Amount type provides better type safety and is more appropriate in
this context than u64.  Currently the checked arithmetic operations for
Amount and u64 are identical in behavior.  Therefore, this refactor does
not result in any behavior change and is purely cosmetic.
2024-12-23 13:03:53 -06:00
calciumbe bcf8580913
bitcoin: fix typo 2024-12-23 20:44:18 +08:00
Nick Johnson 72e97c637f Add a hash value to Inventory's Error variant
While the hash value of the Error variant is meaningless, the variant
still conforms to all other Inventory messages and requires a 32
byte hash to be sent over the wire. This is how bitcoin core operates.

This patch adds the 32 byte array to the Error variant in order to make
its Encoding and Decoding paths symmetrical. This also allows a reader
to discard the 32 bytes when decoding a message. The hash is still not
exposed to the caller.

This was never a problem before because the top level RawNetworkPackage
pulls all the required bytes off a reader before decoding. But this is
not as easy to do with the v2 p2p network messages.
2024-12-18 19:24:26 -08:00
merge-script f4069fcd61
Merge rust-bitcoin/rust-bitcoin#3780: Use uniform capitalisation of SegWit in rustdocs
e56f461916 Make capitalization of SegWit uniform in strings (Jamil Lambert, PhD)
3520e832ac Make capitalization of SegWit uniform in rustdocs (Jamil Lambert, PhD)

Pull request description:

  Fixes #3770

  - Searched and replaced all occurrences of `//` * `segwit` (case insensitive) with `//` * `SegWit`
  - Searched and replaced all occurrences of `"` * `segwit` (case insensitive) with `"` * `SegWit`

ACKs for top commit:
  apoelstra:
    ACK e56f461916b85928139950074d0df52caf4f919b; successfully ran local tests

Tree-SHA512: c56704102d8e86f26378bb302d5fdc7ea21d41fd49f55606e589ec32ff896f1adfb1960d8fb29abccfbf298b90fc357ed609d80fd0163dcb4ff01573646b02c3
2024-12-17 18:10:44 +00:00
merge-script 1d3f42e589
Merge rust-bitcoin/rust-bitcoin#3762: Remove double spacing in rustdocs
bb29490308 Remove double spacing in rustdocs (Jamil Lambert, PhD)

Pull request description:

  Fixes #3761

ACKs for top commit:
  apoelstra:
    ACK bb294903086e2e317c9a7a6f298a36ec17082c39; successfully ran local tests

Tree-SHA512: efc41bdfd7b46bae4ed1159c852b3a2df0a95e36e1964679640de37ae3e0cc994426e7e9d643beb5ba0f5210bb6c2a19028fc8d28a6150580bad4471d4502bb3
2024-12-17 16:38:01 +00:00