Skip to content

Commit 209bc11

Browse files
authored
Merge pull request #1589 from cyrossignol/quorum
Remove legacy quorum messaging system (neural network)
2 parents 4910488 + 12ab976 commit 209bc11

15 files changed

+19
-492
lines changed

src/main.cpp

+13-191
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ extern std::string NodeAddress(CNode* pfrom);
4343
extern bool WalletOutOfSync();
4444
bool AdvertiseBeacon(std::string &sOutPrivKey, std::string &sOutPubKey, std::string &sError, std::string &sMessage);
4545
extern void CleanInboundConnections(bool bClearAll);
46-
bool RequestSupermajorityNeuralData();
4746
extern bool AskForOutstandingBlocks(uint256 hashStart);
4847
extern void ResetTimerMain(std::string timer_name);
4948
extern void IncrementCurrentNeuralNetworkSupermajority(const NN::QuorumHash& quorum_hash, std::string GRCAddress, double distance);
50-
extern double ExtractMagnitudeFromExplainMagnitude();
5149
extern void GridcoinServices();
5250
extern bool StrLessThanReferenceHash(std::string rh);
5351
extern bool IsContract(CBlockIndex* pIndex);
@@ -57,9 +55,6 @@ extern void IncrementVersionCount(const std::string& Version);
5755
extern bool LoadAdminMessages(bool bFullTableScan,std::string& out_errors);
5856
extern std::string GetCurrentNeuralNetworkSupermajorityHash(double& out_popularity);
5957

60-
bool AsyncNeuralRequest(std::string command_name,std::string cpid,int NodeLimit);
61-
extern bool FullSyncWithDPORNodes();
62-
6358
extern bool GetEarliestStakeTime(std::string grcaddress, std::string cpid);
6459
extern double GetTotalBalance();
6560
extern std::string PubKeyToAddress(const CScript& scriptPubKey);
@@ -181,7 +176,6 @@ std::string msMiningErrors7;
181176
std::string msMiningErrors8;
182177
std::string msMiningErrorsIncluded;
183178
std::string msMiningErrorsExcluded;
184-
std::string msNeuralResponse;
185179
std::string msHDDSerial;
186180
//When syncing, we grandfather block rejection rules up to this block, as rules became stricter over time and fields changed
187181

@@ -227,28 +221,6 @@ bool TimerMain(std::string timer_name, int max_ms)
227221
return false;
228222
}
229223

230-
bool FullSyncWithDPORNodes()
231-
{
232-
if(!NN::GetInstance()->IsEnabled())
233-
return false;
234-
// 3-30-2016 : First try to get the master database from another neural network node if these conditions occur:
235-
// The foreign node is fully synced. The foreign nodes quorum hash matches the supermajority hash. My hash != supermajority hash.
236-
double dCurrentPopularity = 0;
237-
std::string sCurrentNeuralSupermajorityHash = GetCurrentNeuralNetworkSupermajorityHash(dCurrentPopularity);
238-
std::string sMyNeuralHash = NN::GetInstance()->GetNeuralHash();
239-
if (!sMyNeuralHash.empty() && sMyNeuralHash != sCurrentNeuralSupermajorityHash)
240-
{
241-
bool bNodeOnline = RequestSupermajorityNeuralData();
242-
if (bNodeOnline)
243-
return false; // Async call to another node will continue after the node responds.
244-
}
245-
246-
std::string errors1;
247-
LoadAdminMessages(false,errors1);
248-
NN::GetInstance()->SynchronizeDPOR(GetConsensusBeaconList());
249-
return true;
250-
}
251-
252224
double GetEstimatedNetworkWeight(unsigned int nPoSInterval)
253225
{
254226
// The number of stakes to include in the average has been reduced to 40 (default) from 72. 72 stakes represented 1.8 hours at
@@ -3620,57 +3592,6 @@ void GridcoinServices()
36203592
LogPrintf("Daily backup results: Wallet -> %s Config -> %s", (bWalletBackupResults ? "true" : "false"), (bConfigBackupResults ? "true" : "false"));
36213593
}
36223594

3623-
if (TimerMain("MyNeuralMagnitudeReport",30))
3624-
{
3625-
try
3626-
{
3627-
std::string primary_cpid = NN::GetPrimaryCpid();
3628-
3629-
if (msNeuralResponse.length() < 25 && IsResearcher(primary_cpid))
3630-
{
3631-
AsyncNeuralRequest("explainmag", primary_cpid, 5);
3632-
if (fDebug3) LogPrintf("Async explainmag sent for %s.", primary_cpid);
3633-
}
3634-
if (fDebug3) LogPrintf("MR Complete");
3635-
}
3636-
catch (std::exception &e)
3637-
{
3638-
LogPrintf("Error in MyNeuralMagnitudeReport1.");
3639-
}
3640-
catch(...)
3641-
{
3642-
LogPrintf("Error in MyNeuralMagnitudeReport.");
3643-
}
3644-
}
3645-
3646-
// Every N blocks as a Synchronized TEAM:
3647-
if ((nBestHeight % 30) == 0)
3648-
{
3649-
//Sync RAC with neural network IF superblock is over 24 hours Old, Or if we have No superblock (in case of the latter, age will be 45 years old)
3650-
// Note that nodes will NOT accept superblocks without a supermajority hash, so the last block will not be in memory unless it is a good superblock.
3651-
// Let's start syncing the neural network as soon as the LAST superblock is over 12 hours old.
3652-
// Also, lets do this as a TEAM exactly every 30 blocks (~30 minutes) to try to reach an EXACT consensus every half hour:
3653-
// For effeciency, the network sleeps for 20 hours after a good superblock is accepted
3654-
if (NN::Tally::SuperblockNeeded() && IsNeuralNodeParticipant(DefaultWalletAddress(), GetAdjustedTime()))
3655-
{
3656-
if (fDebug3) LogPrintf("FSWDPOR ");
3657-
FullSyncWithDPORNodes();
3658-
}
3659-
}
3660-
3661-
if (( (nBestHeight-10) % 30 ) == 0)
3662-
{
3663-
// 10 Blocks after the network started syncing the neural network as a team, ask the neural network to come to a quorum
3664-
if (NN::Tally::SuperblockNeeded() && IsNeuralNodeParticipant(DefaultWalletAddress(), GetAdjustedTime()))
3665-
{
3666-
// First verify my node has a synced contract
3667-
if (NN::GetInstance()->GetSuperblockContract().WellFormed())
3668-
{
3669-
AsyncNeuralRequest("quorum","gridcoin",25);
3670-
}
3671-
}
3672-
}
3673-
36743595
/* Do this only for users with valid CPID */
36753596
if (TimerMain("send_beacon", 180)) {
36763597
if (const NN::CpidOption cpid = NN::Researcher::Get()->Id().TryCpid()) {
@@ -3690,9 +3611,6 @@ void GridcoinServices()
36903611
}
36913612
}
36923613
}
3693-
3694-
if (TimerMain("gather_cpids",480))
3695-
msNeuralResponse.clear();
36963614
}
36973615

36983616
bool AskForOutstandingBlocks(uint256 hashStart)
@@ -4521,47 +4439,6 @@ std::string NodeAddress(CNode* pfrom)
45214439
return ip;
45224440
}
45234441

4524-
double ExtractMagnitudeFromExplainMagnitude()
4525-
{
4526-
if (msNeuralResponse.empty()) return 0;
4527-
try
4528-
{
4529-
std::vector<std::string> vMag = split(msNeuralResponse.c_str(),"<ROW>");
4530-
for (unsigned int i = 0; i < vMag.size(); i++)
4531-
{
4532-
if (Contains(vMag[i],"Total Mag:"))
4533-
{
4534-
std::vector<std::string> vMyMag = split(vMag[i].c_str(),":");
4535-
if (vMyMag.size() > 0)
4536-
{
4537-
std::string sSubMag = vMyMag[1];
4538-
boost::replace_all(sSubMag, " ", "");
4539-
double dMag = RoundFromString("0"+sSubMag,0);
4540-
return dMag;
4541-
}
4542-
}
4543-
}
4544-
return 0;
4545-
}
4546-
catch(...)
4547-
{
4548-
return 0;
4549-
}
4550-
return 0;
4551-
}
4552-
4553-
bool VerifyExplainMagnitudeResponse()
4554-
{
4555-
if (msNeuralResponse.empty())
4556-
return false;
4557-
4558-
double dMag = ExtractMagnitudeFromExplainMagnitude();
4559-
if (dMag==0)
4560-
msNeuralResponse.clear();
4561-
4562-
return dMag != 0;
4563-
}
4564-
45654442
bool SecurityTest(CNode* pfrom, bool acid_test)
45664443
{
45674444
if (pfrom->nStartingHeight > (nBestHeight*.5) && acid_test) return true;
@@ -4605,13 +4482,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
46054482
CAddress addrMe;
46064483
CAddress addrFrom;
46074484
uint64_t nNonce = 1;
4608-
std::string acid = "";
4609-
vRecv >> pfrom->nVersion >> pfrom->boinchashnonce >> pfrom->boinchashpw >> pfrom->cpid >> pfrom->enccpid >> acid >> pfrom->nServices >> nTime >> addrMe;
4485+
std::string legacy_dummy;
4486+
4487+
vRecv >> pfrom->nVersion
4488+
>> legacy_dummy // pfrom->boinchashnonce
4489+
>> legacy_dummy // pfrom->boinchashpw
4490+
>> legacy_dummy // pfrom->cpid
4491+
>> legacy_dummy // pfrom->enccpid
4492+
>> legacy_dummy // acid
4493+
>> pfrom->nServices
4494+
>> nTime
4495+
>> addrMe;
46104496

46114497
if (fDebug10)
4612-
LogPrintf("received aries version %i boinchashnonce %s boinchashpw %s cpid %s enccpid %s acid %s ..."
4613-
,pfrom->nVersion, pfrom->boinchashnonce, pfrom->boinchashpw
4614-
,pfrom->cpid.c_str(), pfrom->enccpid, acid);
4498+
LogPrintf("received aries version %i ...", pfrom->nVersion);
46154499

46164500
int64_t timedrift = std::abs(GetAdjustedTime() - nTime);
46174501

@@ -4669,7 +4553,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
46694553
// 12-5-2015 - Append Trust fields
46704554
pfrom->nTrust = 0;
46714555

4672-
if (!vRecv.empty()) vRecv >> pfrom->sGRCAddress;
4556+
if (!vRecv.empty()) vRecv >> legacy_dummy; // pfrom->sGRCAddress;
46734557

46744558

46754559
// Allow newbies to connect easily with 0 blocks
@@ -5267,33 +5151,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
52675151
if (!tracker.IsNull())
52685152
tracker.fn(tracker.param1, vRecv);
52695153
}
5270-
else if (strCommand == "neural")
5271-
{
5272-
std::string neural_request = "";
5273-
std::string neural_request_id = "";
5274-
vRecv >> neural_request >> neural_request_id; // foreign node issued neural request with request ID:
5275-
std::string neural_response = "generic_response";
5276-
5277-
if (neural_request=="neural_data")
5278-
{
5279-
pfrom->PushMessage("ndata_nresp", NN::GetInstance()->GetNeuralContract());
5280-
}
5281-
else if (neural_request=="neural_hash")
5282-
{
5283-
pfrom->PushMessage("hash_nresp", NN::GetInstance()->GetNeuralHash());
5284-
}
5285-
else if (neural_request=="explainmag")
5286-
{
5287-
pfrom->PushMessage(
5288-
"expmag_nresp",
5289-
NN::GetInstance()->ExplainMagnitude(neural_request_id));
5290-
}
5291-
else if (neural_request=="quorum")
5292-
{
5293-
// 7-12-2015 Resolve discrepencies in w nodes to speak to each other
5294-
pfrom->PushMessage("quorum_nresp", NN::GetInstance()->GetNeuralContract());
5295-
}
5296-
}
52975154
else if (strCommand == "ping")
52985155
{
52995156
std::string acid = "";
@@ -5371,41 +5228,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
53715228
pfrom->nPingNonceSent = 0;
53725229
}
53735230
}
5374-
else if (strCommand == "hash_nresp")
5375-
{
5376-
std::string neural_response = "";
5377-
vRecv >> neural_response;
5378-
// if (pfrom->nNeuralRequestSent != 0)
5379-
// nNeuralNonce must match request ID
5380-
pfrom->NeuralHash = neural_response;
5381-
if (fDebug10) LogPrintf("hash_Neural Response %s ",neural_response);
5382-
}
5383-
else if (strCommand == "expmag_nresp")
5384-
{
5385-
std::string neural_response = "";
5386-
vRecv >> neural_response;
5387-
if (neural_response.length() > 10)
5388-
{
5389-
msNeuralResponse=neural_response;
5390-
//If invalid, try again 10-20-2015
5391-
VerifyExplainMagnitudeResponse();
5392-
}
5393-
if (fDebug10) LogPrintf("expmag_Neural Response %s ",neural_response);
5394-
}
5395-
else if (strCommand == "quorum_nresp")
5396-
{
5397-
std::string neural_contract = "";
5398-
vRecv >> neural_contract;
5399-
if (fDebug && neural_contract.length() > 100) LogPrintf("Quorum contract received %s",neural_contract.substr(0,80));
5400-
}
5401-
else if (strCommand == "ndata_nresp")
5402-
{
5403-
std::string neural_contract;
5404-
vRecv >> neural_contract;
5405-
if (fDebug3 && neural_contract.length() > 100) LogPrintf("Quorum contract received %s",neural_contract.substr(0,80));
5406-
if (neural_contract.length() > 10)
5407-
FullSyncWithDPORNodes();
5408-
}
54095231
else if (strCommand == "alert")
54105232
{
54115233
CAlert alert;

src/main.h

-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ extern std::string msMiningErrors8;
198198
extern std::string msMiningErrorsIncluded;
199199
extern std::string msMiningErrorsExcluded;
200200

201-
extern std::string msNeuralResponse;
202201
extern std::string msHDDSerial;
203202
extern bool mbBlocksDownloaded;
204203
extern int nGrandfather;

src/net.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ void CNode::PushVersion()
724724
std::string sboinchashargs;
725725
std::string nonce;
726726
std::string pw1;
727-
std::string mycpid = "INVESTOR";
728-
std::string acid = GetCommandNonce("aries");
727+
std::string mycpid;
728+
std::string acid;
729729

730730
PushMessage("aries", PROTOCOL_VERSION, nonce, pw1,
731731
mycpid, mycpid, acid, nLocalServices, nTime, addrYou, addrMe,
@@ -809,7 +809,6 @@ void CNode::copyStats(CNodeStats &stats)
809809
stats.strSubVer = strSubVer;
810810
stats.fInbound = fInbound;
811811
stats.nStartingHeight = nStartingHeight;
812-
stats.sGRCAddress = sGRCAddress;
813812
stats.nTrust = nTrust;
814813
stats.nMisbehavior = GetMisbehavior();
815814

src/net.h

-12
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ class CNodeStats
149149
double dPingWait;
150150
std::string addrLocal;
151151
int nTrust;
152-
std::string sGRCAddress;
153-
//std::string securityversion;
154152
};
155153

156154

@@ -226,13 +224,6 @@ class CNode
226224
CService addrLocal;
227225
int nVersion;
228226
std::string strSubVer;
229-
std::string boinchashnonce;
230-
std::string boinchashpw;
231-
//12-10-2014 CPID Support
232-
std::string cpid;
233-
std::string enccpid;
234-
std::string NeuralHash;
235-
std::string sGRCAddress;
236227
int nTrust;
237228
////////////////////////
238229

@@ -307,7 +298,6 @@ class CNode
307298
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
308299
nVersion = 0;
309300
strSubVer = "";
310-
//securityversion = "";
311301
fOneShot = false;
312302
fClient = false; // set by version message
313303
fInbound = fInboundIn;
@@ -326,8 +316,6 @@ class CNode
326316
nLastOrphan=0;
327317
nOrphanCount=0;
328318
nOrphanCountViolations=0;
329-
NeuralHash = "";
330-
sGRCAddress = "";
331319
nTrust = 0;
332320
hashCheckpointKnown.SetNull();
333321
setInventoryKnown.max_size(SendBufferSize() / 1000);

src/neuralnet/neuralnet.h

-12
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ namespace NN
3333
//!
3434
virtual bool IsEnabled() = 0;
3535

36-
//!
37-
//! \brief Get application neural version.
38-
//!
39-
//! Fetches the application version with the neural network magic suffix
40-
//! (\c 1999) if the neural net is enabled.
41-
//!
42-
//! \return Current application version with proper neural suffix.
43-
//!
44-
virtual std::string GetNeuralVersion() = 0;
45-
4636
//!
4737
//! \brief Get current neural hash from neural net.
4838
//!
@@ -95,8 +85,6 @@ namespace NN
9585
virtual bool SynchronizeDPOR(const BeaconConsensus& beacons) = 0;
9686

9787
virtual std::string ExplainMagnitude(const std::string& cpid) = 0;
98-
99-
virtual int64_t IsNeuralNet() = 0;
10088
};
10189

10290
//!

0 commit comments

Comments
 (0)