-
-
Notifications
You must be signed in to change notification settings - Fork 365
Reduce memory consumption of checking Spark spend transactions #1723
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
Changes from 4 commits
70c341c
53cc00c
54fbec9
b75e2d3
844dca7
8f13be0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ struct ProofCheckState { | |
| static std::map<uint256, ProofCheckState> gCheckedSparkSpendTransactions; | ||
| static CCriticalSection cs_checkedSparkSpendTransactions; | ||
|
|
||
| static ParallelOpThreadPool<bool> gCheckProofThreadPool(boost::thread::hardware_concurrency()); | ||
| static ParallelOpThreadPool<bool> gCheckProofThreadPool(std::max(boost::thread::hardware_concurrency(), 8u)); | ||
|
|
||
| static CSparkState sparkState; | ||
|
|
||
|
|
@@ -804,17 +804,23 @@ bool CheckSparkSpendTransaction( | |
| } | ||
| else if (!fStatefulSigmaCheck && !gCheckProofThreadPool.IsPoolShutdown()) { | ||
| // not an urgent check, put the proof into the thread pool for verification | ||
| auto future = gCheckProofThreadPool.PostTask([spend, cover_sets]() { | ||
| try { | ||
| return spark::SpendTransaction::verify(*spend, cover_sets); | ||
| } catch (const std::exception &) { | ||
| return false; | ||
| } | ||
| }); | ||
| auto &checkState = gCheckedSparkSpendTransactions[hashTx]; | ||
| checkState.fChecked = false; | ||
| checkState.fResult = false; | ||
| checkState.checkInProgress = std::make_shared<boost::future<bool>>(std::move(future)); | ||
| // don't post a request if there are too many tasks already | ||
| if (gCheckProofThreadPool.GetPendingTaskCount() < (std::size_t)gCheckProofThreadPool.GetNumberOfThreads()/2) { | ||
|
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. Just asking. I am not 100% sure. It wouldn't be better to have this: as atomic operation?
Contributor
Author
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. it's not that important right here, it's just an optimization, even if the number of tasks changes it won't cause any real damage |
||
| auto future = gCheckProofThreadPool.PostTask([spend, cover_sets]() mutable { | ||
| try { | ||
| bool result = spark::SpendTransaction::verify(*spend, cover_sets); | ||
| spend.reset(); | ||
| cover_sets.clear(); | ||
| return result; | ||
| } catch (const std::exception &) { | ||
| return false; | ||
| } | ||
| }); | ||
| auto &checkState = gCheckedSparkSpendTransactions[hashTx]; | ||
| checkState.fChecked = false; | ||
| checkState.fResult = false; | ||
| checkState.checkInProgress = std::make_shared<boost::future<bool>>(std::move(future)); | ||
| } | ||
| } | ||
| } | ||
| while (fRecheckNeeded); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: firoorg/firo
Length of output: 3131
Use
std::mininstead ofstd::maxto enforce the 8-thread cap.The code uses
std::max(boost::thread::hardware_concurrency(), 8u), which sets a minimum of 8 threads. On a 64-core system, this creates 64 threads, contradicting the PR goal of "constraining the ZK proof verification thread pool size" to an explicit cap of 8. The backpressure mechanism at line 808 only throttles task queueing, not thread creation. Change tostd::min(boost::thread::hardware_concurrency(), 8u)to enforce the intended maximum.🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.
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.
@psolstice I confirm Coderabbit's comment here.
std::maxis not correct here.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.