dash/src/instantx.h

110 lines
2.7 KiB
C
Raw Normal View History

2015-03-18 00:06:58 +01:00
// Copyright (c) 2009-2012 The Dash developers
// 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"
#include "spork.h"
2015-04-03 00:51:08 +02:00
/*
At 15 signatures, 1/2 of the masternode network can be owned by
one party without comprimising the security of InstantX
(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
*/
2015-07-28 02:33:57 +02:00
#define INSTANTX_SIGNATURES_REQUIRED 6
2015-07-12 19:47:28 +02:00
#define INSTANTX_SIGNATURES_TOTAL 10
2015-04-03 00:51:08 +02:00
using namespace std;
using namespace boost;
class CConsensusVote;
class CTransaction;
class CTransactionLock;
2015-08-04 20:22:31 +02:00
static const int MIN_INSTANTX_PROTO_VERSION = 70101;
extern map<uint256, CTransaction> mapTxLockReq;
extern map<uint256, CTransaction> mapTxLockReqRejected;
extern map<uint256, CConsensusVote> mapTxLockVote;
extern map<uint256, CTransactionLock> mapTxLocks;
2015-02-04 21:20:13 +01:00
extern std::map<COutPoint, uint256> mapLockedInputs;
extern int nCompleteTXLocks;
int64_t CreateNewLock(CTransaction tx);
2015-02-04 11:44:41 +01:00
bool IsIXTXValid(const CTransaction& txCollateral);
2015-02-05 17:48:57 +01:00
// if two conflicting locks are approved by the network, they will cancel out
bool CheckForConflictingLocks(CTransaction& tx);
void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
//check if we need to vote on this transaction
void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight);
//process consensus vote message
2015-08-07 05:07:40 +02:00
bool ProcessConsensusVote(CNode *pnode, CConsensusVote& ctx);
// keep transaction locks in memory for an hour
void CleanTransactionLocksList();
int64_t GetAverageVoteTime();
class CConsensusVote
{
public:
CTxIn vinMasternode;
uint256 txHash;
int nBlockHeight;
2015-02-01 16:53:49 +01:00
std::vector<unsigned char> vchMasterNodeSignature;
uint256 GetHash() const;
bool SignatureValid();
bool Sign();
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) {
READWRITE(txHash);
READWRITE(vinMasternode);
READWRITE(vchMasterNodeSignature);
READWRITE(nBlockHeight);
2015-04-03 00:51:08 +02:00
}
};
class CTransactionLock
{
public:
int nBlockHeight;
uint256 txHash;
std::vector<CConsensusVote> vecConsensusVotes;
int nExpiration;
int nTimeout;
bool SignaturesValid();
int CountSignatures();
void AddSignature(CConsensusVote& cv);
uint256 GetHash()
{
return txHash;
}
};
2015-04-03 00:51:08 +02:00
#endif