Skip to content

Commit 06b6966

Browse files
committed
[Sapling] Load zk-snarks params.
1 parent da60be2 commit 06b6966

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/init.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
#include "validationinterface.h"
5353
#include "zpivchain.h"
5454

55+
// Sapling
56+
#include "sapling/util.h"
57+
#include <librustzcash.h>
58+
5559
#ifdef ENABLE_WALLET
5660
#include "wallet/db.h"
5761
#include "wallet/wallet.h"
@@ -752,6 +756,30 @@ bool InitSanityCheck(void)
752756
return true;
753757
}
754758

759+
static void LoadSaplingParams()
760+
{
761+
struct timeval tv_start, tv_end;
762+
float elapsed;
763+
gettimeofday(&tv_start, 0);
764+
765+
try {
766+
initZKSNARKS();
767+
} catch (std::runtime_error &e) {
768+
uiInterface.ThreadSafeMessageBox(strprintf(
769+
_("Cannot find the Sapling parameters in the following directory:\n"
770+
"%s\n"
771+
"Please run 'sapling-fetch-params' or './util/fetch-params.sh' and then restart."),
772+
ZC_GetParamsDir()),
773+
"", CClientUIInterface::MSG_ERROR);
774+
StartShutdown();
775+
return;
776+
}
777+
778+
gettimeofday(&tv_end, 0);
779+
elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000);
780+
LogPrintf("Loaded Sapling parameters in %fs seconds.\n", elapsed);
781+
}
782+
755783
bool AppInitServers()
756784
{
757785
RPCServer::OnStarted(&OnRPCStarted);
@@ -1177,6 +1205,9 @@ bool AppInit2()
11771205
CScheduler::Function serviceLoop = boost::bind(&CScheduler::serviceQueue, &scheduler);
11781206
threadGroup.create_thread(boost::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
11791207

1208+
// Initialize Sapling circuit parameters
1209+
LoadSaplingParams();
1210+
11801211
/* Start the RPC server already. It will be started in "warmup" mode
11811212
* and not really process calls already (but it will signify connections
11821213
* that the server is there and will be ready later). Warmup mode will

src/wallet/test/wallet_test_fixture.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
#include "wallet/test/wallet_test_fixture.h"
77

88
#include "rpc/server.h"
9+
#include "sapling/util.h"
910
#include "wallet/db.h"
1011
#include "wallet/wallet.h"
1112
#include "wallet/rpcwallet.h"
1213

14+
#include <librustzcash.h>
15+
1316
void clean()
1417
{
1518
delete pwalletMain;
@@ -21,6 +24,8 @@ void clean()
2124

2225
WalletTestingSetup::WalletTestingSetup(): TestingSetup()
2326
{
27+
initZKSNARKS(); // init zk-snarks lib
28+
2429
clean(); // todo: research why we have an initialized bitdb here.
2530
bitdb.MakeMock();
2631
walletRegisterRPCCommands();

0 commit comments

Comments
 (0)