Skip to content

Commit 7084840

Browse files
random-zebraFuzzbawls
authored andcommitted
[Cleanup][DB] Remove DB functions for zerocoin precomputing
Github-Pull: #1237 Rebased-From: bd3eebb
1 parent 1e93feb commit 7084840

File tree

6 files changed

+0
-153
lines changed

6 files changed

+0
-153
lines changed

src/rpc/server.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ static const CRPCCommand vRPCCommands[] =
477477
{"zerocoin", "generatemintlist", &generatemintlist, false, false, true},
478478
{"zerocoin", "searchdzpiv", &searchdzpiv, false, false, true},
479479
{"zerocoin", "dzpivstate", &dzpivstate, false, false, true},
480-
{"zerocoin", "clearspendcache", &clearspendcache, false, false, true}
481480

482481
#endif // ENABLE_WALLET
483482
};

src/rpc/server.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ extern UniValue getzpivseed(const UniValue& params, bool fHelp);
281281
extern UniValue generatemintlist(const UniValue& params, bool fHelp);
282282
extern UniValue searchdzpiv(const UniValue& params, bool fHelp);
283283
extern UniValue dzpivstate(const UniValue& params, bool fHelp);
284-
extern UniValue clearspendcache(const UniValue& params, bool fHelp);
285284
extern UniValue enableautomintaddress(const UniValue& params, bool fHelp);
286285
extern UniValue createautomintaddress(const UniValue& params, bool fHelp);
287286

src/wallet/rpcwallet.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4425,38 +4425,3 @@ UniValue spendrawzerocoin(const UniValue& params, bool fHelp)
44254425
return DoZpivSpend(mint.GetDenominationAsAmount(), false, true, vMintsSelected, address_str, isPublicSpend);
44264426
}
44274427

4428-
UniValue clearspendcache(const UniValue& params, bool fHelp)
4429-
{
4430-
if(fHelp || params.size() != 0)
4431-
throw std::runtime_error(
4432-
"clearspendcache\n"
4433-
"\nClear the pre-computed zPIV spend cache, and database.\n" +
4434-
HelpRequiringPassphrase() + "\n"
4435-
4436-
"\nExamples\n" +
4437-
HelpExampleCli("clearspendcache", "") + HelpExampleRpc("clearspendcache", ""));
4438-
4439-
EnsureWalletIsUnlocked();
4440-
4441-
CzPIVTracker* zpivTracker = pwalletMain->zpivTracker.get();
4442-
4443-
{
4444-
int nTries = 0;
4445-
while (nTries < 100) {
4446-
TRY_LOCK(zpivTracker->cs_spendcache, fLocked);
4447-
if (fLocked) {
4448-
if (zpivTracker->ClearSpendCache()) {
4449-
fClearSpendCache = true;
4450-
CWalletDB walletdb("precomputes.dat", "cr+");
4451-
walletdb.EraseAllPrecomputes();
4452-
return "Successfully Cleared the Precompute Spend Cache and Database";
4453-
}
4454-
} else {
4455-
fGlobalUnlockSpendCache = true;
4456-
nTries++;
4457-
MilliSleep(100);
4458-
}
4459-
}
4460-
}
4461-
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Spend cache not cleared!");
4462-
}

src/wallet/walletdb.cpp

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,111 +1373,6 @@ bool CWalletDB::WriteMintPoolPair(const uint256& hashMasterSeed, const uint256&
13731373
return Write(std::make_pair(std::string("mintpool"), hashPubcoin), std::make_pair(hashMasterSeed, nCount));
13741374
}
13751375

1376-
void CWalletDB::LoadPrecomputes(std::list<std::pair<uint256, CoinWitnessCacheData> >& itemList, std::map<uint256, std::list<std::pair<uint256, CoinWitnessCacheData> >::iterator>& itemMap)
1377-
{
1378-
1379-
Dbc* pcursor = GetCursor();
1380-
if (!pcursor)
1381-
throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor");
1382-
unsigned int fFlags = DB_SET_RANGE;
1383-
for (;;)
1384-
{
1385-
// Read next record
1386-
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
1387-
if (fFlags == DB_SET_RANGE)
1388-
ssKey << std::make_pair(std::string("precompute"), uint256(0));
1389-
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
1390-
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
1391-
fFlags = DB_NEXT;
1392-
if (ret == DB_NOTFOUND)
1393-
break;
1394-
else if (ret != 0)
1395-
{
1396-
pcursor->close();
1397-
throw std::runtime_error(std::string(__func__)+" : error scanning precompute DB");
1398-
}
1399-
1400-
// Unserialize
1401-
std::string strType;
1402-
ssKey >> strType;
1403-
if (strType != "precompute")
1404-
break;
1405-
1406-
uint256 hash;
1407-
ssKey >> hash;
1408-
1409-
CoinWitnessCacheData cacheData;
1410-
ssValue >> cacheData;
1411-
1412-
itemList.push_front(std::make_pair(hash, cacheData));
1413-
itemMap.insert(std::make_pair(hash, itemList.begin()));
1414-
1415-
if (itemMap.size() == PRECOMPUTE_LRU_CACHE_SIZE)
1416-
break;
1417-
}
1418-
1419-
pcursor->close();
1420-
}
1421-
1422-
void CWalletDB::LoadPrecomputes(std::set<uint256> setHashes)
1423-
{
1424-
Dbc* pcursor = GetCursor();
1425-
if (!pcursor)
1426-
throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor");
1427-
unsigned int fFlags = DB_SET_RANGE;
1428-
for (;;)
1429-
{
1430-
// Read next record
1431-
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
1432-
if (fFlags == DB_SET_RANGE)
1433-
ssKey << make_pair(std::string("precompute"), uint256(0));
1434-
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
1435-
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
1436-
fFlags = DB_NEXT;
1437-
if (ret == DB_NOTFOUND)
1438-
break;
1439-
else if (ret != 0)
1440-
{
1441-
pcursor->close();
1442-
throw std::runtime_error(std::string(__func__)+" : error scanning precompute DB");
1443-
}
1444-
1445-
// Unserialize
1446-
std::string strType;
1447-
ssKey >> strType;
1448-
if (strType != "precompute")
1449-
break;
1450-
1451-
uint256 hash;
1452-
ssKey >> hash;
1453-
1454-
setHashes.insert(hash);
1455-
}
1456-
1457-
pcursor->close();
1458-
}
1459-
1460-
void CWalletDB::EraseAllPrecomputes()
1461-
{
1462-
std::set<uint256> setHashes;
1463-
LoadPrecomputes(setHashes);
1464-
1465-
for (auto hash : setHashes)
1466-
ErasePrecompute(hash);
1467-
}
1468-
1469-
bool CWalletDB::WritePrecompute(const uint256& hash, const CoinWitnessCacheData& data)
1470-
{
1471-
return Write(std::make_pair(std::string("precompute"), hash), data);
1472-
}
1473-
bool CWalletDB::ReadPrecompute(const uint256& hash, CoinWitnessCacheData& data)
1474-
{
1475-
return Read(std::make_pair(std::string("precompute"), hash), data);
1476-
}
1477-
bool CWalletDB::ErasePrecompute(const uint256& hash)
1478-
{
1479-
return Erase(std::make_pair(std::string("precompute"), hash));
1480-
}
14811376

14821377
//! map with hashMasterSeed as the key, paired with vector of hashPubcoins and their count
14831378
std::map<uint256, std::vector<std::pair<uint256, uint32_t> > > CWalletDB::MapMintPool()

src/wallet/walletdb.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,6 @@ class CWalletDB : public CDB
188188
std::map<uint256, std::vector<std::pair<uint256, uint32_t> > > MapMintPool();
189189
bool WriteMintPoolPair(const uint256& hashMasterSeed, const uint256& hashPubcoin, const uint32_t& nCount);
190190

191-
void LoadPrecomputes(std::list<std::pair<uint256, CoinWitnessCacheData> >& itemList, std::map<uint256, std::list<std::pair<uint256, CoinWitnessCacheData> >::iterator>& itemMap);
192-
void LoadPrecomputes(std::set<uint256> setHashes);
193-
void EraseAllPrecomputes();
194-
bool WritePrecompute(const uint256& hash, const CoinWitnessCacheData& data);
195-
bool ReadPrecompute(const uint256& hash, CoinWitnessCacheData& data);
196-
bool ErasePrecompute(const uint256& hash);
197-
198191
private:
199192
CWalletDB(const CWalletDB&);
200193
void operator=(const CWalletDB&);

src/zpiv/witness.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
#include "zerocoin.h"
1212
#include "serialize.h"
1313

14-
#define PRECOMPUTE_LRU_CACHE_SIZE 1000
15-
#define PRECOMPUTE_MAX_DIRTY_CACHE_SIZE 100
16-
#define PRECOMPUTE_FLUSH_TIME 300 // 5 minutes
17-
1814
class CoinWitnessCacheData;
1915

2016
class CoinWitnessData

0 commit comments

Comments
 (0)