forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 717
/
swifttx.h
125 lines (96 loc) · 3.13 KB
/
swifttx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (c) 2009-2012 The Dash developers
// Copyright (c) 2015-2019 The PIVX developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef SWIFTTX_H
#define SWIFTTX_H
#include "base58.h"
#include "key.h"
#include "net.h"
#include "spork.h"
#include "sync.h"
#include "util.h"
/*
At 15 signatures, 1/2 of the masternode network can be owned by
one party without comprimising the security of SwiftX
(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
*/
#define SWIFTTX_SIGNATURES_REQUIRED 6
#define SWIFTTX_SIGNATURES_TOTAL 10
class CConsensusVote;
class CTransaction;
class CTransactionLock;
static const int MIN_SWIFTTX_PROTO_VERSION = 70103;
extern std::map<uint256, CTransaction> mapTxLockReq;
extern std::map<uint256, CTransaction> mapTxLockReqRejected;
extern std::map<uint256, CConsensusVote> mapTxLockVote;
extern std::map<uint256, CTransactionLock> mapTxLocks;
extern std::map<COutPoint, uint256> mapLockedInputs;
extern int nCompleteTXLocks;
int64_t CreateNewLock(CTransaction tx);
bool IsIXTXValid(const CTransaction& txCollateral);
// if two conflicting locks are approved by the network, they will cancel out
bool CheckForConflictingLocks(const CTransaction& tx);
void ProcessMessageSwiftTX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
//check if we need to vote on this transaction
void DoConsensusVote(const CTransaction& tx, int64_t nBlockHeight);
//process consensus vote message
bool ProcessConsensusVote(CNode* pnode, CConsensusVote& ctx);
// keep transaction locks in memory for an hour
void CleanTransactionLocksList();
// get the accepted transaction lock signatures
int GetTransactionLockSignatures(uint256 txHash);
int64_t GetAverageVoteTime();
class CConsensusVote : public CSignedMessage
{
public:
CTxIn vinMasternode;
uint256 txHash;
int nBlockHeight;
CConsensusVote() :
CSignedMessage(),
vinMasternode(),
txHash(),
nBlockHeight(0)
{}
uint256 GetHash() const;
// override CSignedMessage functions
uint256 GetSignatureHash() const override;
std::string GetStrMessage() const override;
const CTxIn GetVin() const override { return vinMasternode; };
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(txHash);
READWRITE(vinMasternode);
READWRITE(vchSig);
READWRITE(nBlockHeight);
try
{
READWRITE(nMessVersion);
} catch (...) {
nMessVersion = MessageVersion::MESS_VER_STRMESS;
}
}
};
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;
}
};
#endif