Commit Graph

3588 Commits

Author SHA1 Message Date
Andrew Poelstra 5bf2117dc4
Merge rust-bitcoin/rust-bitcoin#1995: Improve segwit signature hash API
4300cf2210 Add p2wpkh and p2wsh signature hash functions (Tobin C. Harding)

Pull request description:

  The word "segwit" refers to segwit v0 and taproot but these functions are version specific. Add `v0` into the function names.

  This is similar to #1994, both based on recent post of mine to bitcoin dev mailing list.

ACKs for top commit:
  stevenroose:
    ACK 4300cf2210
  apoelstra:
    ACK 4300cf2210

Tree-SHA512: 723fc302954514da0fa57a3890b9f62e9d8d1b25289b8db00611d8bc34c5000b9e54943f57b8e94befcaf72633ac078b2ff66a1da0c5bb483cfaa584e3cb6014
2023-08-21 14:53:04 +00:00
yancy 3369257c75 Fix grammar 2023-08-21 15:51:58 +02:00
Tobin C. Harding 752adff9d1
Add method calc_height
Add a private method to the `PartialMerkleTree` to calculate the height.
Enables removal of duplicate code.
2023-08-21 15:34:04 +10:00
Tobin C. Harding 46f5588646
Add unit test for calc_tree_width
Add a unit test for a `PartialMerkleTree` with node counts of 1-7
2023-08-21 15:34:04 +10:00
Andrew Poelstra 672656515e
Merge rust-bitcoin/rust-bitcoin#2001: Add txin base weight
7ec33d29eb refactor: developer doc first (yancy)
5496feb5c1 Add base weight const to TxIn (yancy)

Pull request description:

  Add a base weight const to TxIn.  I also used this const in strippedsize() and scaledsize().  As a different PR, I think strippedsize and scaledsize could return Weight instead of usize.  Also added a small commit to re-arrange commit messages.

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

Tree-SHA512: b20f95605ed664b88df0a5a178d48f15f27d90eb404c9707aef010c4504d7ffd4a3565c217710b9289f87ed2a0724fd8f7cc78a79a58547fe3ee87339c0d74c1
2023-08-18 14:28:38 +00:00
Andrew Poelstra 1b3a9d3580
Merge rust-bitcoin/rust-bitcoin#1990: Introduce the `small-hash` feature for `bitcoin_hashes`
f2c5f19557 Introduce the `small-hash` feature for `bitcoin_hashes` (Alekos Filini)

Pull request description:

  When enabled this feature swaps the hash implementation of sha512, sha256 and ripemd160 for a smaller (but also slower) one.

  On embedded processors (Cortex-M4) it can lead to up to a 52% size reduction, from around 37KiB for just the `process_block` methods of the three hash functions to 17.8KiB.

  The following numbers were collected on `aarch64-unknown-linux-gnu` with `cargo 1.72.0-nightly`.

  ## Original

  ```
  RUSTFLAGS='--cfg=bench -C opt-level=z' cargo bench
  ```

  ```
  test hash160::benches::hash160_10                 ... bench:          33 ns/iter (+/- 1) = 303 MB/s
  test hash160::benches::hash160_1k                 ... bench:       2,953 ns/iter (+/- 187) = 346 MB/s
  test hash160::benches::hash160_64k                ... bench:     188,480 ns/iter (+/- 11,595) = 347 MB/s
  test hmac::benches::hmac_sha256_10                ... bench:          33 ns/iter (+/- 2) = 303 MB/s
  test hmac::benches::hmac_sha256_1k                ... bench:       2,957 ns/iter (+/- 104) = 346 MB/s
  test hmac::benches::hmac_sha256_64k               ... bench:     192,022 ns/iter (+/- 6,407) = 341 MB/s
  test ripemd160::benches::ripemd160_10             ... bench:          25 ns/iter (+/- 1) = 400 MB/s
  test ripemd160::benches::ripemd160_1k             ... bench:       2,288 ns/iter (+/- 93) = 447 MB/s
  test ripemd160::benches::ripemd160_64k            ... bench:     146,823 ns/iter (+/- 1,102) = 446 MB/s
  test sha1::benches::sha1_10                       ... bench:          41 ns/iter (+/- 0) = 243 MB/s
  test sha1::benches::sha1_1k                       ... bench:       3,844 ns/iter (+/- 70) = 266 MB/s
  test sha1::benches::sha1_64k                      ... bench:     245,854 ns/iter (+/- 10,158) = 266 MB/s
  test sha256::benches::sha256_10                   ... bench:          35 ns/iter (+/- 0) = 285 MB/s
  test sha256::benches::sha256_1k                   ... bench:       3,063 ns/iter (+/- 15) = 334 MB/s
  test sha256::benches::sha256_64k                  ... bench:     195,729 ns/iter (+/- 2,880) = 334 MB/s
  test sha256d::benches::sha256d_10                 ... bench:          34 ns/iter (+/- 1) = 294 MB/s
  test sha256d::benches::sha256d_1k                 ... bench:       3,071 ns/iter (+/- 107) = 333 MB/s
  test sha256d::benches::sha256d_64k                ... bench:     188,614 ns/iter (+/- 8,101) = 347 MB/s
  test sha512::benches::sha512_10                   ... bench:          21 ns/iter (+/- 0) = 476 MB/s
  test sha512::benches::sha512_1k                   ... bench:       1,714 ns/iter (+/- 36) = 597 MB/s
  test sha512::benches::sha512_64k                  ... bench:     110,084 ns/iter (+/- 3,637) = 595 MB/s
  test sha512_256::benches::sha512_256_10           ... bench:          22 ns/iter (+/- 1) = 454 MB/s
  test sha512_256::benches::sha512_256_1k           ... bench:       1,822 ns/iter (+/- 70) = 562 MB/s
  test sha512_256::benches::sha512_256_64k          ... bench:     116,231 ns/iter (+/- 4,745) = 563 MB/s
  test siphash24::benches::siphash24_1ki            ... bench:       1,072 ns/iter (+/- 41) = 955 MB/s
  test siphash24::benches::siphash24_1ki_hash       ... bench:       1,102 ns/iter (+/- 42) = 929 MB/s
  test siphash24::benches::siphash24_1ki_hash_u64   ... bench:       1,064 ns/iter (+/- 41) = 962 MB/s
  test siphash24::benches::siphash24_64ki           ... bench:      69,957 ns/iter (+/- 2,712) = 936 MB/
  ```

  ```
  0000000000005872 t _ZN84_$LT$bitcoin_hashes..ripemd160..HashEngine$u20$as$u20$bitcoin_hashes..HashEngine$GT$5input17hc4800746a9da7ff4E
  0000000000007956 t _ZN81_$LT$bitcoin_hashes..sha256..HashEngine$u20$as$u20$bitcoin_hashes..HashEngine$GT$5input17hf49345f65130ce9bE
  0000000000008024 t _ZN14bitcoin_hashes6sha2568Midstate10const_hash17h57317bc8012004b4E.llvm.441255102889972912
  0000000000010528 t _ZN81_$LT$bitcoin_hashes..sha512..HashEngine$u20$as$u20$bitcoin_hashes..HashEngine$GT$5input17h9bc868d4392bd9acE
  ```

  Total size: 32380 bytes

  ## With `small-hash` enabled

  ```
  RUSTFLAGS='--cfg=bench -C opt-level=z' cargo bench --features small-hash
  ```

  ```
  test hash160::benches::hash160_10                 ... bench:          52 ns/iter (+/- 3) = 192 MB/s
  test hash160::benches::hash160_1k                 ... bench:       4,817 ns/iter (+/- 286) = 212 MB/s
  test hash160::benches::hash160_64k                ... bench:     319,572 ns/iter (+/- 11,031) = 205 MB/s
  test hmac::benches::hmac_sha256_10                ... bench:          54 ns/iter (+/- 2) = 185 MB/s
  test hmac::benches::hmac_sha256_1k                ... bench:       4,846 ns/iter (+/- 204) = 211 MB/s
  test hmac::benches::hmac_sha256_64k               ... bench:     319,114 ns/iter (+/- 4,451) = 205 MB/s
  test ripemd160::benches::ripemd160_10             ... bench:          27 ns/iter (+/- 0) = 370 MB/s
  test ripemd160::benches::ripemd160_1k             ... bench:       2,358 ns/iter (+/- 150) = 434 MB/s
  test ripemd160::benches::ripemd160_64k            ... bench:     154,573 ns/iter (+/- 3,954) = 423 MB/s
  test sha1::benches::sha1_10                       ... bench:          41 ns/iter (+/- 1) = 243 MB/s
  test sha1::benches::sha1_1k                       ... bench:       3,700 ns/iter (+/- 243) = 276 MB/s
  test sha1::benches::sha1_64k                      ... bench:     231,039 ns/iter (+/- 13,989) = 283 MB/s
  test sha256::benches::sha256_10                   ... bench:          51 ns/iter (+/- 3) = 196 MB/s
  test sha256::benches::sha256_1k                   ... bench:       4,823 ns/iter (+/- 182) = 212 MB/s
  test sha256::benches::sha256_64k                  ... bench:     299,960 ns/iter (+/- 17,545) = 218 MB/s
  test sha256d::benches::sha256d_10                 ... bench:          52 ns/iter (+/- 2) = 192 MB/s
  test sha256d::benches::sha256d_1k                 ... bench:       4,827 ns/iter (+/- 323) = 212 MB/s
  test sha256d::benches::sha256d_64k                ... bench:     302,844 ns/iter (+/- 15,796) = 216 MB/s
  test sha512::benches::sha512_10                   ... bench:          34 ns/iter (+/- 1) = 294 MB/s
  test sha512::benches::sha512_1k                   ... bench:       3,002 ns/iter (+/- 123) = 341 MB/s
  test sha512::benches::sha512_64k                  ... bench:     189,767 ns/iter (+/- 10,396) = 345 MB/s
  test sha512_256::benches::sha512_256_10           ... bench:          34 ns/iter (+/- 1) = 294 MB/s
  test sha512_256::benches::sha512_256_1k           ... bench:       2,996 ns/iter (+/- 198) = 341 MB/s
  test sha512_256::benches::sha512_256_64k          ... bench:     192,024 ns/iter (+/- 8,181) = 341 MB/s
  test siphash24::benches::siphash24_1ki            ... bench:       1,081 ns/iter (+/- 65) = 947 MB/s
  test siphash24::benches::siphash24_1ki_hash       ... bench:       1,083 ns/iter (+/- 63) = 945 MB/s
  test siphash24::benches::siphash24_1ki_hash_u64   ... bench:       1,084 ns/iter (+/- 63) = 944 MB/s
  test siphash24::benches::siphash24_64ki           ... bench:      67,237 ns/iter (+/- 4,185) = 974 MB/s
  ```

  ```
  0000000000005384 t _ZN81_$LT$bitcoin_hashes..sha256..HashEngine$u20$as$u20$bitcoin_hashes..HashEngine$GT$5input17hae341658cf9b880bE
  0000000000005608 t _ZN14bitcoin_hashes9ripemd16010HashEngine13process_block17h3276b13f1e9feef8E.llvm.13618235596061801146
  0000000000005616 t _ZN14bitcoin_hashes6sha2568Midstate10const_hash17h3e6fbef64c15ee00E.llvm.7326223909590351031
  0000000000005944 t _ZN81_$LT$bitcoin_hashes..sha512..HashEngine$u20$as$u20$bitcoin_hashes..HashEngine$GT$5input17h321a237bfbe5c0bbE
  ```

  Total size: 22552 bytes

  ## Conclusion

  On `aarch64` there's overall a ~30% improvement in size, although ripemd160 doesn't really shrink that much (and its performance also aren't impacted much with only a 6% slowdown). sha512 and sha256 instead are almost 40% slower with `small-hash` enabled.

  I don't have performance numbers for other architectures, but in terms of size there was an even larger improvements on `thumbv7em-none-eabihf`, with a 52% size reduction overall:

  ```
     Size          Crate Name
  25.3KiB bitcoin_hashes <bitcoin_hashes[fe467ef2aa3a1470]::sha512::HashEngine as bitcoin_hashes[fe467ef2aa3a1470]::HashEngine>::input
   6.9KiB bitcoin_hashes <bitcoin_hashes[fe467ef2aa3a1470]::sha256::HashEngine as bitcoin_hashes[fe467ef2aa3a1470]::HashEngine>::input
   4.8KiB bitcoin_hashes <bitcoin_hashes[fe467ef2aa3a1470]::ripemd160::HashEngine as bitcoin_hashes[fe467ef2aa3a1470]::HashEngine>::input
  ```

  vs

  ```
    Size          Crate Name
  9.5KiB bitcoin_hashes <bitcoin_hashes[974bb476ef905797]::sha512::HashEngine as bitcoin_hashes[974bb476ef905797]::HashEngine>::input
  4.5KiB bitcoin_hashes <bitcoin_hashes[974bb476ef905797]::ripemd160::HashEngine>::process_block
  3.8KiB bitcoin_hashes <bitcoin_hashes[974bb476ef905797]::sha256::HashEngine as bitcoin_hashes[974bb476ef905797]::HashEngine>::input
  ```

  I'm assuming this is because on more limited architectures the compiler needs to use more instructions to move data in and out of registers (especially for sha512 which ideally would benefit from 64-bit registers), so reusing the code by moving it into functions saves a lot of those instructions.

  Also note that the `const_hash` method on `sha256` causes the compiler to emit two independent implementations. I haven't looked into the code yet, maybe there's a way to merge them so that the non-const `process_block` calls into the const fn.

  -----

  Note: commits are unverified right now because I don't have the keys available, I will sign them after addressing the review comments.

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

Tree-SHA512: 1d5eb56324c458660e2571e8cf59895dc31dae9c5427c7ed36f8a0e81ca2e9a0f39026f56b6803df03635cc8b66aee3bf5182d51ab8972d169d56bcfec33771c
2023-08-17 16:34:10 +00:00
Andrew Poelstra af85528428
Merge rust-bitcoin/rust-bitcoin#1962: Add simd sha256 intrinsics for x86 machines
546c0122d7 Add simd sha256 intrinsics for x86 machines (sanket1729)

Pull request description:

  This is my first time dabbling into architecture specific code and simd. The algorithm is a word to word translation of the C code from  4899efc81d/sha256-x86.c .

  Some benchmarks:

  With simd
  ```
  test sha256::benches::sha256_10                   ... bench:          11 ns/iter (+/- 0) = 909 MB/s
  test sha256::benches::sha256_1k                   ... bench:         712 ns/iter (+/- 2) = 1438 MB/s
  test sha256::benches::sha256_64k                  ... bench:      45,597 ns/iter (+/- 189) = 1437 MB/s
  ```
  Without simd
  ```
  test sha256::benches::sha256_10                   ... bench:          47 ns/iter (+/- 0) = 212 MB/s
  test sha256::benches::sha256_1k                   ... bench:       4,243 ns/iter (+/- 17) = 241 MB/s
  test sha256::benches::sha256_64k                  ... bench:     271,263 ns/iter (+/- 1,610) = 241 MB/s
  ```

ACKs for top commit:
  apoelstra:
    ACK 546c0122d7
  tcharding:
    ACK 546c0122d7

Tree-SHA512: 7167c900b77e63cf38135a3960cf9ac2615f73b2ef7020a12b5cc3f4c047910063ba9045217b9ecfa70f7de1eb0f02f2674f291bd023a853bad2b9162fae831e
2023-08-17 16:22:46 +00:00
yancy 7ec33d29eb refactor: developer doc first 2023-08-17 10:37:12 +02:00
yancy 5496feb5c1 Add base weight const to TxIn 2023-08-17 10:37:02 +02:00
Tobin C. Harding 84614d9997
Unit test debug print of witness with empty instruction
We recently fixed a bug that causes a panic if a `Witness` contains an
empty instruction. Add a unit test to verify it.
2023-08-17 09:36:11 +10:00
Tobin C. Harding e96be5ee6e
Fix Witness debug display bug
Currently if the witness has zero elements or any of the individual
witnesses is empty we panic. Panic is caused by subtracting 1 from a
zero length.

Check the length is non-zero before subtracting 1, print `[]` if empty.
2023-08-17 09:34:46 +10:00
Alekos Filini f2c5f19557
Introduce the `small-hash` feature for `bitcoin_hashes`
When enabled this feature swaps the hash implementation of sha512,
sha256 and ripemd160 for a smaller (but also slower) one.

On embedded processors (Cortex-M4) it can lead to up to a 52% size
reduction, from around 37KiB for just the `process_block` methods of the
three hash functions to 17.8KiB.
2023-08-16 14:19:17 +02:00
Tobin C. Harding 7bbdd9b2af
Export all hash types
During the 0.30.0 release we removed the re-exports of hash types. This
upset some folk and since the aim of our re-exports is not exactly clean
as well as the fact that the public API surface is not yet fixed just
re-export all the hash types at the crate root again.

This is 1792 but does not use a wildcard and also grabs the other
hashes that we recently moved.
2023-08-15 14:53:27 +10:00
Tobin C. Harding 4300cf2210
Add p2wpkh and p2wsh signature hash functions
The word "segwit" refers to segwit v0 and taproot but currently we have
`segwit_signature_hash` that is version specific (segwit v0).

- Rename `segwit_encode_signing_data_to` to
  `segwit_v0_encode_signing_data_to`
- Add `p2wpkh_signature_hash` and `p2wsh_signature_hash` functions

We keep the single encode function because the error handling is better
that way.

While we are at it test the bip-143 test vectors against all the
sighash types of wrapped p2wsh.
2023-08-15 11:54:08 +10:00
Andrew Poelstra 29af523beb
Merge rust-bitcoin/rust-bitcoin#1992: Update docs and format test file
02890d3fba Use spaces instead of tabs (yancy)
a640f0f034 Refer to the location where the deps are pinned (yancy)

Pull request description:

  A rollup of two simple commits.  1) add a line to point developers to the CI test where the deps are tested and 2) replace tabs with spaces (spaces are used everywhere else) in `contrib/test.sh`.

ACKs for top commit:
  apoelstra:
    ACK 02890d3fba
  tcharding:
    ACK 02890d3fba

Tree-SHA512: 29b02e6d91a169429fe931a97ff7f86ac99016c6356f85d887a84141b3eec57527f85a43aeb3905a4acc73730e33a505c265b6a22ffbca1b102b63adf8599e4f
2023-08-14 19:13:03 +00:00
Andrew Poelstra c276cea66d
Merge rust-bitcoin/rust-bitcoin#1744: Expose XOnlyPublicKey in crate root
1db0b21b84 Expose XonlyPublicKey and TapSighashType in crate root (sanket1729)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK 1db0b21b84
  apoelstra:
    ACK 1db0b21b84

Tree-SHA512: c997024e046139d5aa89e16793e582dce6cfe8a06867aa11769c15f39f15159b6207227cd103b72dbb9e9dde7ad4451bfcc32bc04d74143bd2c8344f1ec488d1
2023-08-14 14:56:38 +00:00
sanket1729 1db0b21b84
Expose XonlyPublicKey and TapSighashType in crate root 2023-08-12 16:28:35 -07:00
yancy 02890d3fba Use spaces instead of tabs 2023-08-12 17:34:08 +02:00
yancy a640f0f034 Refer to the location where the deps are pinned 2023-08-12 17:26:58 +02:00
Andrew Poelstra 19bb55f77e
Merge rust-bitcoin/rust-bitcoin#1991: Eliminate a heap allocation from PartialMerkleTree encoding & decoding
fa10668a35 Eliminate a heap allocation from PartialMerkleTree encoding & decoding (Steven Roose)

Pull request description:

  Just came across this and felt like doing this.

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

Tree-SHA512: 7167c63077851c4c461b33292948d9b09fe21eb45d52ed278ecf884ce15bc8b21c14040fa1eb5f50bfe51c5cde10abc133d0c59be502de139408c0d107ffa7eb
2023-08-11 22:23:02 +00:00
Steven Roose fa10668a35
Eliminate a heap allocation from PartialMerkleTree encoding & decoding
Just came across this and felt like doing this.
2023-08-11 20:51:55 +01:00
Andrew Poelstra f1b3e69f20
Merge rust-bitcoin/rust-bitcoin#1955: Rename `opcodes::All` to `Opcode`
63d0fa0164 Rename All to Opcode (Tobin C. Harding)
881d1b1a9d Move opcode aliases to the all module (Tobin C. Harding)
f3e8dbc392 Remove floating code comment (Tobin C. Harding)
dfd9384d14 opcodes: Fix whitespace (Tobin C. Harding)

Pull request description:

  I may be missing something about the `All` type but it seems it can be re-named to `Opcode` with no loss of clarity.

  The first few patches do some other clean ups, the last patch is the meat and potatoes.

ACKs for top commit:
  apoelstra:
    ACK 63d0fa0164

Tree-SHA512: c1b8be9e0c090d015c2bbfcb7ed6abe998ccada5a1eb0f6966c2a7dc462f8bbc45e6b99bf1387c736d2fca21a993a2c7fd5844c18b97a2e37ec43da517566ab1
2023-08-11 19:07:22 +00:00
Andrew Poelstra e2deeddd50
Merge rust-bitcoin/rust-bitcoin#1982: Add CI test for pinned versions using 1.48
894aa130b6 Add CI test for pinned versions using MSRV (yancy)

Pull request description:

  Add a test for pinned version with current MSRV.  I'm not sure how to test this in CI before opening this PR (will probably fail).

ACKs for top commit:
  apoelstra:
    ACK 894aa130b6
  tcharding:
    ACK 894aa130b6

Tree-SHA512: ab6a68628d486f8a3aa47ad6921fd90a60df62f99f3bf017d4aac092510b226b3acb8d1ee3b80e9884006bfc746f4ec0d7f150df104ec30a2e0da67886ebd3cd
2023-08-11 13:50:11 +00:00
yancy 894aa130b6 Add CI test for pinned versions using MSRV 2023-08-10 22:01:06 +02:00
Andrew Poelstra b60c19261c
Merge rust-bitcoin/rust-bitcoin#1977: Update what deps to pin
443a4c5869 Remove pins from test script (yancy)
a0c5c1282a Update what deps to pin (yancy)

Pull request description:

  Update the deps to pin so that they match contrib/test.sh: https://github.com/rust-bitcoin/rust-bitcoin/blob/master/bitcoin/contrib/test.sh#L27

ACKs for top commit:
  apoelstra:
    ACK 443a4c5869
  tcharding:
    ACK 443a4c5869

Tree-SHA512: 84b10f1020328f1609c572d67aafa54203a9b84ecfb57ce217ede2b7d735495e9699eeb4a48f09c291922b7218bf6a359dbe6791bb915e7eefd1031409334aff
2023-08-10 14:52:30 +00:00
yancy 443a4c5869 Remove pins from test script 2023-08-09 12:48:26 +02:00
yancy a0c5c1282a Update what deps to pin 2023-08-09 12:48:22 +02:00
Tobin C. Harding 29a4f9b114
Wrap the bitcoinconsensus error
Currently the `bitcoinconsensus` error is part of the public API. This
hinders maintainability because changes to the verison of
`bitcoinconsensus` force a re-release in `rust-bitcoin`. This is
an unnecessary maintenance burden, we can wrap the error instead.
2023-08-08 10:21:05 +10:00
Tobin C. Harding 63d0fa0164
Rename All to Opcode
The `opcodes::All` type can seemingly be re-named to `Opcode` with no
loss of clarity - unless I'm missing something.
2023-08-07 17:08:11 +10:00
Tobin C. Harding 881d1b1a9d
Move opcode aliases to the all module
The opcode aliases are just that, aliases to opcodes so they can live in
the `all` module along with the other opcodes.
2023-08-07 17:07:20 +10:00
Tobin C. Harding f3e8dbc392
Remove floating code comment
This code comment is not commenting anything, remove it.
2023-08-07 17:07:20 +10:00
Tobin C. Harding dfd9384d14
opcodes: Fix whitespace
Fix indentation of macro code and remove unnecessary line of whitespace.
2023-08-07 17:07:20 +10:00
Andrew Poelstra caf53d755d
Merge rust-bitcoin/rust-bitcoin#1968: Add max standard tx weight constant to transaction
2e3006a729 Add max standard tx weight constant to transaction (yancy)

Pull request description:

  Add a constant for the max transaction weight.  Similar to [max block weight](1b009b809b/bitcoin/src/blockdata/weight.rs (L35)).  This value is pulled from core  [here](44b05bf3fe/src/policy/policy.h (L27))

ACKs for top commit:
  apoelstra:
    ACK 2e3006a729
  sanket1729:
    ACK 2e3006a729

Tree-SHA512: 1583695f43387538f948be85ded7ff9a4bf9778169acb958debcbe1572a6dc8bfcd26ddfb8dbe0c030c98ab1f8a66d239a5bc663bf65ec3376a46d5f71e90894
2023-08-02 22:11:48 +00:00
Andrew Poelstra 49fa879b19
Merge rust-bitcoin/rust-bitcoin#1947: Add absolute fee rate convenience functions to `FeeRate`
9eff2f2f5e fee_rate: Add public absolute weight convenience functions (Tobin C. Harding)
f00e93bdcd Fix typos in rustdoc (Tobin C. Harding)
f3412325ea weight: Make docs uniform and terse (Tobin C. Harding)

Pull request description:

  - Patch 1 is docs cleanup
  - Patch 2 adds two functions to `FeeRate`

  From the commit log of patch 2:

      Calculating the absolute fee from a fee rate can currently be achieved
      by creating a `Weight` object and using
      `FeeRate::checked_mul_by_weight`. This is kind of hard to discover, we
      can add two public convenience functions that make discovery of the
      functionality easier.

      Add two functions for calculating the absolute fee by multiplying by
      weight units (`Weight`) and virtual bytes (by first converting to weight
      units).

  This seems like an obvious thing so I'm inclined to think that Kixunil left it out for a reason. (Mentioning you here Kix so even if this merges you'll see it in notifications later on.)

ACKs for top commit:
  sanket1729:
    utACK 9eff2f2f5e
  apoelstra:
    ACK 9eff2f2f5e

Tree-SHA512: 5b3997b721b7d7225bcf0e8a4a3efb6f207393541dbbcef533135af06a4d9c95210d450bb2322fd65a727e4560b29f0b20fb96c154d019fd4e745506213abc1c
2023-08-02 16:43:28 +00:00
Riccardo Casatta ff5fa41975
Merge rust-bitcoin/rust-bitcoin#1933: Fix links in docs
154552e334 docs: Do not link to std::option::Option (Tobin C. Harding)
24843468c3 Remove rustdocs links to serde (Tobin C. Harding)

Pull request description:

  Two minor patches to fix up docs links. These were originally done as part of #1880 but are unrelated so pushing them up separately.

ACKs for top commit:
  apoelstra:
    ACK 154552e334
  RCasatta:
    utACK 154552e334

Tree-SHA512: e45e1538c66b59d63a66898896927bb6c1336fb4c8515bb9e2204c8035870ef8e4a6fd32dfc83db2938afda67feb27c48989e382410f9e7ea7a967132941c720
2023-08-02 16:37:13 +02:00
Andrew Poelstra f99459522d
Merge rust-bitcoin/rust-bitcoin#1914: Move type definitions of pubkey/script hash types
27b3c1e0e6 Improve the ScriptHash and WScriptHash types (Tobin C. Harding)
2197f1377f Improve PubkeyHash and WPubkeyHash (Tobin C. Harding)

Pull request description:

  Total re-write since review. Now this PR moves the hash type definitions out of `hash_types`. Please see https://github.com/rust-bitcoin/rust-bitcoin/issues/1909#issuecomment-1603634440 for more.

  No longer adds unit tests.

  Fix: #1909

ACKs for top commit:
  apoelstra:
    ACK 27b3c1e0e6

Tree-SHA512: 216b9bed05d1a4a4fc493262664ceb5d60f9c30685b63d6f6675d21a7bf811053320a002165487b29599c52f345057d9c92babb0fc1ccd4628671ec468c804f9
2023-08-02 13:57:39 +00:00
Andrew Poelstra c042b66931
Merge rust-bitcoin/rust-bitcoin#1957: Remove deprecated code
50ada8298f Move EncodeSigningDataResult to sighash module (Tobin C. Harding)
1b7dc51ccb Remove deprecated code (Tobin C. Harding)

Pull request description:

  We only keep deprecated code around for one release so we can now remove code deprecated in v0.30.0

  Done in preparation as we gear up for v0.31.0 release.

ACKs for top commit:
  apoelstra:
    ACK 50ada8298f
  sanket1729:
    ACK 50ada8298f

Tree-SHA512: 40769258605563e2e12a6118306655fc9a012ae1f86509fca757ca411f0cef74480b7bb7b0db147f30a7d362b8494a077d5ec04f719351661ceb5a0697a5369d
2023-08-02 13:40:50 +00:00
Andrew Poelstra 48be5372d6
Merge rust-bitcoin/rust-bitcoin#1970: Return Weight in the TxIn/TxOut weight() methods
40c37adaf3 Return Weight in the TxIn/TxOut weight() methods (Daniela Brozzoni)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK 40c37adaf3
  apoelstra:
    ACK 40c37adaf3

Tree-SHA512: 24e8962626deb016856d9b47f1c196eb2ca9923cd90b21304de7c2e0cc3d41596ad7d5373fd05f1664771f5b72b4070ca60a4845012eb5711a9fad7f672dfc42
2023-08-02 13:34:52 +00:00
Andrew Poelstra 205544b6aa
Merge rust-bitcoin/rust-bitcoin#1862: crypto: Overhaul the errors
3c0bb63423 Do trivial rustdoc improvements (Tobin C. Harding)
3225aa9556 Use defensive documentation (Tobin C. Harding)
80d5d6665a crypto: key: Move error code to the bottom of the file (Tobin C. Harding)
fe3b1e1140 Move From for Error impl (Tobin C. Harding)
5f8e0ad67e Fix docs on error type (Tobin C. Harding)
f23155aa16 Do not capitalize error messages (Tobin C. Harding)
ae07786c27 Add InvalidSighashTypeError (Tobin C. Harding)
baba0fde57 Put NonStandardSighashTypeError inside ecdsa::Error variant (Tobin C. Harding)
6c9d9d9c36 Improve error display imlps (Tobin C. Harding)
22c7aa8808 Rename non standard sighash error type (Tobin C. Harding)

Pull request description:

  EDIT: The commit hashes below are stale but the text is valid still.

  In an effort to "perfect" our error handling, overhaul the error handling in the `crypto` module.

  The aim is to do a small chunk so we can bikeshed on it then I can apply the learnings to the rest of the codebase.

  Its all pretty trivial except:

  - commit `4c180277 Put NonStandardSighashTypeError inside ecdsa::Error variant`
  - comimt `5a196535 Add InvalidSighashTypeError`
  - commit `05772ade Use defensive documentation`

  Particularly the last one might be incorrect/controversial.

  Also, please take the time to check the overall state of error code in the `crypto` module on this branch in case there is anything else we want to do.

  Thanks

ACKs for top commit:
  apoelstra:
    ACK 3c0bb63423

Tree-SHA512: 7e5f8590aec5826098d4d8d33351a41b10c42b6379ff86e5b889e73271b71921fc3ca9525baa5da53e07fa2e961e710393694e04658a8243799950b4604caf43
2023-08-02 13:18:19 +00:00
yancy 2e3006a729 Add max standard tx weight constant to transaction 2023-08-02 10:51:55 +02:00
Tobin C. Harding 27b3c1e0e6
Improve the ScriptHash and WScriptHash types
Improve the script hash types by doing:

- Define the types in the `crypto::script` module
- Put the From impls directly below the type definitions

Keep the current crate level re-export so this does not impact the
public API _if_ people are using the re-export but is still a breaking
change.
2023-08-02 11:28:14 +10:00
Tobin C. Harding 2197f1377f
Improve PubkeyHash and WPubkeyHash
Improve the pubkey hash types by doing:

- Define the types in the `crypto::key` module
- Add From<&PublicKey> impl for `PubkeyHash`

Keep the current crate level re-export so this does not impact the
public API _if_ people are using the re-export but is still a breaking
change.
2023-08-02 11:27:55 +10:00
Tobin C. Harding 9eff2f2f5e
fee_rate: Add public absolute weight convenience functions
Calculating the absolute fee from a fee rate can currently be achieved
by creating a `Weight` object and using
`FeeRate::checked_mul_by_weight`. This is kind of hard to discover, we
can add two public convenience functions that make discovery of the
functionality easier.

Add two functions for calculating the absolute fee by multiplying by
weight units (`Weight`) and virtual bytes (by first converting to weight
units).
2023-08-02 09:10:49 +10:00
Tobin C. Harding f00e93bdcd
Fix typos in rustdoc 2023-08-02 08:29:00 +10:00
Andrew Poelstra fc562e953e
Merge rust-bitcoin/rust-bitcoin#1854: Rename `network` module and move/clean up types
d4e8f49fc3 Move p2p::constants::Network to crate root (Tobin C. Harding)
0f78943ef0 Move p2p::constants::Magic to p2p module (Tobin C. Harding)
d9d5a4ed4f Move p2p::constants::ServiceFlags to p2p module (Tobin C. Harding)
99d8ae1173 Improve rustdocs on PROTOCOL_VERSION (Tobin C. Harding)
4330722d62 Move p2p::constants::PROTOCOL_VERSION to p2p module (Tobin C. Harding)
1bac1fd518 Rename the network module to p2p (Tobin C. Harding)
dac97072a5 Add BorrowMut to prelude (Tobin C. Harding)

Pull request description:

  This PR has grown.

  - Rename the `network` module to `p2p` (fix: #1855)
  - add `BorrowMut` to prelude
  - Move the `Network`, `ChainHash`, and `Magic` structs to a newly create `p2p::network` module
  - Do a few cleanups

ACKs for top commit:
  apoelstra:
    ACK d4e8f49fc3

Tree-SHA512: 7cee93d36363b8acbece6c92c6afc34bb3abe6d5801373d291db1323c934e7c384f3b5881cefb8b0d102dea53da6ed8da1bf60c324bf60d5dab3af598e0310da
2023-08-01 18:57:10 +00:00
Andrew Poelstra 1b952def81
Merge rust-bitcoin/rust-bitcoin#1945: policy: Add refactor carve out
55be538dac policy: Add refactor carve out (Tobin C. Harding)

Pull request description:

  I have managed to burn out or bore our reviewers/maintainers. Getting two acks is becoming increasingly difficult. I've pestered everyone to the limit that I feel socially comfortable doing so, and as such, am requesting a carve out to the 2-ACK before merge rule.

  The primary justification is that I feel we should have a bit more of BDFL and a bit less total consensus if we are to push forwards.

  ### Example PRs where this change would apply

  - https://github.com/rust-bitcoin/rust-bitcoin/pull/1925
  - https://github.com/rust-bitcoin/rust-bitcoin/pull/1854
  - https://github.com/rust-bitcoin/rust-bitcoin/pull/1862

ACKs for top commit:
  elichai:
    I agree this makes sense for refactors ACK 55be538dac
  apoelstra:
    ACK 55be538dac
  sanket1729:
    ACK 55be538dac. Same reasons as apoelstra. And this is only for re-factors that are not adding any new features.
  RCasatta:
    ACK 55be538dac

Tree-SHA512: a5e206252015f49245ed282a3be7a35760d16f94dc6e60f31edf589a41ef642eba52a3bd7d1375b6033f3cf0128f47beee4f03e59cad151c64eedd71ac98baac
2023-08-01 18:19:41 +00:00
Daniela Brozzoni 40c37adaf3
Return Weight in the TxIn/TxOut weight() methods 2023-08-01 16:51:41 +02:00
Tobin C. Harding d4e8f49fc3
Move p2p::constants::Network to crate root
The `Network` type is not a p2p construct, it is more general, used
throughout the codebase to define _which_ Bitcoin network we are
operating on.
2023-08-01 16:46:59 +10:00
Tobin C. Harding 0f78943ef0
Move p2p::constants::Magic to p2p module
In preparation for removing the `p2p::constants` module; move the
`p2p::constants::Magic` type to the `p2p` module.
2023-08-01 16:42:05 +10:00
Tobin C. Harding d9d5a4ed4f
Move p2p::constants::ServiceFlags to p2p module
The `ServiceFlags` type is used by the p2p layer. It can live in the
`mod.rs` file of the `p2p` module. Done in preparation for removing the
`p2p::constants` module.

This is a straight code move, the `ServiceFlags` replaces the
current re-export.
2023-08-01 16:36:12 +10:00