8000 fix sparktest segfault by aleflm · Pull Request #1575 · firoorg/firo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix sparktest segfault #1575

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

Merged
merged 1 commit into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/liblelantus/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,13 @@ class ParallelOpThreadPool {
// start missing threads
while (threads.size() < number_of_threads)
threads.emplace_back(std::bind(&ParallelOpThreadPool::ThreadProc, this));
}
}

public:
ParallelOpThreadPool(std::size_t thread_number) : number_of_threads(thread_number), shutdown(false) {}

~ParallelOpThreadPool() {
std::list<boost::thread> threadsToJoin;

{
boost::mutex::scoped_lock lock(task_queue_mutex);
shutdown = true;
task_queue_condition.notify_all();

// move the list to separate variable to wait for the shutdown process to complete
threadsToJoin.swap(threads);
}

// wait for all the threads
for (boost::thread &t: threadsToJoin)
t.join();
Shutdown();
}

// Post a task to the thread pool and return a future to wait for its completion
Expand All @@ -110,6 +97,23 @@ class ParallelOpThreadPool {
int GetNumberOfThreads() const {
return number_of_threads;
}

void Shutdown() {
std::list<boost::thread> threadsToJoin;

{
boost::mutex::scoped_lock lock(task_queue_mutex);
shutdown = true;
task_queue_condition.notify_all();

// move the list to separate variable to wait for the shutdown process to complete
threadsToJoin.swap(threads);
}

// wait for all the threads
for (boost::thread &t: threadsToJoin)
t.join();
}
};


Expand Down
4 changes: 4 additions & 0 deletions src/spark/sparkwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ CSparkWallet::~CSparkWallet() {
delete (ParallelOpThreadPool<void>*)threadPool;
}

void CSparkWallet::FinishTasks() {
((ParallelOpThreadPool<void>*)threadPool)->Shutdown();
}

void CSparkWallet::resetDiversifierFromDB(CWalletDB& walletdb) {
walletdb.readDiversifier(lastDiversifier);
}
Expand Down
2 changes: 2 additions & 0 deletions src/spark/sparkwallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class CSparkWallet {
// Returns the list of pairs of coins and metadata for that coin,
std::list<CSparkMintMeta> GetAvailableSparkCoins(const CCoinControl *coinControl = NULL) const;

void FinishTasks();

public:
// to protect coinMeta
mutable CCriticalSection cs_spark_wallet;
Expand Down
1 change: 1 addition & 0 deletions src/spark/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ CSparkState::CSparkState(
}

void CSparkState::Reset() {
ShutdownWallet();
coinGroups.clear();
latestCoinId = 0;
mintedCoins.clear();
Expand Down
1 change: 1 addition & 0 deletions src/spark/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "libspark/coin.h"
#include "chain.h"
#include "../wallet/wallet.h"
#include "../libspark/mint_transaction.h"
#include "../libspark/spend_transaction.h"
#include "primitives.h"
Expand Down
1 change: 1 addition & 0 deletions src/test/fixtures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,5 @@ CTransaction SparkTestingSetup::GenerateSparkSpend(

SparkTestingSetup::~SparkTestingSetup()
{
pwalletMain->sparkWallet->FinishTasks();
}
8 changes: 8 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8265,6 +8265,14 @@ bool CMerkleTx::AcceptToMemoryPool(const CAmount &nAbsurdFee, CValidationState &
bool CompSigmaHeight(const CSigmaEntry &a, const CSigmaEntry &b) { return a.nHeight < b.nHeight; }
bool CompSigmaID(const CSigmaEntry &a, const CSigmaEntry &b) { return a.id < b.id; }

void ShutdownWallet() {
if (pwalletMain) {
if (pwalletMain->sparkWallet) {
pwalletMain->sparkWallet->FinishTasks();
}
}
}

bool CWallet::CreateSparkMintTransactions(
const std::vector<spark::MintedCoinData>& outputs,
std::vector<std::pair<CWalletTx, CAmount>>& wtxAndFee,
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ class CAccount

bool CompSigmaHeight(const CSigmaEntry& a, const CSigmaEntry& b);
bool CompSigmaID(const CSigmaEntry& a, const CSigmaEntry& b);
void ShutdownWallet();

// Helper for producing a bunch of max-sized low-S signatures (eg 72 bytes)
// ContainerType is meant to hold pair<CWalletTx *, int>, and be iterable
Expand Down
0