mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
refactor: drop usage of chainstate globals in coinjoin logic
This commit is contained in:
parent
ed56dbdbc4
commit
a475f5f4e5
@ -131,7 +131,7 @@ PeerMsgRet CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataS
|
||||
return {};
|
||||
}
|
||||
|
||||
void CCoinJoinClientManager::ProcessMessage(CNode& peer, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
|
||||
void CCoinJoinClientManager::ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
|
||||
{
|
||||
if (m_is_masternode) return;
|
||||
if (!CCoinJoinClientOptions::IsEnabled()) return;
|
||||
@ -150,7 +150,7 @@ void CCoinJoinClientManager::ProcessMessage(CNode& peer, CConnman& connman, cons
|
||||
AssertLockNotHeld(cs_deqsessions);
|
||||
LOCK(cs_deqsessions);
|
||||
for (auto& session : deqSessions) {
|
||||
session.ProcessMessage(peer, connman, mempool, msg_type, vRecv);
|
||||
session.ProcessMessage(peer, active_chainstate, connman, mempool, msg_type, vRecv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,7 +167,7 @@ CCoinJoinClientSession::CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletMa
|
||||
m_is_masternode{is_masternode}
|
||||
{}
|
||||
|
||||
void CCoinJoinClientSession::ProcessMessage(CNode& peer, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
|
||||
void CCoinJoinClientSession::ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
|
||||
{
|
||||
if (m_is_masternode) return;
|
||||
if (!CCoinJoinClientOptions::IsEnabled()) return;
|
||||
@ -202,7 +202,7 @@ void CCoinJoinClientSession::ProcessMessage(CNode& peer, CConnman& connman, cons
|
||||
WalletCJLogPrint(m_wallet, "DSFINALTX -- txNew %s", txNew.ToString()); /* Continued */
|
||||
|
||||
// check to see if input is spent already? (and probably not confirmed)
|
||||
SignFinalTransaction(mempool, txNew, peer, connman);
|
||||
SignFinalTransaction(peer, active_chainstate, connman, mempool, txNew);
|
||||
|
||||
} else if (msg_type == NetMsgType::DSCOMPLETE) {
|
||||
if (!mixingMasternode) return;
|
||||
@ -548,7 +548,7 @@ void CCoinJoinClientSession::ProcessPoolStateUpdate(CCoinJoinStatusUpdate psssup
|
||||
// check it to make sure it's what we want, then sign it if we agree.
|
||||
// If we refuse to sign, it's possible we'll be charged collateral
|
||||
//
|
||||
bool CCoinJoinClientSession::SignFinalTransaction(const CTxMemPool& mempool, const CTransaction& finalTransactionNew, CNode& peer, CConnman& connman)
|
||||
bool CCoinJoinClientSession::SignFinalTransaction(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, const CTransaction& finalTransactionNew)
|
||||
{
|
||||
if (!CCoinJoinClientOptions::IsEnabled()) return false;
|
||||
|
||||
@ -577,7 +577,7 @@ bool CCoinJoinClientSession::SignFinalTransaction(const CTxMemPool& mempool, con
|
||||
|
||||
// Make sure all inputs/outputs are valid
|
||||
PoolMessage nMessageID{MSG_NOERR};
|
||||
if (!IsValidInOuts(mempool, finalMutableTransaction.vin, finalMutableTransaction.vout, nMessageID, nullptr)) {
|
||||
if (!IsValidInOuts(active_chainstate, mempool, finalMutableTransaction.vin, finalMutableTransaction.vout, nMessageID, nullptr)) {
|
||||
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CoinJoin::GetMessageByID(nMessageID).translated);
|
||||
UnlockCoins();
|
||||
keyHolderStorage.ReturnAll();
|
||||
|
@ -161,7 +161,7 @@ private:
|
||||
void CompletedTransaction(PoolMessage nMessageID);
|
||||
|
||||
/// As a client, check and sign the final transaction
|
||||
bool SignFinalTransaction(const CTxMemPool& mempool, const CTransaction& finalTransactionNew, CNode& peer, CConnman& connman) EXCLUSIVE_LOCKS_REQUIRED(!cs_coinjoin);
|
||||
bool SignFinalTransaction(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, const CTransaction& finalTransactionNew) EXCLUSIVE_LOCKS_REQUIRED(!cs_coinjoin);
|
||||
|
||||
void RelayIn(const CCoinJoinEntry& entry, CConnman& connman) const;
|
||||
|
||||
@ -171,7 +171,7 @@ public:
|
||||
explicit CCoinJoinClientSession(CWallet& wallet, CoinJoinWalletManager& walletman, CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
|
||||
const CMasternodeSync& mn_sync, const std::unique_ptr<CCoinJoinClientQueueManager>& queueman, bool is_masternode);
|
||||
|
||||
void ProcessMessage(CNode& peer, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv);
|
||||
void ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv);
|
||||
|
||||
void UnlockCoins();
|
||||
|
||||
@ -268,7 +268,7 @@ public:
|
||||
m_wallet(wallet), m_walletman(walletman), m_dmnman(dmnman), m_mn_metaman(mn_metaman), m_mn_sync(mn_sync), m_queueman(queueman),
|
||||
m_is_masternode{is_masternode} {}
|
||||
|
||||
void ProcessMessage(CNode& peer, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);
|
||||
void ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);
|
||||
|
||||
bool StartMixing();
|
||||
void StopMixing();
|
||||
|
@ -217,7 +217,7 @@ std::string CCoinJoinBaseSession::GetStateString() const
|
||||
}
|
||||
}
|
||||
|
||||
bool CCoinJoinBaseSession::IsValidInOuts(const CTxMemPool& mempool, const std::vector<CTxIn>& vin, const std::vector<CTxOut>& vout, PoolMessage& nMessageIDRet, bool* fConsumeCollateralRet) const
|
||||
bool CCoinJoinBaseSession::IsValidInOuts(CChainState& active_chainstate, const CTxMemPool& mempool, const std::vector<CTxIn>& vin, const std::vector<CTxOut>& vout, PoolMessage& nMessageIDRet, bool* fConsumeCollateralRet) const
|
||||
{
|
||||
std::set<CScript> setScripPubKeys;
|
||||
nMessageIDRet = MSG_NOERR;
|
||||
@ -264,7 +264,7 @@ bool CCoinJoinBaseSession::IsValidInOuts(const CTxMemPool& mempool, const std::v
|
||||
nFees -= txout.nValue;
|
||||
}
|
||||
|
||||
CCoinsViewMemPool viewMemPool(WITH_LOCK(cs_main, return &::ChainstateActive().CoinsTip()), mempool);
|
||||
CCoinsViewMemPool viewMemPool(WITH_LOCK(cs_main, return &active_chainstate.CoinsTip()), mempool);
|
||||
|
||||
for (const auto& txin : vin) {
|
||||
LogPrint(BCLog::COINJOIN, "CCoinJoinBaseSession::%s -- txin=%s\n", __func__, txin.ToString());
|
||||
|
@ -309,7 +309,7 @@ protected:
|
||||
|
||||
virtual void SetNull() EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);
|
||||
|
||||
bool IsValidInOuts(const CTxMemPool& mempool, const std::vector<CTxIn>& vin, const std::vector<CTxOut>& vout, PoolMessage& nMessageIDRet, bool* fConsumeCollateralRet) const;
|
||||
bool IsValidInOuts(CChainState& active_chainstate, const CTxMemPool& mempool, const std::vector<CTxIn>& vin, const std::vector<CTxOut>& vout, PoolMessage& nMessageIDRet, bool* fConsumeCollateralRet) const;
|
||||
|
||||
public:
|
||||
int nSessionDenom{0}; // Users must submit a denom matching this
|
||||
|
@ -608,7 +608,7 @@ bool CCoinJoinServer::AddEntry(const CCoinJoinEntry& entry, PoolMessage& nMessag
|
||||
}
|
||||
|
||||
bool fConsumeCollateral{false};
|
||||
if (!IsValidInOuts(mempool, vin, entry.vecTxOut, nMessageIDRet, &fConsumeCollateral)) {
|
||||
if (!IsValidInOuts(m_chainstate, mempool, vin, entry.vecTxOut, nMessageIDRet, &fConsumeCollateral)) {
|
||||
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CoinJoin::GetMessageByID(nMessageIDRet).translated);
|
||||
if (fConsumeCollateral) {
|
||||
ConsumeCollateral(entry.txCollateral);
|
||||
|
@ -4897,7 +4897,7 @@ void PeerManagerImpl::ProcessMessage(
|
||||
#ifdef ENABLE_WALLET
|
||||
ProcessPeerMsgRet(m_cj_ctx->queueman->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
|
||||
for (auto& pair : m_cj_ctx->walletman->raw()) {
|
||||
pair.second->ProcessMessage(pfrom, m_connman, m_mempool, msg_type, vRecv);
|
||||
pair.second->ProcessMessage(pfrom, m_chainman.ActiveChainstate(), m_connman, m_mempool, msg_type, vRecv);
|
||||
}
|
||||
#endif // ENABLE_WALLET
|
||||
ProcessPeerMsgRet(m_cj_ctx->server->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
|
||||
|
Loading…
Reference in New Issue
Block a user