Skip to content
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

[Bug] Fix wallet data race #2923

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

using namespace std::chrono_literals;

int64_t nTimeBestReceived = 0; // Used only to inform the wallet of when we last received a block

static const uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL; // SHA256("main address relay")[0:8]

Expand Down Expand Up @@ -757,8 +756,6 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex* pindexNew, const CB
}
});
}

nTimeBestReceived = GetTime();
}

void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationState& state)
Expand Down
1 change: 0 additions & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ extern BlockMap mapBlockIndex;
extern PrevBlockMap mapPrevBlockIndex;
extern uint64_t nLastBlockTx;
extern uint64_t nLastBlockSize;
extern int64_t nTimeBestReceived;

// Best block section
extern Mutex g_best_block_mutex;
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,11 @@ void CWallet::ResendWalletTransactions(CConnman* connman)
}
}

void CWallet::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload)
{
nTimeBestReceived = GetTime();
}

/** @} */ // end of mapWallet


Expand Down
2 changes: 2 additions & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface

int64_t nNextResend;
int64_t nLastResend;
std::atomic<int64_t> nTimeBestReceived{0}; // Used only to inform the wallet of when we last received a block

/**
* Used to keep track of spent outpoints, and
Expand Down Expand Up @@ -1042,6 +1043,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
void TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) override;
void ReacceptWalletTransactions(bool fFirstLoad = false);
void ResendWalletTransactions(CConnman* connman) override;
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override;

struct Balance {
CAmount m_mine_trusted{0}; //!< Trusted, at depth=GetBalance.min_depth or more
Expand Down
Loading