Browse Source

Load proving/verifying keys at startup from the public alpha parameters file.

metaverse
Sean Bowe 9 years ago
parent
commit
4f1c37980e
  1. 43
      src/init.cpp
  2. 3
      src/init.h
  3. 1
      src/test/test_bitcoin.cpp
  4. 51
      src/util.cpp
  5. 2
      src/util.h

43
src/init.cpp

@ -49,6 +49,8 @@
using namespace std;
libzerocash::ZerocashParams *pzerocashParams = NULL;
#ifdef ENABLE_WALLET
CWallet* pwalletMain = NULL;
#endif
@ -591,6 +593,44 @@ bool InitSanityCheck(void)
return true;
}
static void ZC_LoadParams()
{
struct timeval tv_start, tv_end;
float elapsed;
boost::filesystem::path pk_path = ZC_GetParamsDir() / "zc-testnet-public-alpha-proving.key";
boost::filesystem::path vk_path = ZC_GetParamsDir() / "zc-testnet-public-alpha-verification.key";
LogPrintf("Loading proving key from %s\n", pk_path.string().c_str());
gettimeofday(&tv_start, 0);
libzerocash::ZerocashParams::zerocash_pp::init_public_params();
auto pk_loaded = libzerocash::ZerocashParams::LoadProvingKeyFromFile(
pk_path.string(),
INCREMENTAL_MERKLE_TREE_DEPTH
);
gettimeofday(&tv_end, 0);
elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000);
LogPrintf("Loaded proving key in %fs seconds.\n", elapsed);
LogPrintf("Loading verification key from %s\n", vk_path.string().c_str());
gettimeofday(&tv_start, 0);
auto vk_loaded = libzerocash::ZerocashParams::LoadVerificationKeyFromFile(
vk_path.string(),
INCREMENTAL_MERKLE_TREE_DEPTH
);
gettimeofday(&tv_end, 0);
elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000);
LogPrintf("Loaded verification key in %fs seconds.\n", elapsed);
pzerocashParams = new libzerocash::ZerocashParams(
INCREMENTAL_MERKLE_TREE_DEPTH,
&pk_loaded,
&vk_loaded
);
}
/** Initialize bitcoin.
* @pre Parameters should be parsed and config file should be read.
*/
@ -1223,6 +1263,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
mempool.ReadFeeEstimates(est_filein);
fFeeEstimatesInitialized = true;
// ********************************************************* Step 7i: Load zcash params
ZC_LoadParams();
// ********************************************************* Step 8: load wallet
#ifdef ENABLE_WALLET
if (fDisableWallet) {

3
src/init.h

@ -8,6 +8,8 @@
#include <string>
#include "libzerocash/ZerocashParams.h"
class CScheduler;
class CWallet;
@ -17,6 +19,7 @@ class thread_group;
} // namespace boost
extern CWallet* pwalletMain;
extern libzerocash::ZerocashParams* pzerocashParams;
void StartShutdown();
bool ShutdownRequested();

1
src/test/test_bitcoin.cpp

@ -23,6 +23,7 @@
CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h
CWallet* pwalletMain;
libzerocash::ZerocashParams *pzerocashParams;
extern bool fPrintToConsole;
extern void noui_connect();

51
src/util.cpp

@ -430,8 +430,59 @@ boost::filesystem::path GetDefaultDataDir()
static boost::filesystem::path pathCached;
static boost::filesystem::path pathCachedNetSpecific;
static boost::filesystem::path zc_paramsPathCached;
static CCriticalSection csPathCached;
static boost::filesystem::path ZC_GetBaseParamsDir()
{
// Copied from GetDefaultDataDir and adapter for zcash params.
namespace fs = boost::filesystem;
// Windows < Vista: C:\Documents and Settings\Username\Application Data\ZcashParams
// Windows >= Vista: C:\Users\Username\AppData\Roaming\ZcashParams
// Mac: ~/Library/Application Support/ZcashParams
// Unix: ~/.zcash-params
#ifdef WIN32
// Windows
return GetSpecialFolderPath(CSIDL_APPDATA) / "ZcashParams";
#else
fs::path pathRet;
char* pszHome = getenv("HOME");
if (pszHome == NULL || strlen(pszHome) == 0)
pathRet = fs::path("/");
else
pathRet = fs::path(pszHome);
#ifdef MAC_OSX
// Mac
pathRet /= "Library/Application Support";
TryCreateDirectory(pathRet);
return pathRet / "ZcashParams";
#else
// Unix
return pathRet / ".zcash-params";
#endif
#endif
}
const boost::filesystem::path &ZC_GetParamsDir()
{
namespace fs = boost::filesystem;
LOCK(csPathCached); // Reuse the same lock as upstream.
fs::path &path = zc_paramsPathCached;
// This can be called during exceptions by LogPrintf(), so we cache the
// value so we don't have to do memory allocations after that.
if (!path.empty())
return path;
path = ZC_GetBaseParamsDir();
path /= BaseParams().DataDir();
return path;
}
const boost::filesystem::path &GetDataDir(bool fNetSpecific)
{
namespace fs = boost::filesystem;

2
src/util.h

@ -104,6 +104,8 @@ static inline bool error(const char* format)
return false;
}
const boost::filesystem::path &ZC_GetParamsDir();
void PrintExceptionContinue(const std::exception *pex, const char* pszThread);
void ParseParameters(int argc, const char*const argv[]);
void FileCommit(FILE *fileout);

Loading…
Cancel
Save