Commit Graph

2330 Commits

Author SHA1 Message Date
merge-script 1fee075502
Merge rust-bitcoin/rust-bitcoin#4616: units: Improve the fee calculation functions
0ff8d82193 Make FeeRate from sat constructors infallible (Tobin C. Harding)
3b0286bd56 Return NumOpResult for FeeRate and Weight (Tobin C. Harding)
15065b78c7 Return NumOpResult when calculating fee on Amount (Tobin C. Harding)
75106e6d82 Remove checked_ prefix from fee functions (Tobin C. Harding)

Pull request description:

  This was 14dc950b54 from #4610.

  Remove the `checked_` prefix from `fee` functions then make them all return `NumOpResult`.

ACKs for top commit:
  apoelstra:
    ACK 0ff8d82193ef562c1aedabe98a6283d09f803c0c; successfully ran local tests; nice!

Tree-SHA512: 62f2af6701f2a0e17b9f0a0ee132ca4a9289fe00e22c94f746602ed3c1f3758bb22323b224362cb659432ff5297391f3106ee460e9a8f65a39f904d72bc98aeb
2025-06-16 19:47:31 +00:00
Tobin C. Harding 0ff8d82193
Make FeeRate from sat constructors infallible
We now have constructors that take an arbitrary size fee
rate (`Amount`). The `from_sat_per_foo` constructors can be made
infallible by taking a `u32` instead of `u64`. This makes the API more
ergonomic but limits the fee rate to just under 42 BTC which is plenty.

Note we just delete the `from_sat_per_vb_u32` function because it is
unreleased, in the past we had `from_sat_per_vb_unchecked` so we could
put that back in if we wanted to be a bit more kind to downstream. Can
be done later, we likely want to go over the public API before release
and add a few things back in that we forgot to deprecate or could not
for some reason during dev.

Fuzz with a new function that consumes a `u32`.
2025-06-16 09:56:42 +10:00
Tobin C. Harding 15065b78c7
Return NumOpResult when calculating fee on Amount
Currently we call the `Amount` fee calculation functions `div_by_foo`
and return an `Option` to indicate error. We have the `NumOpResult`
type that better indicates the error case.

Includes a bunch of changes to the `psbt` tests because extracting the
transaction from a PSBT has a bunch of overflow paths that need testing
caused by fee calculation.
2025-06-16 08:48:05 +10:00
Fmt Bot 81dbfae0a8 2025-06-15 automated rustfmt nightly 2025-06-15 01:46:36 +00:00
Tobin C. Harding e7c90c57e7
Remove reachable unreachable call in psbt
A bunch of changes have been implemented lately in the fee calculation
logic. As a result of this a at once time `unreachable` statement is now
reachable - bad rust-bitcoin devs, no biscuit.

Saturate to `FeeRate::MAX` when calculating the fee rate, check against
the limit arg, and win.

Co-developed-by: Andrew Poelstra <apoelstra@wpsoftware.net>
2025-06-12 11:33:17 +10:00
merge-script f2c6ec3b8c
Merge rust-bitcoin/rust-bitcoin#4569: bitcoin: secp256k1 global-context feature re-export
aa76108315 bitcoin: secp256k1 global-context feature re-export (Jose Storopoli)

Pull request description:

  Often we want to have the `global-context` feature in `secp256k1` without having to add manually the `secp256k1` dependency and enabling the `global-context` feature.

  Having the ability to do that directly from `bitcoin` without having to add `secp256k1` and do the whole tango of tightly coupling the two dependecies versions together, e.g. `bitcoin` `0.32.x` and `secp256k1` `0.29.x` would be really nice and would also simplify a lot code maintainability for anyone who depends on bitcoin.

  This needs to be backported to `0.32.x`, which I'll gladly do as well.

ACKs for top commit:
  luisschwab:
    ACK aa76108315
  tcharding:
    ACK aa76108315

Tree-SHA512: ff0e0016a6bf7cadf42cb40857393acace538fc3fb5214b89d4222a2fe570e9ae79617ae276273eefc34c3b68a64100bb22a9c01f9075cc3ed0705d7a264b9b3
2025-06-10 12:32:08 +00:00
Jamil Lambert, PhD 69ce8f448b
Remove unneeded return statement
New clipply lint in rustc nightly "unneeded `return` statement".

Remove it.
2025-06-09 09:35:44 +01:00
Jamil Lambert, PhD 8e60711265
Use the anonymous lifetime for paths
New clippy lint in rustc nightly "lifetime flowing from input to output
with different syntax can be confusing".

Apply the suggested fix and use the anonymous lifetime for paths.
2025-06-09 09:31:55 +01:00
merge-script 17cd382327
Merge rust-bitcoin/rust-bitcoin#4599: Add backticks around OPCodes
ebb9861c58 Add backticks around OPCodes (yancy)

Pull request description:

  Item in documentation is missing backticks

ACKs for top commit:
  tcharding:
    ACK ebb9861c58
  apoelstra:
    ACK ebb9861c58419c1f2e3cce2ef4ecdfa1dee144e0; successfully ran local tests

Tree-SHA512: 1a06db90c026544efda2b248d2e1fd2ca49af9e9828c52b427077edf65e8a6fa789b691e9411d704459a55aae7f28b4bd784a493e89506b83c872b4ecbb9fe1e
2025-06-08 18:44:43 +00:00
Fmt Bot 4b5c6dd547 2025-06-08 automated rustfmt nightly 2025-06-08 01:44:53 +00:00
yancy ebb9861c58 Add backticks around OPCodes
Item in documentation is missing backticks
2025-06-07 12:10:24 -05:00
merge-script 9d586a982b
Merge rust-bitcoin/rust-bitcoin#4590: Clean up `bip32` test
dd3f3e44bc Split into_derivation_path tests out (Tobin C. Harding)
0c9dd31f53 Test with m prefix (Tobin C. Harding)
c5073f4c51 Refactor simple valid path tests into a loop (Tobin C. Harding)
3e7fdad5fd Split empty master test out (Tobin C. Harding)
ed36a980f8 Refactor invalid derivation path tests (jamillambert)
015fb1be3b Split invalid derivation path test (jamillambert)
76dd6100a2 Split derivation path test into valid and invalid (jamillambert)

Pull request description:

  Refactor tests like its our job.

  Co-developed-by: Jamil Lambert <jamil.lambert@proton.me>

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

Tree-SHA512: 8907ff127c11767a600cf856fb34645eb78392c755998565675a026dc4ddd9db00083963414f7e45fc7a2194ad3c5f251f7249bc7d7a2150a5840d1ec8b5d4da
2025-06-06 15:51:02 +00:00
merge-script 4213d4a9d3
Merge rust-bitcoin/rust-bitcoin#4592: Remove unnecessary closure
a1e8fabbbe Remove unnecessary closure (Tobin C. Harding)

Pull request description:

  We can just pass the function directly. Found by clippy bizarrely after running `rustfmt` (in bot-created PR #4586).

  Internal change only, no logic change.

ACKs for top commit:
  yancyribbens:
    cr ACK a1e8fabbbe
  apoelstra:
    ACK a1e8fabbbe26cbe62e1a966cc0c760407bfb063f; successfully ran local tests

Tree-SHA512: 19d5ee65da7cfdae82a9a6609afac6d6b03d1c44c0c5bed21916ec31665e76adfc836ac6a1980251db2b9d5704baa577783dc967b1f0035cf662389c87fc6a0a
2025-06-04 21:00:30 +00:00
merge-script a746456601
Merge rust-bitcoin/rust-bitcoin#4568: Remove conversion impl macro for `Magic`/`Network`
028a0d6558 Remove conversion impl macro for `Magic`/`Network` (rustaceanrob)

Pull request description:

  Closes #4560 (or at least one way to close it)

  Handle the coversion of new networks directly in the `From` and `TryFrom` implementations, as new networks are added infrequently.

ACKs for top commit:
  tcharding:
    ACK 028a0d6558
  apoelstra:
    ACK 028a0d6558129f554de8c4247481bc0ad80f1c27; successfully ran local tests

Tree-SHA512: 07b768e229305878849f23e54d3fb4940a736ce44122950e4f4bf68ddeb4f82f2d35020840e8176bd7b562726e46055650ba6de8559bae7559c881b64a437169
2025-06-04 18:17:25 +00:00
merge-script fa07198f21
Merge rust-bitcoin/rust-bitcoin#4511: Modify `locktime` `serde` implementations
4621d2bde1 Modify locktime serde implemenations (Tobin C. Harding)
200c276315 bitcoin: Make test code spacing uniform (Tobin C. Harding)

Pull request description:

  Patch 1 is preparatory clean up. Patch 2 is the meat and potatoes. See commit log there for full explanation.

  Briefly:

      - Remove `serde` stuff from `units::locktime`
      - Manually implement `serde` traits on `relative::LockTime`
      - Fix the regression test to use the new format

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

Tree-SHA512: bc96d79dd4d9f5a124c22f0d3be4750cb7b6e86ba448b31e233982567578337d331b2582c6e1f953c00e8393c4a4552c4b574fe8a55323c911115b269b24090e
2025-06-04 17:32:02 +00:00
merge-script a13ba99c11
Merge rust-bitcoin/rust-bitcoin#4534: Make `FeeRate` use MvB internally
56516757ad Add code comment to amount calculation (Tobin C. Harding)
8cf1dc39b5 Fix incorrect code comment (Tobin C. Harding)
7c186e6081 Refactor fee functions (Tobin C. Harding)
bf0776e3dd Remove panic using checked arithmetic (Tobin C. Harding)
b65860067f Make fee functions const (Tobin C. Harding)
9b2fc021b2 Improve rustdocs on FeeRate (Tobin C. Harding)
1bd1e89458 Re-introduce FeeRate encapsulate module (Tobin C. Harding)
b27d8e5819 Change the internal representation of FeeRate (Tobin C. Harding)
2e0b88ba76 bitcoin: Fix dust 'fee' identifiers (Tobin C. Harding)
399bca531c Reduce the FeeRate::MAX value (Tobin C. Harding)
d174c06a4a Saturate to_fee to Amount::MAX (Tobin C. Harding)
64ac33754f Add missing argument docs (Tobin C. Harding)
fe0a448e78 Temporarily remove const from fee calc function (Tobin C. Harding)
b929022d56 Add floor/ceil versions of to_sat_per_kwu (Tobin C. Harding)
64098e4578 Remove encapsulate module from fee rate (Tobin C. Harding)

Pull request description:

  The `FeeRate` is a bit entangled with amount and weight.  Also we have an off-by-one bug caused by rounding errors and the fact that we use kwu internally.

  We can get more precision in the fee rate by internally using per million virtual bytes.

  - Fix: #4516
  - Fix: #4497
  - Fix: #3806

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

Tree-SHA512: 0c6e7e2c9420886d5332e32519838d6ea415d269abda916e51d5847aa2475c87fa4abfc29b5f75e8b10c44df67ae29d823aa93f7cfabbc89eb27f2173b103242
2025-06-04 16:42:55 +00:00
Tobin C. Harding a1e8fabbbe
Remove unnecessary closure
We can just pass the function directly. Found by clippy bizarrely after
running `rustfmt` (in bot-created PR #4586).

Internal change only, no logic change.
2025-06-04 07:36:52 +01:00
Tobin C. Harding dd3f3e44bc
Split into_derivation_path tests out
The test _still_ tests multiple things.

Move the `into_derivation_path` calls into a separate test.
2025-06-03 12:05:03 +01:00
Tobin C. Harding 0c9dd31f53
Test with m prefix
We have a single test case that tests for the m prefix while all the
others do not.

Move one test case into the loop and then test on each iteration the
path with m prefix added.
2025-06-03 12:03:06 +01:00
Tobin C. Harding c5073f4c51
Refactor simple valid path tests into a loop
The test is still doing a bunch of stuff.

Pull the simple test cases into a loop.
2025-06-03 11:51:48 +01:00
Tobin C. Harding 3e7fdad5fd
Split empty master test out
The valid derivation test is doing a whole bunch of things.

Split out the empty master path assertions into a separate test.
2025-06-03 11:37:12 +01:00
jamillambert ed36a980f8
Refactor invalid derivation path tests
Refactor the tests to have the invalid paths in a list, or string.
2025-06-03 11:20:28 +01:00
jamillambert 015fb1be3b
Split invalid derivation path test
The test tests two sperate things.

Split the test into invalid path and out of range.
2025-06-03 11:19:52 +01:00
jamillambert 76dd6100a2
Split derivation path test into valid and invalid
Make the tests separate to make tests smaller and easier to read.

There are no logic changes.
2025-06-03 11:18:44 +01:00
merge-script a419fc9aa6
Merge rust-bitcoin/rust-bitcoin#4565: Remove all `p2p` dependency from `network`
cbe04b00c6 Remove all `p2p` dependency from `network` (rustaceanrob)

Pull request description:

  Motivated by moving the `p2p` module to its own crate. `TryFrom` and `From` are already implement for converting to and from `Network`/`Magic`. The methods related to `Magic` are removed from `Network`, as well as any reference to `p2p` in the documentation, as `bitcoin` would no longer depend on `p2p`.

  The deser roundtrip test are relocated to `p2p/mod.rs`

ACKs for top commit:
  tcharding:
    ACK cbe04b00c6
  apoelstra:
    ACK cbe04b00c67eab896b7ec0535194771ec36cb68f; successfully ran local tests

Tree-SHA512: ac3aa2eef4d78efd719ccc032a4266827faff8c87997111fa0050765b732462e5e5811c8aa923aedba335cbaad9a374fd54dbbe0f4978a1111d0839a5942af7d
2025-06-01 18:23:15 +00:00
Tobin C. Harding 4621d2bde1
Modify locktime serde implemenations
The `units::locktime` types are used for two things:

- They are the inner types of `primitives` `LockTime`s
- They are used ephemerally for checking satisfaction

Neither of these use cases requires `serde` impls for the `units` types.
Since we are trying to release 1.0 with minimal amounts of code we
should remove them.

For `LockTime`s that need to be stored on disk or go over the wire we
can manually implement the `serde` traits. For `absolute::LockTime` this
is done already and there is no reason the `relative::LockTime` impl
cannot be the same [0]. This differs from the current `serde` trait impls
but we have already decided that in 0.33 we are going to accept breakage
and direct users to use 0.32 to handle it.

- Remove `serde` stuff from `units::locktime`
- Manually implement `serde` traits on `relative::LockTime`
- Fix the regression test to use the new format

While we are at it use a uniform terse call in `serialize`.

[0] This is because there is an unambiguous encoding for the whole set
of locktimes - consensus encoding.
2025-06-01 14:07:33 +01:00
Tobin C. Harding 200c276315
bitcoin: Make test code spacing uniform
Make test code use uniform spacing - twitch averted.

Whitespace only, no logic change.
2025-06-01 14:07:28 +01:00
merge-script 2113a32276
Merge rust-bitcoin/rust-bitcoin#4571: Move `p2p` encodings from `encode` and into `p2p`
20779bdbc8 Move `p2p` encodings out of `encode` (rustaceanrob)
94bcff28b1 p2p: Add wrappers for messages that use `Vec` (rustaceanrob)

Pull request description:

  To move `p2p` into a crate:
  1. All `Encodable` implementations for `p2p` must be defined in `p2p`. To accomplish this, and anything else in the future related to encoding, I added a `deser` module with the necessary macro to implement `Encodable` for `Vec<T> where T: Encodable`.
  2. Because the orphan rule would apply for implementing `Encodable`for `Vec` within `p2p`, three types defined within `p2p` are used to wrap the `Vec` and snake around the orphan rule.

ACKs for top commit:
  tcharding:
    ACK 20779bdbc8
  apoelstra:
    ACK 20779bdbc8ebcac2365d122e857c23b3d8e8d1e7; successfully ran local tests

Tree-SHA512: 7abfe5b853e84bb465579309f80a0687c325217f6f342651278bedf540c4d17ae16683ab02dea5e3d98d90790deb12c6bc7d572a92cec8e19ff94e395bc0d29c
2025-05-31 21:09:28 +00:00
merge-script 6d8299e8b8
Merge rust-bitcoin/rust-bitcoin#4468: Improve lock times - fix off-by-one bug
4ccecf5dec Fix stale Height type link (Tobin C. Harding)
caebb1bf73 units: relative: Do minor rustdocs fixes (Tobin C. Harding)
40bb177bc2 Put is_satisfied_by functions together (Tobin C. Harding)
480a2cd62a Favour new function `from_mtp` over deprecated (Tobin C. Harding)
f9d6453d5b Shorten locktime type term (Tobin C. Harding)
727047bd39 Fix off-by-one-bug in absolute locktime (Tobin C. Harding)
3ffdc54ca5 Fix off-by-one bug in relative locktime (Tobin C. Harding)
a2ff8ddbbb Improve relative::LockTime is_satisfied_by_{height, time} (Tobin C. Harding)

Pull request description:

  Make the APIs uniform in relative and absolute locktimes in relation to the `is_satisfied_by` functions. In doing so improve the API and fix an off-by-one bug when checking satisfaction of locks by height.

  Done in three patches but maybe should be squashed? Probably easiest to review by looking at all the `is_satisfied_by*` functions and convincing yourself we got it right.

  EDIT: Now has 5 cleanup patches also (mostly docs cleanups).

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

Tree-SHA512: 9206cb464a06647510a35a7d564062823117e75df60251969be458616f4f5d04acf0aada53dbf7d493a2a2a72d26b3a300417a6499e45413d5f2a011538b7826
2025-05-31 15:48:29 +00:00
Tobin C. Harding 56516757ad
Add code comment to amount calculation
Its not immediately obvious that x - y cannot overflow. Add a code
comment to explain it.
2025-05-31 07:52:36 +01:00
Tobin C. Harding 8cf1dc39b5
Fix incorrect code comment 2025-05-31 07:52:36 +01:00
Tobin C. Harding b27d8e5819
Change the internal representation of FeeRate
To get more precision use sats per million virtual bytes.

To make review easier keep most calls in tests using
`FeeRate::from_sats_per_kwu` and just unwrap. These can likely be
cleaned up later on if we want to.

For `serde` just change the module to `_floor` and leave it at that. The
serde stuff likely needs re-visiting before release anyways.
2025-05-31 07:52:31 +01:00
Tobin C. Harding 2e0b88ba76
bitcoin: Fix dust 'fee' identifiers
Currently we get the fee_rate per kwu then multiply it by 4. Instead
lets add a per_kvb function to `FeeRate`. We are about to change the
internal representation of `FeeRate` to use MvB so for now just panic on
ovelflow.

Also these are fee _rates_ - we already have suboptimal names from Core
in the consts in `policy`, no need to let them infect other identifiers.
2025-05-31 07:52:01 +01:00
Tobin C. Harding 399bca531c
Reduce the FeeRate::MAX value
In preparation for changing the internal representation of `FeeRate` to
use MvB reduce the max value by 4_000.

Done separately to make the change explicit.
2025-05-31 07:52:00 +01:00
Tobin C. Harding d174c06a4a
Saturate to_fee to Amount::MAX
The `FeeRate::checked_mul_by_weight` function currently returns a
`NumOpResult` but all other `checked_` functions return an `Option`.
This is surprising and adds no additional information.

Change `checked_mul_by_weight` to return `None` on overflow. But in
`to_fee` saturate to `Amount::MAX` because doing so makes a few APIs
better without any risk since a fee must be checked anyway so
`Amount::MAX` as a fee is equally descriptive in the error case.

This leads to removing the `NumOpResult` from `effective_value` also.

Note that sadly we remove the very nice docs on `NumOpResult::map`
because they no longer work.

Fix: #4497
2025-05-31 07:52:00 +01:00
Tobin C. Harding 64ac33754f
Add missing argument docs
We document the other to arguments already, add the missing one.
2025-05-31 07:52:00 +01:00
Tobin C. Harding b929022d56
Add floor/ceil versions of to_sat_per_kwu
In preparation for changing the inner representation of `FeeRate` add
floor and ceil versions of the getter function `to_sat_per_kwu`.

For now both functions return the same thing but still call the
correct one so that when we change the representation we do not need
to re-visit them.
2025-05-31 07:51:59 +01:00
rustaceanrob cbe04b00c6
Remove all `p2p` dependency from `network`
Motivated by moving the `p2p` module to its own crate. `TryFrom` and
`From` are already implement for converting to and from
`Network`/`Magic`. The methods related to `Magic` are removed from
`Network`, as well as any reference to `p2p` in the documentation, as
`bitcoin` would no longer depend on `p2p`.

The deser roundtrip test are relocated to `p2p/mod.rs`
2025-05-29 15:20:10 +01:00
merge-script f0302f2ecd
Merge rust-bitcoin/rust-bitcoin#4570: fix(p2p): remove `AddrV2` <> `SocketAddr` conversions
6335c623f6 fix(p2p): remove `AddrV2` <> `SocketAddr` conversions (Luis Schwab)

Pull request description:

  This PR reverts #4521 due to loss/creation of port information during the conversion. Users should use the `AddrV2` <> `IpAddr` conversion instead.

  Closes #4566

ACKs for top commit:
  Kixunil:
    ACK 6335c623f6
  tcharding:
    ACK 6335c623f6

Tree-SHA512: f183756467ca17bb7e7078023a769ec33d3deb4146ab7ec63ef961107ab93ec975c9adffd9eeddc79250abfa1cee9eccbbcaef7466cf4c2c21205b69d8e9eb4f
2025-05-28 14:28:10 +00:00
merge-script 3c8eeeb42a
Merge rust-bitcoin/rust-bitcoin#4562: Remove redundant `ServiceFlags` test
9d956e8643 test: remove redundant `ServiceFlags` test (rustaceanrob)

Pull request description:

  The `ServiceFlags` type is already tested within p2p/mod.rs with a nearly identical test. This type also has nothing to do with `network`

  ref: https://github.com/rust-bitcoin/rust-bitcoin/blob/master/bitcoin/src/p2p/mod.rs#L400

ACKs for top commit:
  tcharding:
    ACK 9d956e8643
  apoelstra:
    ACK 9d956e8643214b3c1ad0e42cc630e2f35f7b7994; successfully ran local tests

Tree-SHA512: d113609070e3df6d44b1ed57c40c1bce251d59fa22eb1abbf6c576fd84e21464553bee7fa97eba000ad9c1b8ef98e2ba04aec7077486273de9b7e54341ba894b
2025-05-28 13:48:43 +00:00
merge-script 0064ad67a6
Merge rust-bitcoin/rust-bitcoin#4557: Move CheckedSum and add Weight
9dac4d69e0 Implement CheckedSum for Weight iterator (yancy)
0dbcd09bbc Move CheckedSum trait to crate root (yancy)

Pull request description:

  * Move CheckedSum to the crate root so that other types can be added
  * Add Weight to CheckedSum

ACKs for top commit:
  tcharding:
    ACK 9dac4d69e0
  apoelstra:
    ACK 9dac4d69e0f142e9a2dc4b61ea49365a8cae3f4b; successfully ran local tests

Tree-SHA512: 3e4b7f79074e23493ccd17a026542081f0d7a811f4f35edb7994ada95bf414a166531f142ad4986d27fcec448209b2ffa56813b495b5df6b6e8fcd589392e0c1
2025-05-28 04:09:12 +00:00
rustaceanrob 028a0d6558
Remove conversion impl macro for `Magic`/`Network`
Closes #4560

Handle the coversion of new networks directly in the `From` and
`TryFrom` implementations, as new networks are added infrequently.
2025-05-27 17:36:50 +01:00
rustaceanrob 20779bdbc8
Move `p2p` encodings out of `encode`
All of the `Encodable` implementations are defined within `p2p` with the
exception of `p2p` types that are a `Vec`. To fully decouple `p2p` from
`encode` we can define these in `p2p` like the others. This is the final
step in removing anything `p2p` related from the rest of `bitcoin`.
2025-05-27 14:41:03 +01:00
Luis Schwab 6335c623f6
fix(p2p): remove `AddrV2` <> `SocketAddr` conversions 2025-05-27 10:32:23 -03:00
rustaceanrob 94bcff28b1
p2p: Add wrappers for messages that use `Vec`
In preparation to move `p2p` to its own crate, any `Vec<T>` that satisfies
`T: Encodable` will not trivially implement `Encodable` because of the
orphan rule. A type defined within p2p may implement `Encodable`,
however, and the simplest possible type is one that simply wraps the
vector. Three types that will implement `Encodable` within `p2p` are
added here.
2025-05-27 13:55:21 +01:00
Jose Storopoli aa76108315
bitcoin: secp256k1 global-context feature re-export
Often we want to have the global-context feature in secp256k1 without
having to add manually the secp256k1 dependency and enabling the
global-context feature.

Having the ability to do that directly from bitcoin without having to
add secp256k1 and do the whole tango of tightly coupling the two
dependecy versions together, e.g. bitcoin 0.32.x and secp256k1 0.29.x
would be really nice and would also simplify a lot code maintainability
for anyone who depends on bitcoin.

This needs to be backported to 0.32.x, which I'll gladly do as well.
2025-05-27 08:25:40 -03:00
rustaceanrob 9d956e8643
test: remove redundant `ServiceFlags` test
The `ServiceFlags` type is already tested within p2p/mod.rs with a
nearly identical test. This type also has nothing to do with `network`
2025-05-27 10:09:44 +01:00
yancy 0dbcd09bbc Move CheckedSum trait to crate root
In order to add other types to CheckedSum, remove from the Amount
module.  In so doing, other types added to CheeckSum do not need to be
imported into Amount.
2025-05-26 19:01:42 -05:00
merge-script 5e0b86d2b1
Merge rust-bitcoin/rust-bitcoin#4440: Add support for de/serializing PSBT_{IN,OUT}_MUSIG2_PARTICIPANT_PUBKEYS
2481695b45 Add tests for BIP-373 PSBT_{IN,OUT}_MUSIG2_PARTICIPANT_PUBKEYS serialization and deserialization (Daniel Roberts)
3e8e6d9aa1 Add BIP-373 PSBT_{IN,OUT}_MUSIG2_PARTICIPANT_PUBKEYS serialization and deserialization (Daniel Roberts)

Pull request description:

  This change adds support for serializing and deserializing two PSBT keys from BIP-373: `PSBT_IN_MUSIG2_PARTICIPANT_PUBKEYS` and `PSBT_OUT_MUSIG2_PARTICIPANT_PUBKEYS`

  This is a part of #4207 that can be implemented independently of the rest (which depends on https://github.com/rust-bitcoin/rust-secp256k1/pull/716). I believe this satisfactorily avoids changing things multiple times on end users, *however* it's not *completely* transparent to end users, since any code that currently accesses these fields through `unknown` will need to be updated. Later, when `PSBT_IN_MUSIG2_PUB_NONCE` and `PSBT_IN_MUSIG2_PARTIAL_SIG` are supported, code will need to be updated a second time to retrieve them from the correct place instead of `unknown`. I'm of the opinion that this imposes a very minor maintenance burden, only consisting of *removing* deserialization code.

  ### Notes/Requests for feedback

  - For the most part I used my judgement rather than `cargo fmt` since `cargo fmt` already had a lot of other complaints, but of course I'll update if I need to.
  - To satisfy the requirement that every commit pass tests, the commit updating the psbt serde regression test should probably be squashed into the first commit, but I just wanted to confirm that before I did it. I suppose similarly, the test commit could be squashed as well?
  - I waffled between `musig2_participants` and `musig2_participant_pubkeys`, but I've decided to go with `musig2_participant_pubkeys` because that is consistent with Bitcoin Core

ACKs for top commit:
  tcharding:
    ACK 2481695b45
  apoelstra:
    ACK 2481695b456bcccbb25c247c1fd39bbda24dbb30; successfully ran local tests

Tree-SHA512: af884923593c9cbb24ff3f1f08219458538592fabde85d5d65bc2d9bc7bf0b1a73dac38d2c56303b4f3162088db129ea7e879c3d4b324e965933c121ef939a07
2025-05-26 19:17:48 +00:00
yancy 8dd24cb67b Add Arbitrary type for InputWeightPrediction
This type creates sane Arbitrary InputWeightPrediction types that do
not panic.  To this end, when a custom type is created by calling new()
or from_slice() constructor, only use values that would no greater than
block size 4 Mwu.
2025-05-25 13:15:56 -05:00