instantx.h 2.66 KB
Newer Older
1

Evan Duffield's avatar
Evan Duffield committed
2
// Copyright (c) 2009-2012 The Dash developers
3
4
5
6
7
8
9
10
11
12
13
14
// 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"

15
16
17
/*
    At 15 signatures, 1/2 of the masternode network can be owned by
    one party without comprimising the security of InstantX
18
19
20
21
22
    (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
23
*/
Evan Duffield's avatar
Evan Duffield committed
24
25
#define INSTANTX_SIGNATURES_REQUIRED           5
#define INSTANTX_SIGNATURES_TOTAL              10
26

27
28
29
30
31
32
33
using namespace std;
using namespace boost;

class CConsensusVote;
class CTransaction;
class CTransactionLock;

Evan Duffield's avatar
Evan Duffield committed
34
static const int MIN_INSTANTX_PROTO_VERSION = 70099;
35
36

extern map<uint256, CTransaction> mapTxLockReq;
37
38
extern map<uint256, CTransaction> mapTxLockReqRejected;
extern map<uint256, CConsensusVote> mapTxLockVote;
39
extern map<uint256, CTransactionLock> mapTxLocks;
Evan Duffield's avatar
Evan Duffield committed
40
extern std::map<COutPoint, uint256> mapLockedInputs;
41
extern int nCompleteTXLocks;
42

43
44
45

int64_t CreateNewLock(CTransaction tx);

Evan Duffield's avatar
Evan Duffield committed
46
47
bool IsIXTXValid(const CTransaction& txCollateral);

Evan Duffield's avatar
Evan Duffield committed
48
49
50
// if two conflicting locks are approved by the network, they will cancel out
bool CheckForConflictingLocks(CTransaction& tx);

51
52
53
void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);

//check if we need to vote on this transaction
54
void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight);
55
56

//process consensus vote message
57
bool ProcessConsensusVote(CConsensusVote& ctx);
58
59
60
61

// keep transaction locks in memory for an hour
void CleanTransactionLocksList();

62
63
int64_t GetAverageVoteTime();

64
65
66
67
class CConsensusVote
{
public:
    CTxIn vinMasternode;
68
    uint256 txHash;
69
    int nBlockHeight;
Evan Duffield's avatar
Evan Duffield committed
70
71
72
    std::vector<unsigned char> vchMasterNodeSignature;

    uint256 GetHash() const;
73
74
75
76

    bool SignatureValid();
    bool Sign();

77
78
79
80
    ADD_SERIALIZE_METHODS;

    template <typename Stream, typename Operation>
    inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
81
        READWRITE(txHash);
82
83
84
        READWRITE(vinMasternode);
        READWRITE(vchMasterNodeSignature);
        READWRITE(nBlockHeight);
85
    }
86
87
88
89
90
91
};

class CTransactionLock
{
public:
    int nBlockHeight;
92
    uint256 txHash;
93
    std::vector<CConsensusVote> vecConsensusVotes;
94
    int nExpiration;
Evan Duffield's avatar
Evan Duffield committed
95
    int nTimeout;
96
97
98

    bool SignaturesValid();
    int CountSignatures();
99
    void AddSignature(CConsensusVote& cv);
100

101
102
    uint256 GetHash()
    {
103
        return txHash;
104
105
106
107
    }
};


108
#endif