-
Notifications
You must be signed in to change notification settings - Fork 1
Add VerifyScriptBatchParallel for multi-threaded batch verification #32
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
Open
icellan
wants to merge
13
commits into
master
Choose a base branch
from
feature/verify-script-batch-parallel
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
135ae2b
Add VerifyScriptBatchParallel for multi-threaded batch script verific…
icellan 1b60155
Add purego FFI alternative to CGO for calling C library from Go
icellan a211039
Add parallel batch verification benchmark and .gitignore
icellan c4c9370
Add fixed thread pool and architecture-specific optimizations
icellan df3749a
Fix duplicate symbol errors in shared library build on Linux
icellan 9bb2503
Fix CI: shared library install path and checkout ref
icellan 1c12977
Fix CI: checkout ref and secp256k1 purego size_t mapping
icellan bab65e6
CI: clear GOFLAGS for purego test, add debug output, make non-blocking
icellan 1d7a7b3
Add prebuilt purego shared libraries for all platforms
icellan 5115616
[bot] [GoBDKUpdate] Update gobdk static libraries changes
github-actions[bot] ae2d6bc
Rebuild static and shared libraries with VerifyScriptBatchParallel
icellan 2de8b2a
add benchmark using goroutine and batching
ctnguyen 95f9c0d
Rename purego build tag to bdk_purego and rebuild libraries
icellan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # IDE | ||
| .idea/ | ||
|
|
||
| # CMake build output | ||
| build/ | ||
| build-*/ | ||
|
|
||
| # Shared libraries for purego are committed (same as static .a files in bdkcgo/) | ||
| # Only ignore intermediate build artifacts, not the final libs | ||
| # module/gobdk/bdkpurego/lib/ -- tracked, not ignored | ||
|
|
||
| # Go vendor directory (test module) | ||
| test/golang/vendor/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #ifndef __THREAD_POOL_HPP__ | ||
| #define __THREAD_POOL_HPP__ | ||
|
|
||
| #include <condition_variable> | ||
| #include <functional> | ||
| #include <future> | ||
| #include <mutex> | ||
| #include <queue> | ||
| #include <thread> | ||
| #include <vector> | ||
|
|
||
| namespace bsv | ||
| { | ||
|
|
||
| class ThreadPool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying hard to make the bdk core not depending to thread. The reason was to plan for wasm build, that don't like threading. Threading implementation would be in client code, i.e module level (go module, py module ...), or at higher level (client code) |
||
| public: | ||
| explicit ThreadPool(size_t numThreads) | ||
| { | ||
| workers.reserve(numThreads); | ||
| for (size_t i = 0; i < numThreads; ++i) { | ||
| workers.emplace_back([this] { | ||
| for (;;) { | ||
| std::function<void()> task; | ||
| { | ||
| std::unique_lock<std::mutex> lock(mtx); | ||
| cv.wait(lock, [this] { return stop || !tasks.empty(); }); | ||
| if (stop && tasks.empty()) return; | ||
| task = std::move(tasks.front()); | ||
| tasks.pop(); | ||
| } | ||
| task(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| ~ThreadPool() | ||
| { | ||
| { | ||
| std::lock_guard<std::mutex> lock(mtx); | ||
| stop = true; | ||
| } | ||
| cv.notify_all(); | ||
| for (auto& w : workers) { | ||
| w.join(); | ||
| } | ||
| } | ||
|
|
||
| // Non-copyable, non-movable | ||
| ThreadPool(const ThreadPool&) = delete; | ||
| ThreadPool& operator=(const ThreadPool&) = delete; | ||
|
|
||
| template<typename F> | ||
| auto submit(F&& f) -> std::future<decltype(f())> | ||
| { | ||
| using ReturnType = decltype(f()); | ||
| auto task = std::make_shared<std::packaged_task<ReturnType()>>(std::forward<F>(f)); | ||
| auto future = task->get_future(); | ||
| { | ||
| std::lock_guard<std::mutex> lock(mtx); | ||
| tasks.emplace([task]() { (*task)(); }); | ||
| } | ||
| cv.notify_one(); | ||
| return future; | ||
| } | ||
|
|
||
| size_t size() const { return workers.size(); } | ||
|
|
||
| private: | ||
| std::vector<std::thread> workers; | ||
| std::queue<std::function<void()>> tasks; | ||
| std::mutex mtx; | ||
| std::condition_variable cv; | ||
| bool stop = false; | ||
| }; | ||
|
|
||
| } // namespace bsv | ||
|
|
||
| #endif /* __THREAD_POOL_HPP__ */ | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Default result should be
SCRIPT_ERR_UNKNOWN_ERROR, i.e in case something unknown happens, the error is relevant.