2019-01-29 15:53:14 +01:00
|
|
|
// Copyright (c) 2014-2019 The Dash Core developers
|
2014-12-09 02:17:57 +01:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef INSTANTX_H
|
|
|
|
#define INSTANTX_H
|
|
|
|
|
2017-08-25 14:56:48 +02:00
|
|
|
#include "chain.h"
|
2014-12-09 02:17:57 +01:00
|
|
|
#include "net.h"
|
2016-12-20 14:27:59 +01:00
|
|
|
#include "primitives/transaction.h"
|
2016-08-05 21:49:45 +02:00
|
|
|
|
2018-11-23 16:33:45 +01:00
|
|
|
#include "evo/deterministicmns.h"
|
|
|
|
|
2016-11-17 01:31:35 +01:00
|
|
|
class CTxLockVote;
|
2017-01-29 09:22:14 +01:00
|
|
|
class COutPointLock;
|
|
|
|
class CTxLockRequest;
|
2016-11-17 01:31:35 +01:00
|
|
|
class CTxLockCandidate;
|
2017-01-29 09:22:14 +01:00
|
|
|
class CInstantSend;
|
|
|
|
|
|
|
|
extern CInstantSend instantsend;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2015-04-03 00:51:08 +02:00
|
|
|
/*
|
|
|
|
At 15 signatures, 1/2 of the masternode network can be owned by
|
2018-01-06 11:05:55 +01:00
|
|
|
one party without compromising the security of InstantSend
|
2015-07-25 18:29:29 +02:00
|
|
|
(1000/2150.0)**10 = 0.00047382219560689856
|
|
|
|
(1000/2900.0)**10 = 2.3769498616783657e-05
|
|
|
|
|
|
|
|
### getting 5 of 10 signatures w/ 1000 nodes of 2900
|
|
|
|
(1000/2900.0)**5 = 0.004875397277841433
|
2015-04-03 00:51:08 +02:00
|
|
|
*/
|
2018-02-12 13:48:09 +01:00
|
|
|
|
2019-02-12 20:51:21 +01:00
|
|
|
static const int MIN_INSTANTSEND_PROTO_VERSION = 70213;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/// For how long we are going to accept votes/locks
|
|
|
|
/// after we saw the first one for a specific transaction
|
2017-10-31 15:50:03 +01:00
|
|
|
static const int INSTANTSEND_LOCK_TIMEOUT_SECONDS = 15;
|
2018-05-13 22:58:01 +02:00
|
|
|
/// For how long we are going to keep invalid votes and votes for failed lock attempts,
|
|
|
|
/// must be greater than INSTANTSEND_LOCK_TIMEOUT_SECONDS
|
2017-10-31 15:50:03 +01:00
|
|
|
static const int INSTANTSEND_FAILED_TIMEOUT_SECONDS = 60;
|
|
|
|
|
2016-08-05 21:49:45 +02:00
|
|
|
extern bool fEnableInstantSend;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/**
|
|
|
|
* Manages InstantSend. Processes lock requests, candidates, and votes.
|
|
|
|
*/
|
2017-01-29 09:22:14 +01:00
|
|
|
class CInstantSend
|
|
|
|
{
|
2019-03-03 18:26:06 +01:00
|
|
|
public:
|
2018-09-26 16:17:47 +02:00
|
|
|
/// Automatic locks of "simple" transactions are only allowed
|
|
|
|
/// when mempool usage is lower than this threshold
|
|
|
|
static const double AUTO_IX_MEMPOOL_THRESHOLD;
|
2019-03-03 18:26:06 +01:00
|
|
|
private:
|
|
|
|
static const std::string SERIALIZATION_VERSION_STRING;
|
2018-07-12 11:01:48 +02:00
|
|
|
|
2017-08-25 14:57:05 +02:00
|
|
|
// Keep track of current block height
|
|
|
|
int nCachedBlockHeight;
|
2015-02-04 22:59:19 +01:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
// maps for AlreadyHave
|
2018-05-13 22:58:01 +02:00
|
|
|
std::map<uint256, CTxLockRequest> mapLockRequestAccepted; ///< Tx hash - Tx
|
|
|
|
std::map<uint256, CTxLockRequest> mapLockRequestRejected; ///< Tx hash - Tx
|
|
|
|
std::map<uint256, CTxLockVote> mapTxLockVotes; ///< Vote hash - Vote
|
|
|
|
std::map<uint256, CTxLockVote> mapTxLockVotesOrphan; ///< Vote hash - Vote
|
2015-02-04 22:59:19 +01:00
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
std::map<uint256, CTxLockCandidate> mapTxLockCandidates; ///< Tx hash - Lock candidate
|
2015-02-04 11:44:41 +01:00
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
std::map<COutPoint, std::set<uint256> > mapVotedOutpoints; ///< UTXO - Tx hash set
|
|
|
|
std::map<COutPoint, uint256> mapLockedOutpoints; ///< UTXO - Tx hash
|
2016-11-22 15:54:26 +01:00
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/// Track masternodes who voted with no txlockrequest (for DOS protection)
|
|
|
|
std::map<COutPoint, int64_t> mapMasternodeOrphanVotes; ///< MN outpoint - Time
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
bool CreateTxLockCandidate(const CTxLockRequest& txLockRequest);
|
2017-09-14 13:41:40 +02:00
|
|
|
void CreateEmptyTxLockCandidate(const uint256& txHash);
|
2017-09-15 20:05:13 +02:00
|
|
|
void Vote(CTxLockCandidate& txLockCandidate, CConnman& connman);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/// Process consensus vote message
|
2018-02-25 06:33:40 +01:00
|
|
|
bool ProcessNewTxLockVote(CNode* pfrom, const CTxLockVote& vote, CConnman& connman);
|
|
|
|
|
|
|
|
void UpdateVotedOutpoints(const CTxLockVote& vote, CTxLockCandidate& txLockCandidate);
|
|
|
|
bool ProcessOrphanTxLockVote(const CTxLockVote& vote);
|
|
|
|
void ProcessOrphanTxLockVotes();
|
2017-01-29 09:22:14 +01:00
|
|
|
int64_t GetAverageMasternodeOrphanVoteTime();
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
void TryToFinalizeLockCandidate(const CTxLockCandidate& txLockCandidate);
|
|
|
|
void LockTransactionInputs(const CTxLockCandidate& txLockCandidate);
|
2018-05-13 22:58:01 +02:00
|
|
|
/// Update UI and notify external script if any
|
2017-01-29 09:22:14 +01:00
|
|
|
void UpdateLockedTransaction(const CTxLockCandidate& txLockCandidate);
|
2017-09-14 13:41:40 +02:00
|
|
|
bool ResolveConflicts(const CTxLockCandidate& txLockCandidate);
|
2016-11-22 15:54:26 +01:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
public:
|
2018-07-12 11:01:48 +02:00
|
|
|
mutable CCriticalSection cs_instantsend;
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
|
|
std::string strVersion;
|
|
|
|
if(ser_action.ForRead()) {
|
|
|
|
READWRITE(strVersion);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strVersion = SERIALIZATION_VERSION_STRING;
|
|
|
|
READWRITE(strVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
READWRITE(mapLockRequestAccepted);
|
|
|
|
READWRITE(mapLockRequestRejected);
|
|
|
|
READWRITE(mapTxLockVotes);
|
|
|
|
READWRITE(mapTxLockVotesOrphan);
|
|
|
|
READWRITE(mapTxLockCandidates);
|
|
|
|
READWRITE(mapVotedOutpoints);
|
|
|
|
READWRITE(mapLockedOutpoints);
|
|
|
|
READWRITE(mapMasternodeOrphanVotes);
|
|
|
|
READWRITE(nCachedBlockHeight);
|
|
|
|
|
|
|
|
if(ser_action.ForRead() && (strVersion != SERIALIZATION_VERSION_STRING)) {
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear();
|
2016-03-24 16:54:29 +01:00
|
|
|
|
2017-02-06 14:31:37 +01:00
|
|
|
void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
|
2016-03-24 16:54:29 +01:00
|
|
|
|
2017-09-15 20:05:13 +02:00
|
|
|
bool ProcessTxLockRequest(const CTxLockRequest& txLockRequest, CConnman& connman);
|
2018-01-06 11:06:43 +01:00
|
|
|
void Vote(const uint256& txHash, CConnman& connman);
|
2016-03-24 16:54:29 +01:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
bool AlreadyHave(const uint256& hash);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
void AcceptLockRequest(const CTxLockRequest& txLockRequest);
|
|
|
|
void RejectLockRequest(const CTxLockRequest& txLockRequest);
|
|
|
|
bool HasTxLockRequest(const uint256& txHash);
|
|
|
|
bool GetTxLockRequest(const uint256& txHash, CTxLockRequest& txLockRequestRet);
|
2016-03-23 15:49:35 +01:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
bool GetTxLockVote(const uint256& hash, CTxLockVote& txLockVoteRet);
|
2016-03-23 15:49:35 +01:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
bool GetLockedOutPointTxHash(const COutPoint& outpoint, uint256& hashRet);
|
2016-03-23 15:49:35 +01:00
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/// Verify if transaction is currently locked
|
2017-01-29 09:22:14 +01:00
|
|
|
bool IsLockedInstantSendTransaction(const uint256& txHash);
|
2018-05-13 22:58:01 +02:00
|
|
|
/// Get the actual number of accepted lock signatures
|
2017-01-29 09:22:14 +01:00
|
|
|
int GetTransactionLockSignatures(const uint256& txHash);
|
2015-02-02 18:33:52 +01:00
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/// Remove expired entries from maps
|
2017-01-29 09:22:14 +01:00
|
|
|
void CheckAndRemove();
|
2018-05-13 22:58:01 +02:00
|
|
|
/// Verify if transaction lock timed out
|
2017-09-14 13:41:40 +02:00
|
|
|
bool IsTxLockCandidateTimedOut(const uint256& txHash);
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2017-09-15 20:05:13 +02:00
|
|
|
void Relay(const uint256& txHash, CConnman& connman);
|
2017-01-29 09:22:14 +01:00
|
|
|
|
|
|
|
void UpdatedBlockTip(const CBlockIndex *pindex);
|
2019-05-23 18:22:37 +02:00
|
|
|
void SyncTransaction(const CTransactionRef& tx, const CBlockIndex* pindex = nullptr, int posInBlock = 0);
|
2017-06-06 01:47:23 +02:00
|
|
|
|
2018-07-12 11:01:48 +02:00
|
|
|
std::string ToString() const;
|
2018-07-16 14:47:37 +02:00
|
|
|
|
2018-11-01 22:58:17 +01:00
|
|
|
void DoMaintenance();
|
2018-09-26 16:17:47 +02:00
|
|
|
|
|
|
|
/// checks if we can automatically lock "simple" transactions
|
|
|
|
static bool CanAutoLock();
|
|
|
|
|
|
|
|
/// flag of the AutoLock Bip9 activation
|
|
|
|
static std::atomic<bool> isAutoLockBip9Active;
|
2017-01-29 09:22:14 +01:00
|
|
|
};
|
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/**
|
|
|
|
* An InstantSend transaction lock request.
|
|
|
|
*/
|
2017-09-20 14:02:53 +02:00
|
|
|
class CTxLockRequest
|
2014-12-09 02:17:57 +01:00
|
|
|
{
|
2017-01-29 09:22:14 +01:00
|
|
|
private:
|
2017-12-07 10:43:23 +01:00
|
|
|
static const CAmount MIN_FEE = 0.0001 * COIN;
|
2018-09-26 16:17:47 +02:00
|
|
|
/// If transaction has less or equal inputs than MAX_INPUTS_FOR_AUTO_IX,
|
|
|
|
/// it will be automatically locked
|
|
|
|
static const int MAX_INPUTS_FOR_AUTO_IX = 4;
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
public:
|
2018-05-13 22:58:01 +02:00
|
|
|
/// Warn for a large number of inputs to an IS tx - fees could be substantial
|
|
|
|
/// and the number txlvote responses requested large (10 * # of inputs)
|
2017-02-02 23:38:33 +01:00
|
|
|
static const int WARN_MANY_INPUTS = 100;
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2017-09-20 14:02:53 +02:00
|
|
|
CTransactionRef tx;
|
|
|
|
|
|
|
|
CTxLockRequest() : tx(MakeTransactionRef()) {}
|
|
|
|
CTxLockRequest(const CTransaction& _tx) : tx(MakeTransactionRef(_tx)) {};
|
2018-09-26 16:17:47 +02:00
|
|
|
CTxLockRequest(const CTransactionRef& _tx) : tx(_tx) {};
|
2017-09-20 14:02:53 +02:00
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
|
|
READWRITE(tx);
|
|
|
|
}
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2017-09-14 13:41:40 +02:00
|
|
|
bool IsValid() const;
|
2018-10-15 13:59:57 +02:00
|
|
|
CAmount GetMinFee(bool fForceMinFee) const;
|
2017-01-29 09:22:14 +01:00
|
|
|
int GetMaxSignatures() const;
|
2017-09-14 13:41:40 +02:00
|
|
|
|
2018-09-26 16:17:47 +02:00
|
|
|
// checks if related transaction is "simple" to lock it automatically
|
|
|
|
bool IsSimple() const;
|
|
|
|
|
2017-09-20 14:02:53 +02:00
|
|
|
const uint256 &GetHash() const {
|
|
|
|
return tx->GetHash();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ToString() const {
|
|
|
|
return tx->ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator==(const CTxLockRequest& a, const CTxLockRequest& b)
|
|
|
|
{
|
|
|
|
return *a.tx == *b.tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator!=(const CTxLockRequest& a, const CTxLockRequest& b)
|
|
|
|
{
|
|
|
|
return *a.tx != *b.tx;
|
|
|
|
}
|
|
|
|
|
2017-09-14 13:41:40 +02:00
|
|
|
explicit operator bool() const
|
|
|
|
{
|
|
|
|
return *this != CTxLockRequest();
|
|
|
|
}
|
2017-01-29 09:22:14 +01:00
|
|
|
};
|
2015-02-01 16:53:49 +01:00
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/**
|
|
|
|
* An InstantSend transaction lock vote. Sent by a masternode in response to a
|
|
|
|
* transaction lock request (ix message) to indicate the transaction input can
|
|
|
|
* be locked. Contains the proposed transaction's hash and the outpoint being
|
|
|
|
* locked along with the masternodes outpoint and signature.
|
|
|
|
* @see CTxLockRequest
|
|
|
|
*/
|
2017-01-29 09:22:14 +01:00
|
|
|
class CTxLockVote
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
uint256 txHash;
|
|
|
|
COutPoint outpoint;
|
2019-01-03 10:17:43 +01:00
|
|
|
// TODO remove this member (not needed anymore after DIP3 has been deployed)
|
2017-01-29 09:22:14 +01:00
|
|
|
COutPoint outpointMasternode;
|
2018-11-28 11:43:28 +01:00
|
|
|
uint256 quorumModifierHash;
|
2018-11-23 16:33:45 +01:00
|
|
|
uint256 masternodeProTxHash;
|
2017-01-29 09:22:14 +01:00
|
|
|
std::vector<unsigned char> vchMasternodeSignature;
|
2016-11-22 15:54:26 +01:00
|
|
|
// local memory only
|
2018-05-13 22:58:01 +02:00
|
|
|
int nConfirmedHeight; ///< When corresponding tx is 0-confirmed or conflicted, nConfirmedHeight is -1
|
2017-01-29 09:22:14 +01:00
|
|
|
int64_t nTimeCreated;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CTxLockVote() :
|
|
|
|
txHash(),
|
|
|
|
outpoint(),
|
|
|
|
outpointMasternode(),
|
2018-11-28 11:43:28 +01:00
|
|
|
quorumModifierHash(),
|
2018-11-23 16:33:45 +01:00
|
|
|
masternodeProTxHash(),
|
2017-01-29 09:22:14 +01:00
|
|
|
vchMasternodeSignature(),
|
|
|
|
nConfirmedHeight(-1),
|
|
|
|
nTimeCreated(GetTime())
|
|
|
|
{}
|
|
|
|
|
2018-11-28 11:43:28 +01:00
|
|
|
CTxLockVote(const uint256& txHashIn, const COutPoint& outpointIn, const COutPoint& outpointMasternodeIn, const uint256& quorumModifierHashIn, const uint256& masternodeProTxHashIn) :
|
2017-01-29 09:22:14 +01:00
|
|
|
txHash(txHashIn),
|
|
|
|
outpoint(outpointIn),
|
|
|
|
outpointMasternode(outpointMasternodeIn),
|
2018-11-28 11:43:28 +01:00
|
|
|
quorumModifierHash(quorumModifierHashIn),
|
2018-11-23 16:33:45 +01:00
|
|
|
masternodeProTxHash(masternodeProTxHashIn),
|
2017-01-29 09:22:14 +01:00
|
|
|
vchMasternodeSignature(),
|
|
|
|
nConfirmedHeight(-1),
|
|
|
|
nTimeCreated(GetTime())
|
|
|
|
{}
|
2016-11-22 15:54:26 +01:00
|
|
|
|
2015-04-03 00:51:08 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2017-09-19 21:36:55 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2015-02-02 13:24:04 +01:00
|
|
|
READWRITE(txHash);
|
2017-01-29 09:22:14 +01:00
|
|
|
READWRITE(outpoint);
|
|
|
|
READWRITE(outpointMasternode);
|
2019-01-03 10:17:43 +01:00
|
|
|
READWRITE(quorumModifierHash);
|
|
|
|
READWRITE(masternodeProTxHash);
|
2018-02-16 15:54:53 +01:00
|
|
|
if (!(s.GetType() & SER_GETHASH)) {
|
|
|
|
READWRITE(vchMasternodeSignature);
|
|
|
|
}
|
2015-04-03 00:51:08 +02:00
|
|
|
}
|
2016-08-12 07:55:41 +02:00
|
|
|
|
|
|
|
uint256 GetHash() const;
|
2018-02-16 15:54:53 +01:00
|
|
|
uint256 GetSignatureHash() const;
|
2016-08-12 07:55:41 +02:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
uint256 GetTxHash() const { return txHash; }
|
|
|
|
COutPoint GetOutpoint() const { return outpoint; }
|
|
|
|
COutPoint GetMasternodeOutpoint() const { return outpointMasternode; }
|
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
bool IsValid(CNode* pnode, CConnman& connman) const;
|
2017-01-29 09:22:14 +01:00
|
|
|
void SetConfirmedHeight(int nConfirmedHeightIn) { nConfirmedHeight = nConfirmedHeightIn; }
|
|
|
|
bool IsExpired(int nHeight) const;
|
2017-09-14 13:41:40 +02:00
|
|
|
bool IsTimedOut() const;
|
2017-10-31 15:50:03 +01:00
|
|
|
bool IsFailed() const;
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2016-08-12 07:55:41 +02:00
|
|
|
bool Sign();
|
2016-11-21 21:40:32 +01:00
|
|
|
bool CheckSignature() const;
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2017-09-15 20:05:13 +02:00
|
|
|
void Relay(CConnman& connman) const;
|
2014-12-09 02:17:57 +01:00
|
|
|
};
|
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/**
|
|
|
|
* An InstantSend OutpointLock.
|
|
|
|
*/
|
2017-01-29 09:22:14 +01:00
|
|
|
class COutPointLock
|
2014-12-09 02:17:57 +01:00
|
|
|
{
|
2017-01-29 09:22:14 +01:00
|
|
|
private:
|
2018-05-13 22:58:01 +02:00
|
|
|
COutPoint outpoint; ///< UTXO
|
|
|
|
std::map<COutPoint, CTxLockVote> mapMasternodeVotes; ///< Masternode outpoint - vote
|
2017-09-14 13:41:40 +02:00
|
|
|
bool fAttacked = false;
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
public:
|
2018-07-12 11:01:48 +02:00
|
|
|
COutPointLock() {}
|
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
COutPointLock(const COutPoint& outpointIn) :
|
|
|
|
outpoint(outpointIn),
|
|
|
|
mapMasternodeVotes()
|
|
|
|
{}
|
2015-02-02 13:24:04 +01:00
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
COutPoint GetOutpoint() const { return outpoint; }
|
|
|
|
|
2018-07-12 11:01:48 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
|
|
READWRITE(outpoint);
|
|
|
|
READWRITE(mapMasternodeVotes);
|
|
|
|
READWRITE(fAttacked);
|
|
|
|
}
|
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
bool AddVote(const CTxLockVote& vote);
|
2017-02-04 19:17:45 +01:00
|
|
|
std::vector<CTxLockVote> GetVotes() const;
|
|
|
|
bool HasMasternodeVoted(const COutPoint& outpointMasternodeIn) const;
|
2017-09-14 13:41:40 +02:00
|
|
|
int CountVotes() const { return fAttacked ? 0 : mapMasternodeVotes.size(); }
|
2019-03-15 09:48:24 +01:00
|
|
|
bool IsReady() const;
|
2017-09-14 13:41:40 +02:00
|
|
|
void MarkAsAttacked() { fAttacked = true; }
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2017-09-15 20:05:13 +02:00
|
|
|
void Relay(CConnman& connman) const;
|
2014-12-09 02:17:57 +01:00
|
|
|
};
|
|
|
|
|
2018-05-13 22:58:01 +02:00
|
|
|
/**
|
|
|
|
* An InstantSend transaction lock candidate.
|
|
|
|
*/
|
2017-01-29 09:22:14 +01:00
|
|
|
class CTxLockCandidate
|
|
|
|
{
|
|
|
|
private:
|
2018-05-13 22:58:01 +02:00
|
|
|
int nConfirmedHeight; ///<When corresponding tx is 0-confirmed or conflicted, nConfirmedHeight is -1
|
2017-09-14 13:41:40 +02:00
|
|
|
int64_t nTimeCreated;
|
2017-01-29 09:22:14 +01:00
|
|
|
|
|
|
|
public:
|
2018-07-12 11:01:48 +02:00
|
|
|
CTxLockCandidate() :
|
|
|
|
nConfirmedHeight(-1),
|
|
|
|
nTimeCreated(GetTime())
|
|
|
|
{}
|
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
CTxLockCandidate(const CTxLockRequest& txLockRequestIn) :
|
|
|
|
nConfirmedHeight(-1),
|
2017-09-14 13:41:40 +02:00
|
|
|
nTimeCreated(GetTime()),
|
2017-01-29 09:22:14 +01:00
|
|
|
txLockRequest(txLockRequestIn),
|
|
|
|
mapOutPointLocks()
|
|
|
|
{}
|
|
|
|
|
|
|
|
CTxLockRequest txLockRequest;
|
|
|
|
std::map<COutPoint, COutPointLock> mapOutPointLocks;
|
|
|
|
|
2018-07-12 11:01:48 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
|
|
READWRITE(txLockRequest);
|
|
|
|
READWRITE(mapOutPointLocks);
|
|
|
|
READWRITE(nTimeCreated);
|
|
|
|
READWRITE(nConfirmedHeight);
|
|
|
|
}
|
|
|
|
|
2017-01-29 09:22:14 +01:00
|
|
|
uint256 GetHash() const { return txLockRequest.GetHash(); }
|
|
|
|
|
|
|
|
void AddOutPointLock(const COutPoint& outpoint);
|
2017-09-14 13:41:40 +02:00
|
|
|
void MarkOutpointAsAttacked(const COutPoint& outpoint);
|
2017-01-29 09:22:14 +01:00
|
|
|
bool AddVote(const CTxLockVote& vote);
|
|
|
|
bool IsAllOutPointsReady() const;
|
|
|
|
|
|
|
|
bool HasMasternodeVoted(const COutPoint& outpointIn, const COutPoint& outpointMasternodeIn);
|
|
|
|
int CountVotes() const;
|
|
|
|
|
|
|
|
void SetConfirmedHeight(int nConfirmedHeightIn) { nConfirmedHeight = nConfirmedHeightIn; }
|
|
|
|
bool IsExpired(int nHeight) const;
|
2017-09-14 13:41:40 +02:00
|
|
|
bool IsTimedOut() const;
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2017-09-15 20:05:13 +02:00
|
|
|
void Relay(CConnman& connman) const;
|
2017-01-29 09:22:14 +01:00
|
|
|
};
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2015-04-03 00:51:08 +02:00
|
|
|
#endif
|