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.
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.
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.
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
Code that works with `const` is annoying to use and hard to reason
about. Just remove all the consts for now so we can hack on `FeeRate`.
Introduces two lint warnings about manual implementation of `map` but
they will go away later.
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.
357ae4051a fix typo Porallel to Parallel crypto.rs (Fallengirl)
Pull request description:
Hi devs! Found and fixed one typo in `hashes/src/ripemd160/crypto.rs`
`Porallel` - `Parallel`
ACKs for top commit:
tcharding:
ACK 357ae4051a
Tree-SHA512: 67b166f8f0262cc9f4fdd9d4cbe74977ca86e0256d0129f645559aa4e75fd30d978d8995d503932c90f000eee4d87b47cc4dd5eac8405d5cd02124346ad35b3a
7b52b9c3a3 Fix typo (yancy)
Pull request description:
Seems the comment has a stutter
ACKs for top commit:
tcharding:
ACK 7b52b9c3a3
apoelstra:
ACK 7b52b9c3a3c28afad41d9a246302ce95e4997ee5; successfully ran local tests
Tree-SHA512: 1cb11c03bb3043c19936dbe4c2ccfa1e8fa43e90c118c969da536d010d95762966cc86e257e3365d18d96cc6dfe4a63d94c4d16b1b766dde3882286ce9bb4925
e47836fb1e Do not derive Default on CompactTarget (Tobin C. Harding)
Pull request description:
It is not immediately obvious what a zero value compact target is. Because of this and the fact that we are trying to release minimal code in `primitives 1.0` its best to remove the `Default` derive.
This is an API breaking change.
ACKs for top commit:
apoelstra:
ACK e47836fb1e0c96936096efb2dfca4e2cbc9b9e5f; successfully ran local tests
Tree-SHA512: 7edb067a7ed66af8155b86b2391ee839b0a21b3d8d36b555123b14e93f1822b89c080328464b194e4ff47643440c56fa5afee929fe58b52d5f1cf84c9b96ca83
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`
2a3e606d89 units: Move some things out of impl_u32_macro (Tobin C. Harding)
Pull request description:
Recently we added a private `impl_u32_macro`. It included a bunch of associated consts and a pair of u32 constructor/getter functions.
We overlooked the fact that the macro produces incorrect docs.
Move the offending code out of the macro and into the already existent impl block for each type.
Docs only, no other logic change.
ACKs for top commit:
apoelstra:
ACK 2a3e606d89d25ce54ff91b38b0aa29f7f733b9d9; successfully ran local tests
Tree-SHA512: ad4bdbb35bc674e9664e293841e14dc2374c8baddf3e795edb666c75860f02728e939ef5a93ede6f4c951e92c5dd5368d6a6b9662cf6d5b268f73ab5ac97e2cc
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
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
Peer to peer messages change on occasion, and we would like to add
messages as they are release from Bitcoin Core. Add an empty crate to
take the crate name.
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
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`.
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.
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.
Recently we added a private `impl_u32_macro`. It included a bunch of
associated consts and a pair of u32 constructor/getter functions.
We overlooked the fact that the macro produces incorrect docs.
Move the offending code out of the macro and into the already existent
impl block for each type.
Docs only, no other logic change.
It is not immediately obvious what a zero value compact target is.
Because of this and the fact that we are trying to release minimal code
in `primitives 1.0` its best to remove the `Default` derive.
This is an API breaking change.
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.
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
8dd24cb67b Add Arbitrary type for InputWeightPrediction (yancy)
Pull request description:
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 MB of witness data or 1 MB of non-witness data. This idea is from the discussion here https://github.com/rust-bitcoin/rust-bitcoin/issues/4547
I'd be up for a future PR that limits the constructors to no greater than 1MB or 4MB witness data, although I feel like this Arbitrary type will be less controversial.
Furthermore, I did test this locally against my application and no panics where produced either through the constructor nor auxiliary methods `total_weight` or `witness_weight`.
ACKs for top commit:
tcharding:
ACK 8dd24cb67b
apoelstra:
ACK 8dd24cb67b948e619038b387d6c3bd79252a5de1; successfully ran local tests
Tree-SHA512: ff33f1a6ced4f68c4d236e362b1d03da405a8b9701cda0405405421ca21a563fa288c8065a9309e542fec0c8bc850119bcf93a2dc5e27677c42b35b1e5e52722
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.
9fb48bc0ef fix error grater to greater array_vec.rs (Alex Pikme)
Pull request description:
Error fixed:
**One `grater` than 15 - One `greater` than 15**
ACKs for top commit:
yancyribbens:
cr ACK 9fb48bc0ef
apoelstra:
ACK 9fb48bc0efec96e332beb8e0d4c6239eb23b6da5; successfully ran local tests
Tree-SHA512: 5f2d88ed33ea30971a20b58a383f9c407feeab3e8d65b44356477b9aff0743e36f7a901099df2cd64c6168b2cf4ce92ed9c3a93c4ea596eff315522e8bf2a1dd
07c4f76052 Add comparison traits to InputWeightPrediction (yancy)
Pull request description:
* Partial Eq is added to Enable symmetric and transitive comparison.
* Eq is added to enable reflexive comparison.
ACKs for top commit:
apoelstra:
ACK 07c4f760523b7a196bf160f585c2b437dea5b532; successfully ran local tests
tcharding:
ACK 07c4f76052
Tree-SHA512: baeb957f000ac0f3be89166243b9cc7126daad06ad6688b811037ca5f5713cad1184c7135b2f4f32235457c0f53eb41304846bdd8a84e57b10a6eff0905224e8
9aa235c24d BREAKING: Change Psbt serde implementations (Daniel Roberts)
d7e9a84339 Fix Psbt preimage keys in serde test (Daniel Roberts)
62026c1e2d Don't use PSBT_GLOBAL_XPUB as an unknown key in Psbt serde test (Daniel Roberts)
Pull request description:
Implements the conclusion of #3454 by serializing Psbts using the BIP-174 binary encoding, optionally using base64 where appropriate.
The core of the problem is the old derived serde implementation by its nature can't be backwards compatible when serialized in binary formats like bincode. Fields will be added to the Psbt (my motivating case in #4440 ) and this will always break formats like bincode.
ACKs for top commit:
apoelstra:
ACK 9aa235c24d65d23de2afc21fcbd019892bf4ad2a; successfully ran local tests
tcharding:
ACK 9aa235c24d
Tree-SHA512: 4dc9dbf1a71f06769d74fada7e3d5557a3df3ee78769c66c2d8480c434baa0abd2efba555137563af58da2cc1d545813eb43b6c696b363a5777a9836bc1b7382
dc2cbc21f9 Make fee_rate test identifiers uniform (Tobin C. Harding)
2e16dbb7e5 fee_rate: Put test assertions in correct order (Tobin C. Harding)
Pull request description:
By convention we put assertions in the order `got` then `want`. This makes debugging easier.
ACKs for top commit:
apoelstra:
ACK dc2cbc21f973251e22901dbf3b4fe80e2fa25b58; successfully ran local tests
Tree-SHA512: 8844a6180c170b391dc1ea6fe225022fcd0858ad8a692af807c7668e0e055e514a0886d0dcc8a63fe23740f46ea0094291c1912035e08077974717cde976f289
4ed0b8918b Automated update to Github CI to rustc nightly-2025-05-23 (Update Nightly Rustc Bot)
Pull request description:
Automated update to Github CI workflow `rust.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action
ACKs for top commit:
tcharding:
ACK 4ed0b8918b
Tree-SHA512: 4edf4f8e4953f34c5e5c55817b9c5c39fff49e591c6dde11571f35071014f0846baad70204a3036dd9244a12ec66aa05a1a8d45be0ea5fef101dda2c205ae4ee