2017-05-05 13:26:27 +02:00
|
|
|
// Copyright (c) 2014-2017 The Dash Core developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef PRIVATESENDCLIENT_H
|
|
|
|
#define PRIVATESENDCLIENT_H
|
|
|
|
|
|
|
|
#include "masternode.h"
|
|
|
|
#include "privatesend.h"
|
|
|
|
#include "wallet/wallet.h"
|
|
|
|
|
|
|
|
class CPrivateSendClient;
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
class CConnman;
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
static const int DENOMS_COUNT_MAX = 100;
|
|
|
|
|
|
|
|
static const int DEFAULT_PRIVATESEND_ROUNDS = 2;
|
|
|
|
static const int DEFAULT_PRIVATESEND_AMOUNT = 1000;
|
|
|
|
static const int DEFAULT_PRIVATESEND_LIQUIDITY = 0;
|
|
|
|
static const bool DEFAULT_PRIVATESEND_MULTISESSION = false;
|
|
|
|
|
|
|
|
// Warn user if mixing in gui or try to create backup if mixing in daemon mode
|
|
|
|
// when we have only this many keys left
|
|
|
|
static const int PRIVATESEND_KEYS_THRESHOLD_WARNING = 100;
|
|
|
|
// Stop mixing completely, it's too dangerous to continue when we have only this many keys left
|
|
|
|
static const int PRIVATESEND_KEYS_THRESHOLD_STOP = 50;
|
|
|
|
|
|
|
|
// The main object for accessing mixing
|
|
|
|
extern CPrivateSendClient privateSendClient;
|
|
|
|
|
|
|
|
/** Used to keep track of current status of mixing pool
|
|
|
|
*/
|
2017-06-30 20:30:16 +02:00
|
|
|
class CPrivateSendClient : public CPrivateSendBase
|
2017-05-05 13:26:27 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
mutable CCriticalSection cs_darksend;
|
|
|
|
|
|
|
|
// Keep track of the used Masternodes
|
|
|
|
std::vector<CTxIn> vecMasternodesUsed;
|
|
|
|
|
|
|
|
std::vector<CAmount> vecDenominationsSkipped;
|
|
|
|
std::vector<COutPoint> vecOutPointLocked;
|
|
|
|
|
|
|
|
int nCachedLastSuccessBlock;
|
2017-09-03 15:30:58 +02:00
|
|
|
int nMinBlocksToWait; // how many blocks to wait after one successful mixing tx in non-multisession mode
|
2017-08-25 14:57:05 +02:00
|
|
|
|
|
|
|
// Keep track of current block height
|
|
|
|
int nCachedBlockHeight;
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
int nEntriesCount;
|
|
|
|
bool fLastEntryAccepted;
|
|
|
|
|
|
|
|
std::string strLastMessage;
|
|
|
|
std::string strAutoDenomResult;
|
|
|
|
|
|
|
|
CMutableTransaction txMyCollateral; // client side collateral
|
|
|
|
|
|
|
|
/// Check for process
|
|
|
|
void CheckPool();
|
|
|
|
void CompletedTransaction(PoolMessage nMessageID);
|
|
|
|
|
|
|
|
bool IsDenomSkipped(CAmount nDenomValue) {
|
|
|
|
return std::find(vecDenominationsSkipped.begin(), vecDenominationsSkipped.end(), nDenomValue) != vecDenominationsSkipped.end();
|
|
|
|
}
|
|
|
|
|
2017-09-03 15:30:58 +02:00
|
|
|
bool WaitForAnotherBlock();
|
|
|
|
|
2017-05-05 13:26:27 +02:00
|
|
|
// Make sure we have enough keys since last backup
|
|
|
|
bool CheckAutomaticBackup();
|
|
|
|
bool JoinExistingQueue(CAmount nBalanceNeedsAnonymized);
|
|
|
|
bool StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsAnonymized);
|
|
|
|
|
|
|
|
/// Create denominations
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
bool CreateDenominated(CConnman& connman);
|
|
|
|
bool CreateDenominated(const CompactTallyItem& tallyItem, bool fCreateMixingCollaterals, CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
/// Split up large inputs or make fee sized inputs
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
bool MakeCollateralAmounts(CConnman& connman);
|
|
|
|
bool MakeCollateralAmounts(const CompactTallyItem& tallyItem, bool fTryDenominated, CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
/// As a client, submit part of a future mixing transaction to a Masternode to start the process
|
|
|
|
bool SubmitDenominate();
|
|
|
|
/// step 1: prepare denominated inputs and outputs
|
|
|
|
bool PrepareDenominate(int nMinRounds, int nMaxRounds, std::string& strErrorRet, std::vector<CTxIn>& vecTxInRet, std::vector<CTxOut>& vecTxOutRet);
|
|
|
|
/// step 2: send denominated inputs and outputs prepared in step 1
|
|
|
|
bool SendDenominate(const std::vector<CTxIn>& vecTxIn, const std::vector<CTxOut>& vecTxOut);
|
|
|
|
|
|
|
|
/// Get Masternode updates about the progress of mixing
|
|
|
|
bool CheckPoolStateUpdate(PoolState nStateNew, int nEntriesCountNew, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, int nSessionIDNew=0);
|
|
|
|
// Set the 'state' value, with some logging and capturing when the state changed
|
|
|
|
void SetState(PoolState nStateNew);
|
|
|
|
|
|
|
|
/// As a client, check and sign the final transaction
|
|
|
|
bool SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* pnode);
|
|
|
|
|
|
|
|
void RelayIn(const CDarkSendEntry& entry);
|
|
|
|
|
|
|
|
void SetNull();
|
|
|
|
|
|
|
|
public:
|
|
|
|
int nPrivateSendRounds;
|
|
|
|
int nPrivateSendAmount;
|
|
|
|
int nLiquidityProvider;
|
|
|
|
bool fEnablePrivateSend;
|
|
|
|
bool fPrivateSendMultiSession;
|
|
|
|
|
|
|
|
masternode_info_t infoMixingMasternode;
|
|
|
|
int nCachedNumBlocks; //used for the overview screen
|
|
|
|
bool fCreateAutoBackups; //builtin support for automatic backups
|
|
|
|
|
|
|
|
CPrivateSendClient() :
|
|
|
|
nCachedLastSuccessBlock(0),
|
2017-09-03 15:30:58 +02:00
|
|
|
nMinBlocksToWait(1),
|
2017-05-05 13:26:27 +02:00
|
|
|
txMyCollateral(CMutableTransaction()),
|
|
|
|
nPrivateSendRounds(DEFAULT_PRIVATESEND_ROUNDS),
|
|
|
|
nPrivateSendAmount(DEFAULT_PRIVATESEND_AMOUNT),
|
|
|
|
nLiquidityProvider(DEFAULT_PRIVATESEND_LIQUIDITY),
|
|
|
|
fEnablePrivateSend(false),
|
|
|
|
fPrivateSendMultiSession(DEFAULT_PRIVATESEND_MULTISESSION),
|
|
|
|
nCachedNumBlocks(std::numeric_limits<int>::max()),
|
|
|
|
fCreateAutoBackups(true) { SetNull(); }
|
|
|
|
|
|
|
|
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
|
|
|
|
|
|
|
void ClearSkippedDenominations() { vecDenominationsSkipped.clear(); }
|
|
|
|
|
2017-09-03 15:30:58 +02:00
|
|
|
void SetMinBlocksToWait(int nMinBlocksToWaitIn) { nMinBlocksToWait = nMinBlocksToWaitIn; }
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
void ResetPool();
|
|
|
|
|
|
|
|
void UnlockCoins();
|
|
|
|
|
|
|
|
std::string GetStatus();
|
|
|
|
|
|
|
|
/// Passively run mixing in the background according to the configuration in settings
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
bool DoAutomaticDenominating(CConnman& connman, bool fDryRun=false);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
void CheckTimeout();
|
|
|
|
|
|
|
|
/// Process a new block
|
|
|
|
void NewBlock();
|
|
|
|
|
|
|
|
void UpdatedBlockTip(const CBlockIndex *pindex);
|
|
|
|
};
|
|
|
|
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
void ThreadCheckPrivateSendClient(CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
#endif
|