2016-12-20 14:26:45 +01:00
|
|
|
// Copyright (c) 2014-2017 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
|
|
|
|
|
|
|
|
#include "sync.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "base58.h"
|
|
|
|
#include "main.h"
|
2016-08-05 21:49:45 +02:00
|
|
|
|
|
|
|
class CTransaction;
|
2016-11-17 01:31:35 +01:00
|
|
|
class CTxLockVote;
|
|
|
|
class CTxLockCandidate;
|
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
|
2016-09-02 14:17:32 +02:00
|
|
|
one party without comprimising 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
|
|
|
*/
|
2016-08-05 21:49:45 +02:00
|
|
|
static const int INSTANTSEND_SIGNATURES_REQUIRED = 6;
|
|
|
|
static const int INSTANTSEND_SIGNATURES_TOTAL = 10;
|
|
|
|
static const int DEFAULT_INSTANTSEND_DEPTH = 5;
|
2015-04-03 00:51:08 +02:00
|
|
|
|
2016-12-20 04:25:20 +01:00
|
|
|
static const int MIN_INSTANTSEND_PROTO_VERSION = 70204;
|
2016-11-21 21:40:32 +01:00
|
|
|
static const CAmount INSTANTSEND_MIN_FEE = 0.001 * COIN;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2016-08-05 21:49:45 +02:00
|
|
|
extern bool fEnableInstantSend;
|
|
|
|
extern int nInstantSendDepth;
|
|
|
|
extern int nCompleteTXLocks;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2016-11-17 01:31:35 +01:00
|
|
|
extern std::map<uint256, CTransaction> mapLockRequestAccepted;
|
|
|
|
extern std::map<uint256, CTransaction> mapLockRequestRejected;
|
|
|
|
extern std::map<uint256, CTxLockVote> mapTxLockVotes;
|
2015-02-04 21:20:13 +01:00
|
|
|
extern std::map<COutPoint, uint256> mapLockedInputs;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2015-02-04 22:59:19 +01:00
|
|
|
|
2016-11-21 21:40:32 +01:00
|
|
|
void ProcessMessageInstantSend(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
2015-02-04 22:59:19 +01:00
|
|
|
|
2016-09-05 18:09:25 +02:00
|
|
|
bool IsInstantSendTxValid(const CTransaction& txCandidate);
|
2015-02-04 11:44:41 +01:00
|
|
|
|
2016-11-22 15:54:26 +01:00
|
|
|
bool ProcessTxLockRequest(CNode* pfrom, const CTransaction &tx);
|
|
|
|
|
2016-11-21 21:40:32 +01:00
|
|
|
int64_t CreateTxLockCandidate(const CTransaction &tx);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
|
|
|
//check if we need to vote on this transaction
|
2016-11-21 21:40:32 +01:00
|
|
|
void CreateTxLockVote(const CTransaction& tx, int nBlockHeight);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
|
|
|
//process consensus vote message
|
2016-11-17 01:31:35 +01:00
|
|
|
bool ProcessTxLockVote(CNode *pnode, CTxLockVote& vote);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2016-11-22 15:54:26 +01:00
|
|
|
void ProcessOrphanTxLockVotes();
|
|
|
|
|
2016-03-24 16:54:29 +01:00
|
|
|
//update UI and notify external script if any
|
2016-11-21 21:40:32 +01:00
|
|
|
void UpdateLockedTransaction(const CTransaction& tx, bool fForceNotification = false);
|
2016-03-24 16:54:29 +01:00
|
|
|
|
2016-11-21 21:40:32 +01:00
|
|
|
void LockTransactionInputs(const CTransaction& tx);
|
2016-03-24 16:54:29 +01:00
|
|
|
|
|
|
|
// if two conflicting locks are approved by the network, they will cancel out
|
2016-11-21 21:40:32 +01:00
|
|
|
bool FindConflictingLocks(const CTransaction& tx);
|
2016-03-24 16:54:29 +01:00
|
|
|
|
|
|
|
//try to resolve conflicting locks
|
2016-11-21 21:40:32 +01:00
|
|
|
void ResolveConflicts(const CTransaction& tx);
|
2016-03-24 16:54:29 +01:00
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
// keep transaction locks in memory for an hour
|
2016-11-17 01:31:35 +01:00
|
|
|
void CleanTxLockCandidates();
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2016-03-23 15:49:35 +01:00
|
|
|
// verify if transaction is currently locked
|
2016-11-21 21:40:32 +01:00
|
|
|
bool IsLockedInstandSendTransaction(const uint256 &txHash);
|
2016-03-23 15:49:35 +01:00
|
|
|
|
|
|
|
// get the actual uber og accepted lock signatures
|
2016-11-21 21:40:32 +01:00
|
|
|
int GetTransactionLockSignatures(const uint256 &txHash);
|
2016-03-23 15:49:35 +01:00
|
|
|
|
|
|
|
// verify if transaction lock timed out
|
2016-11-21 21:40:32 +01:00
|
|
|
bool IsTransactionLockTimedOut(const uint256 &txHash);
|
2016-03-23 15:49:35 +01:00
|
|
|
|
2016-11-22 15:54:26 +01:00
|
|
|
int64_t GetAverageMasternodeOrphanVoteTime();
|
2015-02-02 18:33:52 +01:00
|
|
|
|
2016-11-17 01:31:35 +01:00
|
|
|
class CTxLockVote
|
2014-12-09 02:17:57 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTxIn vinMasternode;
|
2015-02-02 13:24:04 +01:00
|
|
|
uint256 txHash;
|
2014-12-09 02:17:57 +01:00
|
|
|
int nBlockHeight;
|
2015-02-01 16:53:49 +01:00
|
|
|
std::vector<unsigned char> vchMasterNodeSignature;
|
|
|
|
|
2016-11-22 15:54:26 +01:00
|
|
|
// local memory only
|
|
|
|
int64_t nOrphanExpireTime;
|
|
|
|
|
2015-04-03 00:51:08 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
2015-02-02 13:24:04 +01:00
|
|
|
READWRITE(txHash);
|
2014-12-09 02:17:57 +01:00
|
|
|
READWRITE(vinMasternode);
|
|
|
|
READWRITE(vchMasterNodeSignature);
|
|
|
|
READWRITE(nBlockHeight);
|
2015-04-03 00:51:08 +02:00
|
|
|
}
|
2016-08-12 07:55:41 +02:00
|
|
|
|
|
|
|
uint256 GetHash() const;
|
|
|
|
|
|
|
|
bool Sign();
|
2016-11-21 21:40:32 +01:00
|
|
|
bool CheckSignature() const;
|
2014-12-09 02:17:57 +01:00
|
|
|
};
|
|
|
|
|
2016-11-17 01:31:35 +01:00
|
|
|
class CTxLockCandidate
|
2014-12-09 02:17:57 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
int nBlockHeight;
|
2015-02-02 13:24:04 +01:00
|
|
|
uint256 txHash;
|
2016-11-17 01:31:35 +01:00
|
|
|
std::vector<CTxLockVote> vecTxLockVotes;
|
|
|
|
int nExpirationBlock;
|
2015-02-05 16:52:02 +01:00
|
|
|
int nTimeout;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2016-08-12 07:55:41 +02:00
|
|
|
uint256 GetHash() const { return txHash; }
|
2015-02-02 13:24:04 +01:00
|
|
|
|
2016-08-12 07:55:41 +02:00
|
|
|
bool IsAllVotesValid();
|
2016-11-21 21:40:32 +01:00
|
|
|
void AddVote(const CTxLockVote& vote);
|
2016-08-12 07:55:41 +02:00
|
|
|
int CountVotes();
|
2014-12-09 02:17:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-04-03 00:51:08 +02:00
|
|
|
#endif
|