Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
privatesend-server.cpp
Go to the documentation of this file.
27 void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
34 LogPrint(BCLog::PRIVATESEND, "DSACCEPT -- peer=%d using obsolete version %i\n", pfrom->GetId(), pfrom->nVersion);
36 connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::REJECT, strCommand,
54 LogPrint(BCLog::PRIVATESEND, "DSACCEPT -- nDenom %d (%s) txCollateral %s", dsa.nDenom, CPrivateSend::DenominationToString(dsa.nDenom), dsa.txCollateral.ToString());
82 LogPrint(BCLog::PRIVATESEND, "DSACCEPT -- last dsq too recent, must wait: peer=%d, addr=%s\n", pfrom->GetId(), pfrom->addr.ToString());
84 LogPrint(BCLog::PRIVATESEND, "DSACCEPT -- last dsq too recent, must wait: peer=%d\n", pfrom->GetId());
107 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- peer=%d using obsolete version %i\n", pfrom->GetId(), pfrom->nVersion);
109 connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::REJECT, strCommand,
130 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- Peer %s is sending WAY too many dsq messages for a masternode with collateral %s\n", pfrom->GetLogString(), dsq.masternodeOutpoint.ToStringShort());
153 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n", nLastDsq, nDsqThreshold, mmetaman.GetDsqCount());
156 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- Masternode %s is sending too many dsq messages\n", dmn->pdmnState->addr.ToString());
161 LogPrint(BCLog::PRIVATESEND, "DSQUEUE -- new PrivateSend queue (%s) from masternode %s\n", dsq.ToString(), dmn->pdmnState->addr.ToString());
171 LogPrint(BCLog::PRIVATESEND, "DSVIN -- peer=%d using obsolete version %i\n", pfrom->GetId(), pfrom->nVersion);
173 connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::REJECT, strCommand,
206 LogPrint(BCLog::PRIVATESEND, "DSSIGNFINALTX -- peer=%d using obsolete version %i\n", pfrom->GetId(), pfrom->nVersion);
208 connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::REJECT, strCommand,
226 LogPrint(BCLog::PRIVATESEND, "DSSIGNFINALTX -- AddScriptSig() failed at %d/%d, session: %d\n", nTxInIndex, nTxInsCount, nSessionID);
230 LogPrint(BCLog::PRIVATESEND, "DSSIGNFINALTX -- AddScriptSig() %d/%d success\n", nTxInIndex, nTxInsCount);
253 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CheckPool -- entries count %lu\n", GetEntriesCount());
256 if (nState == POOL_STATE_ACCEPTING_ENTRIES && GetEntriesCount() == vecSessionCollaterals.size()) {
283 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CreateFinalTransaction -- FINALIZE TRANSACTIONS\n");
301 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CreateFinalTransaction -- finalMutableTransaction=%s", txNew.ToString());
315 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CommitFinalTransaction -- finalTransaction=%s", finalTransaction->ToString());
322 if (!lockMain || !AcceptToMemoryPool(mempool, validationState, finalTransaction, nullptr /* pfMissingInputs */, false /* bypass_limits */, maxTxFee /* nAbsurdFee */)) {
323 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CommitFinalTransaction -- AcceptToMemoryPool() error: Transaction not valid\n");
335 CPrivateSendBroadcastTx dstxNew(finalTransaction, activeMasternodeInfo.outpoint, GetAdjustedTime());
340 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CommitFinalTransaction -- TRANSMITTING DSTX\n");
352 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CommitFinalTransaction -- COMPLETED -- RESETTING\n");
364 // How does this work? Messages to Masternodes come in via NetMsgType::DSVIN, these require a valid collateral
365 // transaction for the client to be able to enter the pool. This transaction is kept by the Masternode
389 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::ChargeFees -- found uncooperative node (didn't send transaction), found offence\n");
400 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::ChargeFees -- found uncooperative node (didn't sign), found offence\n");
411 if ((int)vecOffendersCollaterals.size() >= vecSessionCollaterals.size() - 1 && GetRandInt(100) > 33) return;
420 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::ChargeFees -- found uncooperative node (didn't %s transaction), charging fees: %s",
444 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::ChargeRandomFees -- charging random fees, txCollateral=%s", txCollateral->ToString());
453 if (!AcceptToMemoryPool(mempool, validationState, txref, nullptr /* pfMissingInputs */, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
467 int nTimeout = (nState == POOL_STATE_SIGNING) ? PRIVATESEND_SIGNING_TIMEOUT : PRIVATESEND_QUEUE_TIMEOUT;
503 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s) "
538 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::IsInputScriptSigValid -- verifying scriptSig %s\n", ScriptToAsmStr(txin.scriptSig).substr(0, 24));
539 // TODO we're using amount=0 here but we should use the correct amount. This works because Dash ignores the amount while signing/verifying (only used in Bitcoin/Segwit)
540 if (!VerifyScript(txNew.vin[nTxInIndex].scriptSig, sigPubKey, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, MutableTransactionSignatureChecker(&txNew, nTxInIndex, 0))) {
541 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::IsInputScriptSigValid -- VerifyScript() failed on input %d\n", nTxInIndex);
545 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::IsInputScriptSigValid -- Failed to find matching input in pool, %s\n", txin.ToString());
549 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::IsInputScriptSigValid -- Successfully validated input and scriptSig\n");
556 bool CPrivateSendServer::AddEntry(CConnman& connman, const CPrivateSendEntry& entry, PoolMessage& nMessageIDRet)
567 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::%s -- ERROR: collateral not valid!\n", __func__);
573 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::%s -- ERROR: too many inputs! %d/%d\n", __func__, entry.vecTxDSIn.size(), PRIVATESEND_ENTRY_MAX_SIZE);
586 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::%s -- ERROR: already have this txin in entries\n", __func__);
600 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::%s -- ERROR! IsValidInOuts() failed: %s\n", __func__, CPrivateSend::GetMessageByID(nMessageIDRet));
609 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::%s -- adding entry %d of %d required\n", __func__, GetEntriesCount(), CPrivateSend::GetMaxPoolParticipants());
617 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::AddScriptSig -- scriptSig=%s\n", ScriptToAsmStr(txinNew.scriptSig).substr(0, 24));
633 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::AddScriptSig -- scriptSig=%s new\n", ScriptToAsmStr(txinNew.scriptSig).substr(0, 24));
638 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::AddScriptSig -- adding to finalMutableTransaction, scriptSig=%s\n", ScriptToAsmStr(txinNew.scriptSig).substr(0, 24));
643 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::AddScriptSig -- adding to entries, scriptSig=%s\n", ScriptToAsmStr(txinNew.scriptSig).substr(0, 24));
664 bool CPrivateSendServer::IsAcceptableDSA(const CPrivateSendAccept& dsa, PoolMessage& nMessageIDRet)
685 bool CPrivateSendServer::CreateNewSession(const CPrivateSendAccept& dsa, PoolMessage& nMessageIDRet, CConnman& connman)
692 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CreateNewSession -- incompatible mode: nState=%d\n", nState);
710 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
717 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::CreateNewSession -- new session created, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d CPrivateSend::GetMaxPoolParticipants(): %d\n",
718 nSessionID, nSessionDenom, CPrivateSend::DenominationToString(nSessionDenom), vecSessionCollaterals.size(), CPrivateSend::GetMaxPoolParticipants());
723 bool CPrivateSendServer::AddUserToExistingSession(const CPrivateSendAccept& dsa, PoolMessage& nMessageIDRet)
734 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::AddUserToExistingSession -- incompatible mode: nState=%d\n", nState);
739 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::AddUserToExistingSession -- incompatible denom %d (%s) != nSessionDenom %d (%s)\n",
740 dsa.nDenom, CPrivateSend::DenominationToString(dsa.nDenom), nSessionDenom, CPrivateSend::DenominationToString(nSessionDenom));
750 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::AddUserToExistingSession -- new user accepted, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d CPrivateSend::GetMaxPoolParticipants(): %d\n",
751 nSessionID, nSessionDenom, CPrivateSend::DenominationToString(nSessionDenom), vecSessionCollaterals.size(), CPrivateSend::GetMaxPoolParticipants());
756 // Returns true if either max size has been reached or if the mix timed out and min size was reached
763 if (CPrivateSendServer::HasTimedOut() && (int)vecSessionCollaterals.size() >= CPrivateSend::GetMinPoolParticipants()) {
775 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::%s -- nSessionID: %d nSessionDenom: %d (%s)\n",
793 void CPrivateSendServer::PushStatus(CNode* pnode, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, CConnman& connman)
797 connman.PushMessage(pnode, CNetMsgMaker(pnode->GetSendVersion()).Make(NetMsgType::DSSTATUSUPDATE, psssup));
800 void CPrivateSendServer::RelayStatus(PoolStatusUpdate nStatusUpdate, CConnman& connman, PoolMessage nMessageID)
806 bool fOk = connman.ForNode(entry.addr, [&nStatusUpdate, &nMessageID, &connman, this](CNode* pnode) {
818 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::%s -- can't continue, %llu client(s) disconnected, nSessionID: %d nSessionDenom: %d (%s)\n",
819 __func__, nDisconnected, nSessionID, nSessionDenom, CPrivateSend::DenominationToString(nSessionDenom));
838 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::%s -- nSessionID: %d nSessionDenom: %d (%s)\n",
861 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::SetState -- Can't set state to ERROR as a Masternode. \n");
865 LogPrint(BCLog::PRIVATESEND, "CPrivateSendServer::SetState -- nState: %d, nStateNew: %d\n", nState, nStateNew);
886 obj.push_back(Pair("denomination", ValueFromAmount(CPrivateSend::DenominationToAmount(nSessionDenom))));
Definition: privatesend.h:34
CTxMemPool mempool
Definition: privatesend.h:64
bool AddEntry(CConnman &connman, const CPrivateSendEntry &entry, PoolMessage &nMessageIDRet)
Add a clients entry to the pool.
Definition: privatesend-server.cpp:556
Definition: privatesend.h:49
std::string ToString(bool fUseGetnameinfo=true) const
Definition: netaddress.cpp:581
Definition: privatesend.h:50
Definition: transaction.h:369
std::vector< CPrivateSendEntry > vecEntries
Definition: privatesend.h:364
CAmount maxTxFee
Absolute maximum transaction fee (in duffs) used by wallet and mempool (rejects high fee in sendrawtr...
Definition: validation.cpp:247
void CheckTimeout(CConnman &connman)
Definition: privatesend-server.cpp:475
int64_t GetDsqThreshold(const uint256 &proTxHash, int nMnCount)
Definition: masternode-meta.cpp:63
bool AddUserToExistingSession(const CPrivateSendAccept &dsa, PoolMessage &nMessageIDRet)
Definition: privatesend-server.cpp:723
A currently in progress mixing merge and denomination information.
Definition: privatesend.h:215
static int GetMaxPoolParticipants()
Definition: privatesend.h:452
Implementation of BIP69 https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki.
Definition: transaction.h:352
Definition: privatesend.h:81
Definition: univalue.h:20
bool IsInputScriptSigValid(const CTxIn &txin)
Check to make sure a given input matches an input in the pool and its scriptSig is valid...
Definition: privatesend-server.cpp:511
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:3733
Definition: privatesend.h:39
Definition: privatesend.h:77
Definition: privatesend.h:36
Definition: privatesend.h:52
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
CMutableTransaction finalMutableTransaction
Definition: privatesend.h:371
Definition: interpreter.h:40
Definition: interpreter.h:45
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
Definition: deterministicmns.cpp:24
Definition: privatesend.h:143
Definition: privatesend.h:42
Definition: privatesend.h:53
void RelayFinalTransaction(const CTransaction &txFinal, CConnman &connman)
Relay mixing Messages.
Definition: privatesend-server.cpp:773
void Misbehaving(NodeId pnode, int howmuch, const std::string &message)
Increase a node's misbehavior score.
Definition: net_processing.cpp:1024
bool ForNode(NodeId id, std::function< bool(const CNode *pnode)> cond, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:3795
static int GetMinPoolParticipants()
Get the minimum/maximum number of participants for the pool.
Definition: privatesend.h:449
Definition: privatesend.h:68
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
Definition: core_write.cpp:86
static bool IsCollateralValid(const CTransaction &txCollateral)
If the collateral is valid given by a client.
Definition: privatesend.cpp:339
Definition: privatesend.h:45
void ChargeRandomFees(CConnman &connman)
Rarely charge fees to pay miners.
Definition: privatesend-server.cpp:438
void GetJsonInfo(UniValue &obj) const
Definition: privatesend-server.cpp:881
Definition: privatesend.h:67
Definition: privatesend.h:44
static CPrivateSendBroadcastTx GetDSTX(const uint256 &hash)
Definition: privatesend.cpp:537
Definition: util.h:142
Definition: privatesend.h:55
Definition: privatesend.h:173
bool CreateNewSession(const CPrivateSendAccept &dsa, PoolMessage &nMessageIDRet, CConnman &connman)
Definition: privatesend-server.cpp:685
std::vector< CPrivateSendQueue > vecPrivateSendQueue
Definition: privatesend.h:403
int64_t nTimeLastSuccessfulStep
Definition: privatesend.h:367
bool IsAcceptableDSA(const CPrivateSendAccept &dsa, PoolMessage &nMessageIDRet)
Is this nDenom and txCollateral acceptable?
Definition: privatesend-server.cpp:664
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:185
static void AddDSTX(const CPrivateSendBroadcastTx &dstx)
Definition: privatesend.cpp:531
void ProcessMessage(CNode *pfrom, const std::string &strCommand, CDataStream &vRecv, CConnman &connman)
Definition: privatesend-server.cpp:27
void RelayStatus(PoolStatusUpdate nStatusUpdate, CConnman &connman, PoolMessage nMessageID=MSG_NOERR)
Definition: privatesend-server.cpp:800
void CheckForCompleteQueue(CConnman &connman)
Definition: privatesend-server.cpp:495
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
Definition: interpreter.cpp:1287
bool IsSessionReady()
Do we have enough users to take entries?
Definition: privatesend-server.cpp:757
const char * REJECT
The reject message informs the receiving node that one of its previous messages has been rejected...
Definition: protocol.cpp:37
void DoMaintenance(CConnman &connman)
Definition: privatesend-server.cpp:870
bool IsSignaturesComplete()
Check that all inputs are signed. (Are all inputs signed?)
Definition: privatesend-server.cpp:653
std::string GetStateString() const
Definition: privatesend.cpp:207
void AllowMixing(const uint256 &proTxHash)
Definition: masternode-meta.cpp:74
Definition: protocol.h:409
static bool IsValidDenomination(int nDenom)
Definition: privatesend.cpp:474
Helper class to store mixing transaction (tx) information.
Definition: privatesend.h:291
void PushStatus(CNode *pnode, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, CConnman &connman)
Definition: privatesend-server.cpp:793
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, bool bypass_limits, const CAmount nAbsurdFee, bool fDryRun)
(try to) add transaction to memory pool
Definition: validation.cpp:890
void RelayCompletedTransaction(PoolMessage nMessageID, CConnman &connman)
Definition: privatesend-server.cpp:836
static const int MIN_PRIVATESEND_PEER_PROTO_VERSION
minimum peer version accepted by mixing pool
Definition: privatesend.h:28
static std::string GetMessageByID(PoolMessage nMessageID)
Definition: privatesend.cpp:479
bool IsValidInOuts(const std::vector< CTxIn > &vin, const std::vector< CTxOut > &vout, PoolMessage &nMessageIDRet, bool *fConsumeCollateralRet) const
Definition: privatesend.cpp:225
Definition: netmessagemaker.h:12
void RelayInv(CInv &inv, const int minProtoVersion=MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections=false)
Definition: net.cpp:3482
Used to keep track of current status of mixing pool.
Definition: privatesend-server.h:19
void SetState(PoolState nStateNew)
Definition: privatesend-server.cpp:856
void CommitFinalTransaction(CConnman &connman)
Definition: privatesend-server.cpp:308
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
Definition: privatesend.h:76
static CAmount DenominationToAmount(int nDenom)
Definition: privatesend.cpp:419
Definition: privatesend.h:43
Definition: privatesend.h:66
void CreateFinalTransaction(CConnman &connman)
Definition: privatesend-server.cpp:281
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:1317
CMasternodeMetaInfoPtr GetMetaInfo(const uint256 &proTxHash, bool fCreate=true)
Definition: masternode-meta.cpp:45
static std::string DenominationToString(int nDenom)
Definition: privatesend.cpp:453
Definition: privatesend.h:65
Definition: privatesend.h:54
std::vector< CTransactionRef > vecSessionCollaterals
Definition: privatesend-server.h:24
void ConsumeCollateral(CConnman &connman, const CTransactionRef &txref)
Consume collateral in cases when peer misbehaved.
Definition: privatesend-server.cpp:449
Definition: privatesend.h:48
static const size_t PRIVATESEND_ENTRY_MAX_SIZE
Definition: privatesend.h:30
void ChargeFees(CConnman &connman)
Charge fees to bad actors (Charge clients a fee if they're abusive)
Definition: privatesend-server.cpp:368
Definition: privatesend.h:35