Skip to content

Commit 508aa94

Browse files
Merge pull request #22 from adeptio-project/storADEchecker
storADE mechnism change
2 parents 5af8e42 + dcad3b6 commit 508aa94

File tree

6 files changed

+71
-8
lines changed

6 files changed

+71
-8
lines changed

src/activemasternode.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ void CActiveMasternode::ManageStatus()
120120

121121
LogPrintf("CActiveMasternode::ManageStatus() - Is capable master node!\n");
122122
status = ACTIVE_MASTERNODE_STARTED;
123+
startTime = GetAdjustedTime();
123124

124125
return;
125126
} else {
@@ -129,6 +130,22 @@ void CActiveMasternode::ManageStatus()
129130
}
130131
}
131132

133+
workTime = GetAdjustedTime() - startTime;
134+
notCheckedTime = GetAdjustedTime() - lastCheck;
135+
136+
if (workTime >= MASTERNODE_STORADE_START_SECONDS) {
137+
138+
if(notCheckedTime >= MASTERNODE_STORADE_CHECK_SECONDS) {
139+
140+
if(!StoradeIsEnabled()){
141+
142+
status = ACTIVE_MASTERNODE_STORADE_ERROR;
143+
144+
LogPrintf("CActiveMasternode::ManageStatus() - StorADE not working\n");
145+
}
146+
}
147+
}
148+
132149
//send to all peers
133150
if (!SendMasternodePing(errorMessage)) {
134151
LogPrintf("CActiveMasternode::ManageStatus() - Error on Ping: %s\n", errorMessage);
@@ -146,13 +163,40 @@ std::string CActiveMasternode::GetStatus()
146163
return strprintf("Masternode input must have at least %d confirmations", MASTERNODE_MIN_CONFIRMATIONS);
147164
case ACTIVE_MASTERNODE_NOT_CAPABLE:
148165
return "Not capable masternode: " + notCapableReason;
166+
case ACTIVE_MASTERNODE_STORADE_ERROR:
167+
return "StorADE working problem";
149168
case ACTIVE_MASTERNODE_STARTED:
150169
return "Masternode successfully started";
151170
default:
152171
return "unknown";
153172
}
154173
}
155174

175+
bool CActiveMasternode::StoradeIsEnabled()
176+
{
177+
SOCKET hSocket;
178+
CService storade = service;
179+
storade.SetPort(Params().GetStorADEdefaultPort());
180+
startTime = GetAdjustedTime();
181+
182+
if(!ConnectSocket(storade, hSocket, nConnectTimeout)) {
183+
184+
return false;
185+
186+
} else if(!IsSelectableSocket(hSocket)) {
187+
188+
CloseSocket(hSocket);
189+
190+
return false;
191+
192+
} else {
193+
194+
CloseSocket(hSocket);
195+
196+
return true;
197+
}
198+
}
199+
156200
bool CActiveMasternode::SendMasternodePing(std::string& errorMessage)
157201
{
158202
if (status != ACTIVE_MASTERNODE_STARTED) {
@@ -470,6 +514,7 @@ bool CActiveMasternode::EnableHotColdMasterNode(CTxIn& newVin, CService& newServ
470514
if (!fMasterNode) return false;
471515

472516
status = ACTIVE_MASTERNODE_STARTED;
517+
startTime = GetAdjustedTime();
473518

474519
//The values below are needed for signing mnping messages going forward
475520
vin = newVin;

src/activemasternode.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2014-2016 The Dash developers
2-
// Copyright (c) 2015-2017 The PIVX developers// Copyright (c) 2017-2019 The Adeptio developers
2+
// Copyright (c) 2015-2017 The PIVX developers
3+
// Copyright (c) 2017-2019 The Adeptio developers
34
// Distributed under the MIT/X11 software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -19,6 +20,7 @@
1920
#define ACTIVE_MASTERNODE_INPUT_TOO_NEW 2
2021
#define ACTIVE_MASTERNODE_NOT_CAPABLE 3
2122
#define ACTIVE_MASTERNODE_STARTED 4
23+
#define ACTIVE_MASTERNODE_STORADE_ERROR 5
2224

2325
// Responsible for activating the Masternode and pinging the network
2426
class CActiveMasternode
@@ -37,6 +39,8 @@ class CActiveMasternode
3739
bool GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex);
3840
bool GetVinFromOutput(COutput out, CTxIn& vin, CPubKey& pubkey, CKey& secretKey);
3941

42+
bool StoradeIsEnabled();
43+
4044
public:
4145
// Initialized by init.cpp
4246
// Keys for the main Masternode
@@ -47,11 +51,14 @@ class CActiveMasternode
4751
CService service;
4852

4953
int status;
54+
int64_t startTime;
55+
int64_t lastCheck;
5056
std::string notCapableReason;
5157

5258
CActiveMasternode()
5359
{
5460
status = ACTIVE_MASTERNODE_INITIAL;
61+
lastCheck = 0;
5562
}
5663

5764
/// Manage status of main Masternode

src/init.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
17821782
if (!addrTest.IsValid()) {
17831783
return InitError("Invalid -masternodeaddr address: " + strMasterNodeAddr);
17841784
}
1785+
if (addrTest.IsLocal()) {
1786+
return InitError("-masternodeaddr address is local: " + strMasterNodeAddr);
1787+
}
17851788
}
17861789

17871790
strMasterNodePrivKey = GetArg("-masternodeprivkey", "");

src/main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6673,15 +6673,18 @@ bool ProcessMessages(CNode* pfrom)
66736673
} else if (strstr(e.what(), "size too large")) {
66746674
// Allow exceptions from over-long size
66756675
LogPrintf("ProcessMessages(%s, %u bytes): Exception '%s' caught\n", SanitizeString(strCommand), nMessageSize, e.what());
6676+
} else if (strstr(e.what(), "non-canonical ReadCompactSize()")) {
6677+
// Allow exceptions from non-canonical encoding
6678+
LogPrintf("ProcessMessages(%s, %u bytes): Exception '%s' caught\n", SanitizeString(strCommand), nMessageSize, e.what());
66766679
} else {
6677-
PrintExceptionContinue(&e, "ProcessMessages()");
6680+
PrintExceptionContinue(&e, strprintf("ProcessMessages(%s, %u bytes)", SanitizeString(strCommand), nMessageSize));
66786681
}
66796682
} catch (boost::thread_interrupted) {
66806683
throw;
66816684
} catch (std::exception& e) {
6682-
PrintExceptionContinue(&e, "ProcessMessages()");
6685+
PrintExceptionContinue(&e, strprintf("ProcessMessages(%s, %u bytes)", SanitizeString(strCommand), nMessageSize));
66836686
} catch (...) {
6684-
PrintExceptionContinue(NULL, "ProcessMessages()");
6687+
PrintExceptionContinue(NULL, strprintf("ProcessMessages(%s, %u bytes)", SanitizeString(strCommand), nMessageSize));
66856688
}
66866689

66876690
if (!fRet)

src/masternode.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void CMasternode::Check(bool forceCheck)
201201
if (!forceCheck && (GetTime() - lastTimeChecked < MASTERNODE_CHECK_SECONDS)) return;
202202
lastTimeChecked = GetTime();
203203

204-
if (activeState == MASTERNODE_STORADE_EXPIRED) return;
204+
//if (activeState == MASTERNODE_STORADE_EXPIRED) return;
205205

206206
//once spent, stop doing the checks
207207
if (activeState == MASTERNODE_VIN_SPENT) return;
@@ -239,7 +239,9 @@ void CMasternode::Check(bool forceCheck)
239239
}
240240
}
241241
}
242-
// The "StorADE" service needs the correct default port to work properly
242+
243+
/*
244+
// The "StorADE" service needs the correct default port to work properly
243245
int64_t storADElastCheck = GetAdjustedTime() - storADElastTime;
244246
245247
if( (storADElastCheck >= 12 * 60 * 60) || (storADElastCheck >= 1 * 60 * 60 && activeState == MASTERNODE_STORADE_EXPIRED) ) {
@@ -266,7 +268,8 @@ void CMasternode::Check(bool forceCheck)
266268
} else if(block_height >= 0) // Start storADE in v2
267269
268270
threads.create_thread(boost::bind(&CMasternode::CheckStorADEport, this));
269-
}
271+
}*/
272+
270273
activeState = MASTERNODE_ENABLED; // OK
271274
}
272275

src/masternode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
#include "util.h"
1717

1818
#define MASTERNODE_MIN_CONFIRMATIONS 15
19-
#define MASTERNODE_MIN_MNP_SECONDS (10 * 60)
19+
#define MASTERNODE_MIN_MNP_SECONDS (15 * 60)
2020
#define MASTERNODE_MIN_MNB_SECONDS (5 * 60)
21+
#define MASTERNODE_STORADE_START_SECONDS (10 * 60)
22+
#define MASTERNODE_STORADE_CHECK_SECONDS (360 * 60)
2123
#define MASTERNODE_PING_SECONDS (5 * 60)
2224
#define MASTERNODE_EXPIRATION_SECONDS (120 * 60)
2325
#define MASTERNODE_REMOVAL_SECONDS (130 * 60)

0 commit comments

Comments
 (0)