-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[EXPERIMENTAL] Schnorr batch verification for blocks #29491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/29491. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible typos and grammar issues:
drahtbot_id_4_m |
454783c
to
0a5e612
Compare
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
I guess this is most interesting to test against the last 50K blocks on mainnet, i.e. since early 2023? Given the high percentage of taproot transactions. Such testing could benefit from a assume utxo snapshot, saving everyone the pain of rewinding. I can bake one, though ideally I'd like #26045 to land first. Is the current PR already using batches? It's unclear to me by glancing over Maybe add a |
Yeah, that would be great. I have to get the tracing part to work in my setup again before I can start.
Yes, the rough architecture is as as follows (sorry for not writing a better explanation above but it's still very rough and I expect it to change). So, the The 106 is an implementation detail from Everything should be conditional on the presence of a
Yeah, I have been thinking that or maybe even a compiler argument |
0a5e612
to
1825555
Compare
@Sjors maybe what confused you is that |
That clarifies a lot, and should be documented :-) |
@willcl-ark and I ran a IBD benchmark vs master for this PR: IBD from a local node to height 840000 and currently only looking at the connect_block duration. In the current draft implementation:
Used this bpftrace script to collect CSV data: #!/usr/bin/env bpftrace
usdt:./src/bitcoind:validation:block_connected
{
$height = (int32) arg1;
$tx = (uint64) arg2;
$ins = (int32) arg3;
$sigops = (int64) arg4;
$duration = (int64) arg5; // in nanoseconds
printf("%d,%ld,%d,%ld,%ld\n", $height, $tx, $ins, $sigops, $duration);
} |
From a quick skim of the changes ISTM that we always use the |
1825555
to
6f271d7
Compare
It seems in this approach the I think a better approach would be to have a thread local batch for each worker thread and the main thread, so each thread can add all schnorr sigs without locking, and then each thread can verify their batches in parallel at the end. |
6f271d7
to
cafdd14
Compare
OS is Ubuntu 24.04.2 LTS Output from
I'm running the IBD benchmark on a different machine. I'll share details when results are in. EDIT Note that Benchkit is still experimental, it loads the 840000 assumeutxo snapshot and runs hyperfine |
4ab16a0
to
4d9834e
Compare
I couldn't figure out how to test the different thread configurations for the microbench with Benchkit. Are you using Benchkit there as well or are you just setting
I am not sure how to do this completely without copy, using span is unsafe because vChecks is cleared. Using emplace_back is possible and I am using it now but in the benchmarks I didn’t see noticable improvement from this. Can you be a bit more specific what you had in mind?
I have implemented this and see a performance boost from it for the case with 15 worker threads (I didn't test all the other thread configuration yet). On my machine I now get these results (running novo (15 worker threads)
this latest state 9d460e82e1404f7cfb29613d3852bbb99e0071ad (15 worker threads)
Thank you for the continued valuable feedback, I have made you co-author of the relevant commit. A few comments on the latest code in the branch you linked to (0493ba3):
A few more comments on this latest push:
|
Sorry I didn't state that. That's what I did for the microbench. I only use Benchkit for IBD bechmarks. I'm going to review and test latest changes. |
I was thinking it might be better to move away from the collecting sigs idea if the copy operations present a significant slowdown. I'll see if I can detect any performance changes in testing.
Makes sense. I agree. We do not need to do this in core.
It seems like the major reason for performance drop was the batch-verification work being performed in the critical section. I'll try to reproduce your latest results. |
} | ||
|
||
secp256k1_xonly_pubkey pubkey_parsed; | ||
(void)secp256k1_xonly_pubkey_parse(secp256k1_context_static, &pubkey_parsed, pubkey.data()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bcd51a4: why discard the return value of secp256k1_xonly_pubkey_parse()
?
410abb205a batch: Generate speedup graphs e5df505bad batch, extrakeys: Add benchmarks 642901f57a batch: Add tests for batch_add_* APIs 6378b6bcdc batch,ecmult: Add tests for core batch APIs and strauss_batch refactor e5bbca63bf batch: Add example f818fc0e4b batch: Add batch_add_* APIs b47d8f3877 batch, ecmult: Add batch_verify and refactor strauss_batch 535a94b6d2 batch: Add create and destroy APIs 800233a2d4 batch: Initialize an experimental batch module REVERT: b9313c6e1a Merge bitcoin-core/secp256k1#1708: release cleanup: bump version after 0.7.0 REVERT: a660a4976e Merge bitcoin-core/secp256k1#1707: release: Prepare for 0.7.0 REVERT: 7ab8b0cc01 release cleanup: bump version after 0.7.0 REVERT: a3e742d947 release: Prepare for 0.7.0 REVERT: f67b0ac1a0 ci: Don't hardcode ABI version REVERT: 020ee60495 Merge bitcoin-core/secp256k1#1706: musig/tests: initialize keypair REVERT: cde4130898 musig/tests: initialize keypair REVERT: 6037833c9e Merge bitcoin-core/secp256k1#1702: changelog: update REVERT: 40b4a06520 changelog: update REVERT: 5e74086dc8 Merge bitcoin-core/secp256k1#1705: musig/test: Remove dead code REVERT: 7c3380423c Merge bitcoin-core/secp256k1#1696: build: Refactor visibility logic and add override REVERT: 8d967a602b musig/test: Remove dead code REVERT: 983711cd6d musig/tests: Refactor vectors_signverify REVERT: 73a695958a Merge bitcoin-core/secp256k1#1704: cmake: Make `secp256k1_objs` inherit interface defines from `secp256k1` REVERT: bf082221ff cmake: Make `secp256k1_objs` inherit interface defines from `secp256k1` REVERT: c82d84bb86 build: add CMake option for disabling symbol visibility attributes REVERT: ce7923874f build: Add SECP256K1_NO_API_VISIBILITY_ATTRIBUTES REVERT: e5297f6d79 build: Refactor visibility logic REVERT: cbbbf3bd6e Merge bitcoin-core/secp256k1#1699: ci: enable musig module for native macOS arm64 job REVERT: 943479a7a3 Merge bitcoin-core/secp256k1#1694: Revert "cmake: configure libsecp256k1.pc during install" REVERT: 3352f9d667 ci: enable musig module for native macOS arm64 job REVERT: ad60ef7ea7 Merge bitcoin-core/secp256k1#1689: ci: Convert `arm64` Cirrus tasks to GHA jobs REVERT: c498779096 Merge bitcoin-core/secp256k1#1687: cmake: support the use of launchers in ctest -S scripts REVERT: 44b205e9ee Revert "cmake: configure libsecp256k1.pc during install" REVERT: 0dfe387dbe cmake: support the use of launchers in ctest -S scripts REVERT: 89096c234d Merge bitcoin-core/secp256k1#1692: cmake: configure libsecp256k1.pc during install REVERT: 7106dce6fd cmake: configure libsecp256k1.pc during install REVERT: 004f57fcd8 ci: Move Valgrind build for `arm64` from Cirrus to GHA REVERT: 5fafdfc30f ci: Move `gcc-snapshot` build for `arm64` from Cirrus to GHA REVERT: e814b79a8b ci: Switch `arm64_debian` from QEMU to native `arm64` Docker image REVERT: bcf77346b9 ci: Add `arm64` architecture to `docker_cache` job REVERT: b77aae9226 ci: Rename Docker image tag to reflect architecture git-subtree-dir: src/secp256k1 git-subtree-split: 410abb205a93b5c84a00a4e9e478c852b6dc6d69
…batch-validation-updated2
… verification Co-authored-by: Eunovo <eunovo9@gmail.com>
4d9834e
to
bcbbb57
Compare
🐙 This pull request conflicts with the target branch and needs rebase. |
This is a simple draft implementation of Schnorr signature batch verification in blocks, put here for conceptual discussion, and collaborative benchmarking. Most of code added here is from the
secp256k1
implementation.The
secp256k1
code is still under review itself, please spend some time giving feedback on the API etc. if you can:TODOs
functional/feature_taproot.py
ConnectBlock()
tracing