0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-11 15:56:58 -04:00
bitcoin-core/src/bench
Ava Chow 16b4f75d04
Merge bitcoin/bitcoin#28923: script/sign: avoid duplicated signature verification after signing (+introduce signing benchmarks)
fe92c15f0c script/sign: avoid duplicated signature verification after signing (Sebastian Falbesoner)
080089567c bench: add benchmark for `SignTransaction` (Sebastian Falbesoner)

Pull request description:

  This PR is a small performance improvement on the `SignTransaction` function, which is used mostly by the wallet (obviously) and the `signrawtransactionwithkey` RPC. The lower-level function `ProduceSignature` already calls `VerifyScript` internally as last step in order to check whether the signature data is complete:
  daa56f7f66/src/script/sign.cpp (L568-L570)

  If and only if that is the case, the `complete` field of the `SignatureData` is set to `true` accordingly and there is no need then to verify the script after again, as we already know that it would succeed.

  This leads to a rough ~20% speed-up for `SignTransaction` for single-input ECDSA or Taproot transactions, according to the newly introduced `SignTransaction{ECDSA,Taproot}` benchmarks:

  ```
  $ ./src/bench/bench_bitcoin --filter=SignTransaction.*
  ```

  without commit 18185f4f578b8795fdaa75926630a691e9c8d0d4:

  |               ns/op |                op/s |    err% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------:|:----------
  |          185,597.79 |            5,388.00 |    1.6% |      0.22 | `SignTransactionECDSA`
  |          141,323.95 |            7,075.94 |    2.1% |      0.17 | `SignTransactionSchnorr`

  with commit 18185f4f578b8795fdaa75926630a691e9c8d0d4:

  |               ns/op |                op/s |    err% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------:|:----------
  |          149,757.86 |            6,677.45 |    1.4% |      0.18 | `SignTransactionECDSA`
  |          108,284.40 |            9,234.94 |    2.0% |      0.13 | `SignTransactionSchnorr`

  Note that there are already signing benchmarks in the secp256k1 library, but `SignTransaction` does much more than just the cryptographical parts, i.e.:
  * calculate the unsigned tx's `PrecomputedTransactionData` if necessary
  * apply Solver on the prevout scriptPubKey, fetch the relevant keys from the signing provider
  * perform the actual signing operation (for ECDSA signatures, that could be more than once due to low-R grinding)
  * verify if the signatures are correct by calling `VerifyScript` (more than once currently, which is fixed by this PR)

  so it probably makes sense to also have benchmarks from that higher-level application perspective.

ACKs for top commit:
  achow101:
    ACK fe92c15f0c
  furszy:
    utACK fe92c15f0c
  glozow:
    light review ACK fe92c15f0c

Tree-SHA512: b7225ff9e8a640ca5222dea5b2a463a0f9b9de704e4330b5b9a7bce2d63a1f4620575c474a8186f4708d7d9534eab55d000393d99db79c0cfc046b35f0a4a778
2024-07-16 16:19:07 -04:00
..
data
.gitignore
addrman.cpp p2p, refactor: return std::optional<CNetAddr> in LookupHost 2023-05-26 13:41:07 -03:00
base58.cpp
bech32.cpp
bench.cpp util: Move util/string.h functions to util namespace 2024-05-16 10:16:08 -05:00
bench.h Extract util::Xor, Add key_offset option, Add bench 2023-07-12 09:59:55 +02:00
bench_bitcoin.cpp util: Move util/string.h functions to util namespace 2024-05-16 10:16:08 -05:00
bip324_ecdh.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
block_assemble.cpp tidy: modernize-use-emplace 2023-10-12 11:27:19 +02:00
ccoins_caching.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
chacha20.cpp crypto: refactor ChaCha20 classes to use Span<std::byte> interface 2023-08-17 15:26:34 -04:00
checkblock.cpp Convert some CDataStream to DataStream 2023-11-16 11:14:13 +10:00
checkblockindex.cpp bench: add benchmark for checkblockindex 2024-03-20 16:30:04 -04:00
checkqueue.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
coin_selection.cpp Fold GetSelectionWaste() into ComputeAndSetWaste() 2024-05-24 14:53:54 -04:00
crypto_hash.cpp random bench refactor: move to new bench/random.cpp 2024-07-05 09:51:26 -04:00
data.cpp
data.h
descriptors.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
disconnected_transactions.cpp Use Txid in COutpoint 2023-11-21 13:15:44 +00:00
duplicate_inputs.cpp Use Txid in COutpoint 2023-11-21 13:15:44 +00:00
ellswift.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
examples.cpp
gcs_filter.cpp
hashpadding.cpp
index_blockfilter.cpp bench: basic block filter index initial sync 2024-03-12 09:30:42 -03:00
load_external.cpp refactor: switch from CAutoFile to AutoFile 2023-11-18 03:01:41 +10:00
lockedpool.cpp clang-tidy: Add performance-inefficient-vector-operation check 2023-03-26 20:17:55 +01:00
logging.cpp test: [refactor] Pass TestOpts 2024-07-08 16:11:15 +02:00
mempool_eviction.cpp mempool_entry: add mempool entry sequence number 2023-08-03 13:42:45 +10:00
mempool_stress.cpp test: [refactor] Pass TestOpts 2024-07-08 16:11:15 +02:00
merkle_root.cpp
nanobench.cpp
nanobench.h bench: Update nanobench to 4.3.11 2023-11-14 20:22:12 +01:00
parse_hex.cpp Add benchmark for TryParseHex 2024-02-28 17:23:54 +00:00
peer_eviction.cpp
poly1305.cpp Switch all callers from poly1305_auth to Poly1305 class 2023-07-12 22:43:55 -04:00
pool.cpp pool: make sure PoolAllocator uses the correct alignment 2023-11-19 18:43:29 +01:00
prevector.cpp bench: Add benchmark for prevector usage in std::vector 2023-03-26 15:49:41 +02:00
random.cpp random: drop ad-hoc Shuffle in favor of std::shuffle 2024-07-06 09:06:36 -04:00
readblock.cpp validation, blockstorage: Separate code paths for reindex and saving new blocks 2024-05-14 14:54:27 -04:00
rollingbloom.cpp
rpc_blockchain.cpp refactor: rpc: Pass CBlockIndex by reference instead of pointer 2023-12-07 12:05:21 +01:00
rpc_mempool.cpp mempool_entry: add mempool entry sequence number 2023-08-03 13:42:45 +10:00
sign_transaction.cpp bench: add benchmark for SignTransaction 2024-05-12 18:02:37 +02:00
streams_findbyte.cpp refactor: switch from CAutoFile to AutoFile 2023-11-18 03:01:41 +10:00
strencodings.cpp
util_time.cpp refactor: Remove unused GetTimeMillis 2023-05-08 12:40:48 +02:00
verify_script.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
wallet_balance.cpp refactor: De-globalize g_signals 2024-02-15 14:37:01 +01:00
wallet_create.cpp bench: bugfix, properly release wallet before erasing directory 2024-05-17 12:49:59 -03:00
wallet_create_tx.cpp test: wallet, fix change position out of range error 2023-12-12 15:20:38 -03:00
wallet_ismine.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
wallet_loading.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
xor.cpp Extract util::Xor, Add key_offset option, Add bench 2023-07-12 09:59:55 +02:00