Merge #9143: Refactor ZapWalletTxes to avoid layer violations
0165a56 Refactor ZapWalletTxes to avoid layer vialotions (Jonas Schnelli) Tree-SHA512: 51e3abbb866185817d14d685a65cb1070a7a60aa3db692670f3a5fdd328aad59afa765c5a6b13d9e8f6d219e735487f8c87998f2fb38fdd911c1fe19bea373b9
This commit is contained in:
parent
02f4661b3c
commit
bba55e262f
@ -4008,12 +4008,16 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
|
|||||||
{
|
{
|
||||||
if (!fFileBacked)
|
if (!fFileBacked)
|
||||||
return DB_LOAD_OK;
|
return DB_LOAD_OK;
|
||||||
DBErrors nZapSelectTxRet = CWalletDB(strWalletFile,"cr+").ZapSelectTx(this, vHashIn, vHashOut);
|
AssertLockHeld(cs_wallet); // mapWallet
|
||||||
|
vchDefaultKey = CPubKey();
|
||||||
|
DBErrors nZapSelectTxRet = CWalletDB(strWalletFile,"cr+").ZapSelectTx(vHashIn, vHashOut);
|
||||||
|
for (uint256 hash : vHashOut)
|
||||||
|
mapWallet.erase(hash);
|
||||||
|
|
||||||
if (nZapSelectTxRet == DB_NEED_REWRITE)
|
if (nZapSelectTxRet == DB_NEED_REWRITE)
|
||||||
{
|
{
|
||||||
if (CDB::Rewrite(strWalletFile, "\x04pool"))
|
if (CDB::Rewrite(strWalletFile, "\x04pool"))
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
|
||||||
setInternalKeyPool.clear();
|
setInternalKeyPool.clear();
|
||||||
setExternalKeyPool.clear();
|
setExternalKeyPool.clear();
|
||||||
// Note: can't top-up keypool here, because wallet is locked.
|
// Note: can't top-up keypool here, because wallet is locked.
|
||||||
@ -4035,7 +4039,8 @@ DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
|
|||||||
{
|
{
|
||||||
if (!fFileBacked)
|
if (!fFileBacked)
|
||||||
return DB_LOAD_OK;
|
return DB_LOAD_OK;
|
||||||
DBErrors nZapWalletTxRet = CWalletDB(strWalletFile,"cr+").ZapWalletTx(this, vWtx);
|
vchDefaultKey = CPubKey();
|
||||||
|
DBErrors nZapWalletTxRet = CWalletDB(strWalletFile,"cr+").ZapWalletTx(vWtx);
|
||||||
if (nZapWalletTxRet == DB_NEED_REWRITE)
|
if (nZapWalletTxRet == DB_NEED_REWRITE)
|
||||||
{
|
{
|
||||||
if (CDB::Rewrite(strWalletFile, "\x04pool"))
|
if (CDB::Rewrite(strWalletFile, "\x04pool"))
|
||||||
|
@ -690,20 +690,17 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx)
|
DBErrors CWalletDB::FindWalletTx(vector<uint256>& vTxHash, vector<CWalletTx>& vWtx)
|
||||||
{
|
{
|
||||||
pwallet->vchDefaultKey = CPubKey();
|
|
||||||
bool fNoncriticalErrors = false;
|
bool fNoncriticalErrors = false;
|
||||||
DBErrors result = DB_LOAD_OK;
|
DBErrors result = DB_LOAD_OK;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LOCK(pwallet->cs_wallet);
|
|
||||||
int nMinVersion = 0;
|
int nMinVersion = 0;
|
||||||
if (Read((std::string)"minversion", nMinVersion))
|
if (Read((std::string)"minversion", nMinVersion))
|
||||||
{
|
{
|
||||||
if (nMinVersion > CLIENT_VERSION)
|
if (nMinVersion > CLIENT_VERSION)
|
||||||
return DB_TOO_NEW;
|
return DB_TOO_NEW;
|
||||||
pwallet->LoadMinVersion(nMinVersion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get cursor
|
// Get cursor
|
||||||
@ -756,12 +753,12 @@ DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBErrors CWalletDB::ZapSelectTx(CWallet* pwallet, std::vector<uint256>& vTxHashIn, std::vector<uint256>& vTxHashOut)
|
DBErrors CWalletDB::ZapSelectTx(vector<uint256>& vTxHashIn, vector<uint256>& vTxHashOut)
|
||||||
{
|
{
|
||||||
// build list of wallet TXs and hashes
|
// build list of wallet TXs and hashes
|
||||||
std::vector<uint256> vTxHash;
|
vector<uint256> vTxHash;
|
||||||
std::vector<CWalletTx> vWtx;
|
vector<CWalletTx> vWtx;
|
||||||
DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx);
|
DBErrors err = FindWalletTx(vTxHash, vWtx);
|
||||||
if (err != DB_LOAD_OK) {
|
if (err != DB_LOAD_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -780,7 +777,6 @@ DBErrors CWalletDB::ZapSelectTx(CWallet* pwallet, std::vector<uint256>& vTxHashI
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if ((*it) == hash) {
|
else if ((*it) == hash) {
|
||||||
pwallet->mapWallet.erase(hash);
|
|
||||||
if(!EraseTx(hash)) {
|
if(!EraseTx(hash)) {
|
||||||
LogPrint("db", "Transaction was found for deletion but returned database error: %s\n", hash.GetHex());
|
LogPrint("db", "Transaction was found for deletion but returned database error: %s\n", hash.GetHex());
|
||||||
delerror = true;
|
delerror = true;
|
||||||
@ -795,11 +791,11 @@ DBErrors CWalletDB::ZapSelectTx(CWallet* pwallet, std::vector<uint256>& vTxHashI
|
|||||||
return DB_LOAD_OK;
|
return DB_LOAD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, std::vector<CWalletTx>& vWtx)
|
DBErrors CWalletDB::ZapWalletTx(vector<CWalletTx>& vWtx)
|
||||||
{
|
{
|
||||||
// build list of wallet TXs
|
// build list of wallet TXs
|
||||||
std::vector<uint256> vTxHash;
|
vector<uint256> vTxHash;
|
||||||
DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx);
|
DBErrors err = FindWalletTx(vTxHash, vWtx);
|
||||||
if (err != DB_LOAD_OK)
|
if (err != DB_LOAD_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -128,9 +128,9 @@ public:
|
|||||||
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
|
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
|
||||||
|
|
||||||
DBErrors LoadWallet(CWallet* pwallet);
|
DBErrors LoadWallet(CWallet* pwallet);
|
||||||
DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx);
|
DBErrors FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx);
|
||||||
DBErrors ZapWalletTx(CWallet* pwallet, std::vector<CWalletTx>& vWtx);
|
DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
|
||||||
DBErrors ZapSelectTx(CWallet* pwallet, std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut);
|
DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut);
|
||||||
static bool Recover(CDBEnv& dbenv, const std::string& filename, bool fOnlyKeys);
|
static bool Recover(CDBEnv& dbenv, const std::string& filename, bool fOnlyKeys);
|
||||||
static bool Recover(CDBEnv& dbenv, const std::string& filename);
|
static bool Recover(CDBEnv& dbenv, const std::string& filename);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user