Skip to content

Commit 6b40431

Browse files
committed
Merge pull request #6 from Infernoman/Working
Merge working branch
2 parents 665f0da + 4c675ad commit 6b40431

15 files changed

Lines changed: 276 additions & 169 deletions

CHANGELOG

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ https://github.com/dashpay/dash/commit/0d51e1c90df98f649ea3062efa448c1c5bb9827b
6464
Added dstx support for free transactions ( NEEDS FIXED - AcceptToMemoryPool)
6565
https://github.com/dashpay/dash/commit/13246598b8b84af2ade8b3d0368655fc64f5cca0
6666

67+
68+
69+
Change the way changes are handled:
70+
https://github.com/dashpay/dash/commit/2e05bf212eaf5e0fe98161f673483dc62e5c0a95
71+
6772
rpc fixes:
6873
https://github.com/dashpay/dash/commit/558585039696096b355a9e75beb70b36a3b7cec9
6974

@@ -76,6 +81,28 @@ https://github.com/dashpay/dash/commit/56471f83304cff936f2ad09242f9a2462389e75b
7681
allow searching masternode list by ip address
7782
https://github.com/dashpay/dash/commit/736e6da6b852119332b41b4da955af4d1b4ed8f9
7883

84+
Few fixes for processing extra messages:
85+
https://github.com/dashpay/dash/commit/1ded1b9ec2de5687b38ac9178cc4b58375201e03
86+
87+
Fix crashes on remove from vector
88+
https://github.com/dashpay/dash/commit/4fe845bf1530ad1b59dcfddebe50f323e1977402
89+
90+
Fix versions:
91+
https://github.com/dashpay/dash/commit/0747da6b36a51f24efa7ca7fcb4f2ffa3332a118
92+
93+
check and remove expired masternodes on client start
94+
https://github.com/dashpay/dash/commit/4af7c7411ac6837260ff5ff04ee4a4a944ac2082
95+
96+
clear maps in mnodeman
97+
https://github.com/dashpay/dash/commit/80ce3f5a061e069145db81850e1afcffa52c7e12
98+
99+
Cleanup copiler
100+
101+
102+
103+
104+
105+
79106

80107
Removal of old code:
81108
IsProtocolV1/IsProtocolV2 hard fork switches removed

src/darksend.cpp

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
5555
if(IsInitialBlockDownload()) return;
5656

5757
if (strCommand == "dsf") { //DarkSend Final tx
58-
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
58+
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
5959
return;
6060
}
6161

@@ -78,7 +78,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
7878
}
7979

8080
else if (strCommand == "dsc") { //DarkSend Complete
81-
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
81+
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
8282
return;
8383
}
8484

@@ -102,7 +102,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
102102

103103
else if (strCommand == "dsa") { //DarkSend Acceptable
104104

105-
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
105+
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
106106
std::string strError = _("Incompatible version.");
107107
LogPrintf("dsa -- incompatible version! \n");
108108
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, strError);
@@ -133,7 +133,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
133133

134134
if(darkSendPool.sessionUsers == 0) {
135135
if(pmn->nLastDsq != 0 &&
136-
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
136+
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(MIN_POOL_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
137137
LogPrintf("dsa -- last dsq too recent, must wait. %s \n", pmn->addr.ToString().c_str()); std::string strError = _("Last Darksend was too recent.");
138138
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, strError);
139139
return;
@@ -152,7 +152,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
152152
}
153153
} else if (strCommand == "dsq") { //DarkSend Queue
154154

155-
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
155+
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
156156
return;
157157
}
158158

@@ -186,7 +186,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
186186
if(fDebug) LogPrintf("dsq last %d last2 %d count %d\n", pmn->nLastDsq, pmn->nLastDsq + mnodeman.size()/5, darkSendPool.nDsqCount);
187187
//don't allow a few nodes to dominate the queuing process
188188
if(pmn->nLastDsq != 0 &&
189-
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
189+
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(MIN_POOL_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
190190
if(fDebug) LogPrintf("dsq -- masternode sending too many dsq messages. %s \n", pmn->addr.ToString().c_str());
191191
return;
192192
}
@@ -202,7 +202,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
202202

203203
} else if (strCommand == "dsi") { //DarkSend vIn
204204
std::string error = "";
205-
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
205+
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
206206
LogPrintf("dsi -- incompatible version! \n");
207207
error = _("Incompatible version.");
208208
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, error);
@@ -327,7 +327,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
327327
}
328328

329329
else if (strCommand == "dssub") { //DarkSend Subscribe To
330-
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
330+
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
331331
return;
332332
}
333333

@@ -340,7 +340,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
340340

341341
else if (strCommand == "dssu") { //DarkSend status update
342342

343-
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
343+
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
344344
return;
345345
}
346346

@@ -368,7 +368,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
368368
}
369369

370370
else if (strCommand == "dss") { //DarkSend Sign Final Tx
371-
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
371+
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
372372
return;
373373
}
374374

@@ -1039,7 +1039,8 @@ bool CDarkSendPool::IsCollateralValid(const CTransaction& txCollateral){
10391039

10401040
CValidationState state;
10411041
//if(!AcceptableInputs(mempool, state, txCollateral)){
1042-
bool* pfMissingInputs = false;
1042+
bool* pfMissingInputs = new bool;
1043+
*pfMissingInputs = false;
10431044
if(!AcceptableInputs(mempool, txCollateral, false, pfMissingInputs)){
10441045
if(fDebug) LogPrintf ("CDarkSendPool::IsCollateralValid - didn't pass IsAcceptable\n");
10451046
return false;
@@ -1548,7 +1549,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
15481549

15491550
int protocolVersion;
15501551
if(!dsq.GetProtocolVersion(protocolVersion)) continue;
1551-
if(protocolVersion < MIN_PEER_PROTO_VERSION) continue;
1552+
if(protocolVersion < MIN_POOL_PEER_PROTO_VERSION) continue;
15521553

15531554
//non-denom's are incompatible
15541555
if((dsq.nDenom & (1 << 4))) continue;
@@ -1610,7 +1611,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
16101611
if(pmn == NULL)
16111612
{
16121613
LogPrintf("DoAutomaticDenominating --- masternode list is empty!\n");
1613-
return false;
1614+
return false;
16141615
}
16151616
//don't reuse masternodes
16161617
BOOST_FOREACH(CTxIn usedVin, vecMasternodesUsed) {
@@ -1619,13 +1620,13 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
16191620
continue;
16201621
}
16211622
}
1622-
if(pmn->protocolVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
1623+
if(pmn->protocolVersion < MIN_POOL_PEER_PROTO_VERSION) {
16231624
i++;
16241625
continue;
16251626
}
16261627

16271628
if(pmn->nLastDsq != 0 &&
1628-
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
1629+
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(MIN_POOL_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
16291630
i++;
16301631
continue;
16311632
}
@@ -2185,25 +2186,18 @@ void ThreadCheckDarkSendPool()
21852186
MilliSleep(2500);
21862187
//LogPrintf("ThreadCheckDarkSendPool::check timeout\n");
21872188
darkSendPool.CheckTimeout();
2188-
2189-
if(c % 60 == 0){
2189+
if(c % 60 == 0)
2190+
{
2191+
LOCK(cs_main);
2192+
/*
2193+
cs_main is required for doing CMasternode.Check because something
2194+
is modifying the coins view without a mempool lock. It causes
2195+
segfaults from this code without the cs_main lock.
2196+
*/
2197+
mnodeman.CheckAndRemove();
21902198
darkSendPool.ProcessMasternodeConnections();
21912199
masternodePayments.CleanPaymentList();
21922200
CleanTransactionLocksList();
2193-
2194-
// nodes refuse to relay dseep if it was less then MASTERNODE_MIN_DSEEP_SECONDS ago
2195-
// MASTERNODE_PING_WAIT_SECONDS gives some additional time on top of it
2196-
// so we have a timeout for this check on start unless we need to
2197-
if(c > MASTERNODE_MIN_DSEEP_SECONDS + MASTERNODE_PING_WAIT_SECONDS || mnodeman.UpdateNeeded())
2198-
{
2199-
LOCK(cs_main);
2200-
/*
2201-
cs_main is required for doing CMasternode.Check because something
2202-
is modifying the coins view without a mempool lock. It causes
2203-
segfaults from this code without the cs_main lock.
2204-
*/
2205-
mnodeman.CheckAndRemove();
2206-
}
22072201
}
22082202

22092203
if(c % MASTERNODE_PING_SECONDS == 0) activeMasternode.ManageStatus();
@@ -2217,7 +2211,7 @@ void ThreadCheckDarkSendPool()
22172211
LOCK(cs_vNodes);
22182212
BOOST_FOREACH(CNode* pnode, vNodes)
22192213
{
2220-
if (pnode->nVersion >= darkSendPool.MIN_PEER_PROTO_VERSION) {
2214+
if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION) {
22212215

22222216
//keep track of who we've asked for the list
22232217
if(pnode->HasFulfilledRequest("mnsync")) continue;
@@ -2226,7 +2220,7 @@ void ThreadCheckDarkSendPool()
22262220
LogPrintf("Successfully synced, asking for Masternode list and payment list\n");
22272221

22282222
//request full mn list only if masternodes.dat was updated quite a long time ago
2229-
if(mnodeman.UpdateNeeded()) pnode->PushMessage("dseg", CTxIn());
2223+
mnodeman.DsegUpdate(pnode);
22302224

22312225
pnode->PushMessage("mnget"); //sync payees
22322226
pnode->PushMessage("getsporks"); //get current network sporks

src/darksend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class CActiveMasternode;
3838
#define DARKSEND_QUEUE_TIMEOUT 120
3939
#define DARKSEND_SIGNING_TIMEOUT 30
4040

41+
static const int MIN_POOL_PEER_PROTO_VERSION = 61400; // minimum peer version accepted by DarkSendPool
42+
4143
extern CDarkSendPool darkSendPool;
4244
extern CDarkSendSigner darkSendSigner;
4345
extern std::vector<CDarksendQueue> vecDarksendQueue;
@@ -225,8 +227,6 @@ class CDarksendSession
225227
class CDarkSendPool
226228
{
227229
public:
228-
static const int MIN_PEER_PROTO_VERSION = 60020;
229-
230230
// clients entries
231231
std::vector<CDarkSendEntry> myEntries;
232232
// masternode entries

src/init.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,12 @@ bool AppInit2(boost::thread_group& threadGroup)
892892
CMasternodeDB mndb;
893893
if (!mndb.Read(mnodeman))
894894
LogPrintf("Invalid or missing masternodes.dat; recreating\n");
895+
else
896+
mnodeman.CheckAndRemove(); // clean out expired
895897
}
896898

897-
LogPrintf("Loaded %i masternodes from masternodes.dat %dms\n",
898-
mnodeman.size(), GetTimeMillis() - nStart);
899+
LogPrintf("Loaded info from masternodes.dat %dms\n", GetTimeMillis() - nStart);
900+
LogPrintf(" %s\n", mnodeman.ToString());
899901

900902

901903
fMasterNode = GetBoolArg("-masternode", false);

src/instantx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
3737
if(fLiteMode) return; //disable all darksend/masternode related functionality
3838
if(!IsSporkActive(SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT)) return;
3939
if(IsInitialBlockDownload()) return;
40-
40+
4141
if (strCommand == "txlreq")
4242
{
4343
//LogPrintf("ProcessMessageInstantX::txlreq\n");

src/main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool fLimitFree,
762762
LogPrint("mempool", "AcceptToMemoryPool : accepted %s (poolsz %u)\n",
763763
hash.ToString(),
764764
pool.mapTx.size());
765+
765766
return true;
766767
}
767768

@@ -791,6 +792,7 @@ bool AcceptableInputs(CTxMemPool& pool, const CTransaction &txo, bool fLimitFree
791792
return error("AcceptableInputs : nonstandard transaction: %s",
792793
reason);
793794

795+
794796
// is it already in the memory pool?
795797
uint256 hash = tx.GetHash();
796798
if (pool.exists(hash))
@@ -887,9 +889,10 @@ bool AcceptableInputs(CTxMemPool& pool, const CTransaction &txo, bool fLimitFree
887889
}
888890

889891

890-
LogPrint("mempool", "AcceptableInputs : accepted %s (poolsz %u)\n",
892+
/*LogPrint("mempool", "AcceptableInputs : accepted %s (poolsz %u)\n",
891893
hash.ToString(),
892894
pool.mapTx.size());
895+
*/
893896
return true;
894897
}
895898

@@ -3719,7 +3722,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
37193722
CTransaction tx;
37203723

37213724
//masternode signed transaction
3722-
bool allowFree = false;
3725+
//bool allowFree = false;
37233726
CTxIn vin;
37243727
vector<unsigned char> vchSig;
37253728
int64_t sigTime;
@@ -3750,7 +3753,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
37503753

37513754
LogPrintf("dstx: Got Masternode transaction %s\n", tx.GetHash().ToString().c_str());
37523755

3753-
allowFree = true;
3756+
//allowFree = true;
37543757
pmn->allowFreeTx = false;
37553758

37563759
if(!mapDarksendBroadcastTxes.count(tx.GetHash())){

src/masternode.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ CMasternode::CMasternode()
135135
pubkey2 = CPubKey();
136136
sig = std::vector<unsigned char>();
137137
activeState = MASTERNODE_ENABLED;
138-
now = GetTime();
138+
sigTime = GetAdjustedTime();
139139
lastDseep = 0;
140140
lastTimeSeen = 0;
141141
cacheInputAge = 0;
@@ -155,7 +155,7 @@ CMasternode::CMasternode(const CMasternode& other)
155155
pubkey2 = other.pubkey2;
156156
sig = other.sig;
157157
activeState = other.activeState;
158-
now = other.now;
158+
sigTime = other.sigTime;
159159
lastDseep = other.lastDseep;
160160
lastTimeSeen = other.lastTimeSeen;
161161
cacheInputAge = other.cacheInputAge;
@@ -166,7 +166,7 @@ CMasternode::CMasternode(const CMasternode& other)
166166
nLastDsq = other.nLastDsq;
167167
}
168168

169-
CMasternode::CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std::vector<unsigned char> newSig, int64_t newNow, CPubKey newPubkey2, int protocolVersionIn)
169+
CMasternode::CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std::vector<unsigned char> newSig, int64_t newSigTime, CPubKey newPubkey2, int protocolVersionIn)
170170
{
171171
LOCK(cs);
172172
vin = newVin;
@@ -175,7 +175,7 @@ CMasternode::CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std:
175175
pubkey2 = newPubkey2;
176176
sig = newSig;
177177
activeState = MASTERNODE_ENABLED;
178-
now = newNow;
178+
sigTime = newSigTime;
179179
lastDseep = 0;
180180
lastTimeSeen = 0;
181181
cacheInputAge = 0;
@@ -232,7 +232,8 @@ void CMasternode::Check()
232232
tx.vout.push_back(vout);
233233

234234
//if(!AcceptableInputs(mempool, state, tx)){
235-
bool* pfMissingInputs = false;
235+
bool* pfMissingInputs = new bool;
236+
*pfMissingInputs = false;
236237
if(!AcceptableInputs(mempool, tx, false, pfMissingInputs)){
237238
activeState = MASTERNODE_VIN_SPENT;
238239
return;
@@ -379,6 +380,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
379380
LOCK(cs_masternodes);
380381
if(!enabled) return false;
381382
CMasternodePaymentWinner newWinner;
383+
int nEnabled = mnodeman.CountEnabled();
382384

383385
std::vector<CTxIn> vecLastPayments;
384386
BOOST_REVERSE_FOREACH(CMasternodePaymentWinner& winner, vWinning)
@@ -389,8 +391,9 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
389391
vecLastPayments.push_back(winner.vin);
390392
}
391393

392-
CMasternode* pmn = mnodeman.FindNotInVec(vecLastPayments);
393-
if(pmn != NULL)
394+
// pay to the oldest MN that still had no payment but its input is old enough and it was active long enough
395+
CMasternode *pmn = mnodeman.FindOldestNotInVec(vecLastPayments);
396+
if(pmn != NULL && pmn->GetMasternodeInputAge() > nEnabled && pmn->lastTimeSeen - pmn->sigTime > nEnabled * 2.5 * 60)
394397
{
395398
newWinner.score = 0;
396399
newWinner.nBlockHeight = nBlockHeight;
@@ -399,7 +402,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
399402
}
400403

401404
//if we can't find new MN to get paid, pick first active MN counting back from the end of vecLastPayments list
402-
if(newWinner.nBlockHeight == 0 && mnodeman.CountEnabled() > 0)
405+
if(newWinner.nBlockHeight == 0 && nEnabled > 0)
403406
{
404407
BOOST_REVERSE_FOREACH(CTxIn& vinLP, vecLastPayments)
405408
{

0 commit comments

Comments
 (0)