Skip to content

Commit ed23d0d

Browse files
committed
[Wallet] Add some LOCK to avoid crash
1 parent 6b73598 commit ed23d0d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/wallet.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ int64_t CWalletTx::GetTxTime() const
944944

945945
int64_t CWalletTx::GetComputedTxTime() const
946946
{
947+
LOCK(cs_main);
947948
if (IsZerocoinSpend() || IsZerocoinMint()) {
948949
if (IsInMainChain())
949950
return mapBlockIndex.at(hashBlock)->GetBlockTime();
@@ -1045,6 +1046,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const
10451046

10461047
CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const
10471048
{
1049+
LOCK(cs_main);
10481050
if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0 && IsInMainChain()) {
10491051
if (fUseCache && fImmatureCreditCached)
10501052
return nImmatureCreditCached;
@@ -1258,6 +1260,7 @@ CAmount CWalletTx::GetDenominatedCredit(bool unconfirmed, bool fUseCache) const
12581260

12591261
CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool& fUseCache) const
12601262
{
1263+
LOCK(cs_main);
12611264
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) {
12621265
if (fUseCache && fImmatureWatchCreditCached)
12631266
return nImmatureWatchCreditCached;
@@ -1544,6 +1547,7 @@ bool CWalletTx::InMempool() const
15441547

15451548
void CWalletTx::RelayWalletTransaction(std::string strCommand)
15461549
{
1550+
LOCK(cs_main);
15471551
if (!IsCoinBase()) {
15481552
if (GetDepthInMainChain() == 0) {
15491553
uint256 hash = GetHash();
@@ -2078,6 +2082,7 @@ bool less_then_denom(const COutput& out1, const COutput& out2)
20782082

20792083
bool CWallet::SelectStakeCoins(std::list<std::unique_ptr<CStakeInput> >& listInputs, CAmount nTargetAmount)
20802084
{
2085+
LOCK(cs_main);
20812086
//Add PIV
20822087
vector<COutput> vCoins;
20832088
AvailableCoins(vCoins, true, NULL, false, STAKABLE_COINS);
@@ -2142,6 +2147,7 @@ bool CWallet::SelectStakeCoins(std::list<std::unique_ptr<CStakeInput> >& listInp
21422147

21432148
bool CWallet::MintableCoins()
21442149
{
2150+
LOCK(cs_main);
21452151
CAmount nBalance = GetBalance();
21462152
CAmount nZpivBalance = GetZerocoinBalance(false);
21472153

@@ -4075,6 +4081,7 @@ void CWallet::AutoZeromint()
40754081

40764082
void CWallet::AutoCombineDust()
40774083
{
4084+
LOCK2(cs_main, cs_wallet);
40784085
if (chainActive.Tip()->nTime < (GetAdjustedTime() - 300) || IsLocked()) {
40794086
return;
40804087
}
@@ -4166,6 +4173,7 @@ void CWallet::AutoCombineDust()
41664173

41674174
bool CWallet::MultiSend()
41684175
{
4176+
LOCK2(cs_main, cs_wallet);
41694177
// Stop the old blocks from sending multisends
41704178
if (chainActive.Tip()->nTime < (GetAdjustedTime() - 300) || IsLocked()) {
41714179
return false;
@@ -4373,6 +4381,7 @@ int CMerkleTx::GetDepthInMainChain(const CBlockIndex*& pindexRet, bool enableIX)
43734381

43744382
int CMerkleTx::GetBlocksToMaturity() const
43754383
{
4384+
LOCK(cs_main);
43764385
if (!(IsCoinBase() || IsCoinStake()))
43774386
return 0;
43784387
return max(0, (Params().COINBASE_MATURITY() + 1) - GetDepthInMainChain());

0 commit comments

Comments
 (0)