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
Basic multiwallet support #8694
Changes from 6 commits
f28eb80
9d15d55
23fb9ad
74e8738
19b3648
b124cf0
0f08575
008c360
84dcb45
b823a4c
a2a5f3f
9cbe8c8
c237bd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,13 +93,13 @@ class CWalletDBWrapper | |
friend class CDB; | ||
public: | ||
/** Create dummy DB handle */ | ||
CWalletDBWrapper(): env(nullptr) | ||
CWalletDBWrapper() : nLastSeen(0), nLastFlushed(0), nLastWalletUpdate(0), env(nullptr) | ||
{ | ||
} | ||
|
||
/** Create DB handle to real database */ | ||
CWalletDBWrapper(CDBEnv *env_in, const std::string &strFile_in): | ||
env(env_in), strFile(strFile_in) | ||
CWalletDBWrapper(CDBEnv *env_in, const std::string &strFile_in) : | ||
nLastSeen(0), nLastFlushed(0), nLastWalletUpdate(0), env(env_in), strFile(strFile_in) | ||
{ | ||
} | ||
|
||
|
@@ -119,6 +119,13 @@ class CWalletDBWrapper | |
*/ | ||
void Flush(bool shutdown); | ||
|
||
void IncrementUpdateCounter(); | ||
|
||
std::atomic<unsigned int> nUpdateCounter; | ||
unsigned int nLastSeen; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In commit "Wallet: Replace pwalletMain with a vector of wallet pointers" Should initialize these values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Note: comment no longer applies. This is now done in two CWalletDBWrapper constructors. |
||
unsigned int nLastFlushed; | ||
int64_t nLastWalletUpdate; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In commit "Wallet: Replace pwalletMain with a vector of wallet pointers" It would be nice if conversion of these values from static variables to per-wallet members happened in the previous commit ("CWalletDB: Store the update counter per wallet") instead of this one. Would make both commits easier to follow and avoid the unusual intermediate state where globals and per-wallet members are compared to each other. |
||
|
||
private: | ||
/** BerkeleyDB specific */ | ||
CDBEnv *env; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,8 @@ | |
|
||
CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest& request) | ||
{ | ||
return pwalletMain; | ||
// TODO: Some way to access secondary wallets | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I throwing an RPC error like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not always an error for there to be no wallet (eg, signrawtransaction). |
||
return vpwallets.empty() ? nullptr : vpwallets[0]; | ||
} | ||
|
||
std::string HelpRequiringPassphrase(CWallet * const pwallet) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
#include "wallet/db.h" | ||
#include "wallet/wallet.h" | ||
|
||
CWallet *pwalletMain; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why define pwalletMain here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to modify the tests to use vpwallets in most cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In commit "Wallet: Replace pwalletMain with a vector of wallet pointers": Maybe add a TODO comment for updating the tests to stop referencing pwalletMain, since this will be confusing to someone seeing this who isn't familiar with the pre-multiwallet history of the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depends on the reason why they are setting pwalletMain. Generally that is to communicate with stuff in wallet.cpp/walletdb.cpp I'd say. |
||
|
||
WalletTestingSetup::WalletTestingSetup(const std::string& chainName): | ||
TestingSetup(chainName) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
#include <boost/test/unit_test.hpp> | ||
#include <univalue.h> | ||
|
||
extern CWallet* pwalletMain; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In commit "Replace pwalletMain with a vector of wallet" This can probably be removed after the importwallet_rescan test is updated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Never mind, it's used by the receiverequests test. |
||
|
||
extern UniValue importmulti(const JSONRPCRequest& request); | ||
extern UniValue dumpwallet(const JSONRPCRequest& request); | ||
extern UniValue importwallet(const JSONRPCRequest& request); | ||
|
@@ -402,8 +404,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) | |
// after. | ||
{ | ||
CWallet wallet; | ||
CWallet *backup = ::pwalletMain; | ||
::pwalletMain = &wallet; | ||
vpwallets.insert(vpwallets.begin(), &wallet); | ||
UniValue keys; | ||
keys.setArray(); | ||
UniValue key; | ||
|
@@ -434,7 +435,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) | |
"downloading and rescanning the relevant blocks (see -reindex and -rescan " | ||
"options).\"}},{\"success\":true}]", | ||
0, oldTip->GetBlockTimeMax(), TIMESTAMP_WINDOW)); | ||
::pwalletMain = backup; | ||
vpwallets.erase(vpwallets.begin()); | ||
} | ||
} | ||
|
||
|
@@ -444,7 +445,6 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) | |
// than or equal to key birthday. | ||
BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) | ||
{ | ||
CWallet *pwalletMainBackup = ::pwalletMain; | ||
LOCK(cs_main); | ||
|
||
// Create two blocks with same timestamp to verify that importwallet rescan | ||
|
@@ -470,7 +470,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) | |
JSONRPCRequest request; | ||
request.params.setArray(); | ||
request.params.push_back("wallet.backup"); | ||
::pwalletMain = &wallet; | ||
vpwallets.insert(vpwallets.begin(), &wallet); | ||
::dumpwallet(request); | ||
} | ||
|
||
|
@@ -482,7 +482,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) | |
JSONRPCRequest request; | ||
request.params.setArray(); | ||
request.params.push_back("wallet.backup"); | ||
::pwalletMain = &wallet; | ||
vpwallets[0] = &wallet; | ||
::importwallet(request); | ||
|
||
BOOST_CHECK_EQUAL(wallet.mapWallet.size(), 3); | ||
|
@@ -495,7 +495,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) | |
} | ||
|
||
SetMockTime(0); | ||
::pwalletMain = pwalletMainBackup; | ||
vpwallets.erase(vpwallets.begin()); | ||
} | ||
|
||
// Check that GetImmatureCredit() returns a newly calculated value instead of | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
#include <boost/algorithm/string/replace.hpp> | ||
#include <boost/thread.hpp> | ||
|
||
CWallet* pwalletMain = NULL; | ||
std::vector<CWalletRef> vpwallets; | ||
/** Transaction fee set by the user */ | ||
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE); | ||
unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET; | ||
|
@@ -2871,7 +2871,7 @@ bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry) | |
|
||
bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB *pwalletdb) | ||
{ | ||
if (!pwalletdb->WriteAccountingEntry_Backend(acentry)) | ||
if (!pwalletdb->WriteAccountingEntry(++nAccountingEntryNumber, acentry)) | ||
return false; | ||
|
||
laccentries.push_back(acentry); | ||
|
@@ -3884,7 +3884,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) | |
walletInstance->ScanForWalletTransactions(pindexRescan, true); | ||
LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart); | ||
walletInstance->SetBestChain(chainActive.GetLocator()); | ||
CWalletDB::IncrementUpdateCounter(); | ||
walletInstance->dbw->IncrementUpdateCounter(); | ||
|
||
// Restore wallet transaction metadata after -zapwallettxes=1 | ||
if (GetBoolArg("-zapwallettxes", false) && GetArg("-zapwallettxes", "1") != "2") | ||
|
@@ -3926,7 +3926,6 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) | |
bool CWallet::InitLoadWallet() | ||
{ | ||
if (GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | ||
pwalletMain = NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
EDIT: Meh, not really needed, just thought it would be more coherent. |
||
LogPrintf("Wallet disabled!\n"); | ||
return true; | ||
} | ||
|
@@ -3943,7 +3942,7 @@ bool CWallet::InitLoadWallet() | |
if (!pwallet) { | ||
return false; | ||
} | ||
pwalletMain = pwallet; | ||
vpwallets.push_back(pwallet); | ||
|
||
return true; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you still need to delete each wallet here?