Skip to content

Commit

Permalink
Merge remote-tracking branch 'gh/development' into coinstakelimit
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbrod committed Aug 28, 2018
2 parents 7f6dca8 + 5d0e29e commit 61cf036
Show file tree
Hide file tree
Showing 77 changed files with 30,501 additions and 11,451 deletions.
71 changes: 50 additions & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3100,7 +3100,6 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck, boo
int64_t nValueOut = 0;
int64_t nStakeReward = 0;
unsigned int nSigOps = 0;
double DPOR_Paid = 0;

bool bIsDPOR = false;

Expand Down Expand Up @@ -3222,8 +3221,8 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck, boo
MiningCPID bb = DeserializeBoincBlock(vtx[0].hashBoinc,nVersion);
uint64_t nCoinAge = 0;

double dStakeReward = CoinToDouble(nStakeReward+nFees) - DPOR_Paid; //DPOR Recipients checked above already
double dStakeRewardWithoutFees = CoinToDouble(nStakeReward) - DPOR_Paid;
double dStakeReward = CoinToDouble(nStakeReward+nFees);
double dStakeRewardWithoutFees = CoinToDouble(nStakeReward);

if (fDebug) LogPrintf("Stake Reward of %f B %f I %f F %.f %s %s ",
dStakeReward,bb.ResearchSubsidy,bb.InterestSubsidy,(double)nFees,bb.cpid, bb.Organization);
Expand Down Expand Up @@ -3331,9 +3330,9 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck, boo

if ((bb.ResearchSubsidy + bb.InterestSubsidy + dDrift) < dStakeRewardWithoutFees)
{
return DoS(20, error("ConnectBlock[] : Researchers Interest %f + Research %f + TimeDrift %f and total Mint %f, [StakeReward] <> %f, with Out_Interest %f, OUT_POR %f, Fees %f, DPOR %f for CPID %s does not match calculated research subsidy",
(double)bb.InterestSubsidy,(double)bb.ResearchSubsidy,dDrift,CoinToDouble(mint),dStakeRewardWithoutFees,
(double)OUT_INTEREST,(double)OUT_POR,CoinToDouble(nFees),(double)DPOR_Paid,bb.cpid.c_str()));
return DoS(20, error("ConnectBlock[] : Researchers Interest %f + Research %f + TimeDrift %f and total Mint %f, [StakeReward] <> %f, with Out_Interest %f, OUT_POR %f, Fees %f, for CPID %s does not match calculated research subsidy",
bb.InterestSubsidy,bb.ResearchSubsidy,dDrift,CoinToDouble(mint),dStakeRewardWithoutFees,
OUT_INTEREST,OUT_POR,CoinToDouble(nFees),bb.cpid.c_str()));

}

Expand Down Expand Up @@ -3392,19 +3391,30 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck, boo
if (fTestNet || (pindex->nHeight > 975000)) return DoS(20, error(" %s ",sNarr.c_str()));
}

/* ignore bad blocks already in chain on testnet */
const std::set<uint256> badSignBlocksTestnet =
{ uint256("129ae6779d620ec189f8e5148e205efca2dfe31d9f88004b918da3342157b7ff") //T407024
,uint256("c3f85818ba5290aaea1bcbd25b4e136f83acc93999942942bbb25aee2c655f7a") //T407068
,uint256("cf7f1316f92547f611852cf738fc7a4a643a2bb5b9290a33cd2f9425f44cc3f9") //T407099
,uint256("b47085beb075672c6f20d059633d0cad4dba9c5c20f1853d35455b75dc5d54a9") //T407117
,uint256("5a7d437d15bccc41ee8e39143e77960781f3dcf08697a888fa8c4af8a4965682") //T407161
,uint256("aeb3c24277ae1047bda548975a515e9d353d6e12a2952fb733da03f92438fb0f") //T407181
,uint256("fc584b18239f3e3ea78afbbd33af7c6a29bb518b8299f01c1ed4b52d19413d4f") //T407214
,uint256("d5441f7c35eb9ea1b786bbbed820b7f327504301ae70ef2ac3ca3cbc7106236b") //T479114
};
if (dStakeReward > ((OUT_POR*1.25)+OUT_INTEREST+1+CoinToDouble(nFees)))
{
StructCPID st1 = GetLifetimeCPID(pindex->GetCPID(),"ConnectBlock()");
GetProofOfStakeReward(nCoinAge, nFees, bb.cpid, true, 2, nTime,
pindex, "connectblock_researcher_doublecheck", OUT_POR, OUT_INTEREST, dAccrualAge, dMagnitudeUnit, dAvgMagnitude);
if (dStakeReward > ((OUT_POR*1.25)+OUT_INTEREST+1+CoinToDouble(nFees)))
{

if (fDebug3) LogPrintf("ConnectBlockError[ResearchAge] : Researchers Reward Pays too much : Interest %f and Research %f and StakeReward %f, OUT_POR %f, with Out_Interest %f for CPID %s ",
(double)bb.InterestSubsidy,(double)bb.ResearchSubsidy,dStakeReward,(double)OUT_POR,(double)OUT_INTEREST,bb.cpid);

return DoS(10,error("ConnectBlock[ResearchAge] : Researchers Reward Pays too much : Interest %f and Research %f and StakeReward %f, OUT_POR %f, with Out_Interest %f for CPID %s ",
(double)bb.InterestSubsidy,(double)bb.ResearchSubsidy,dStakeReward,(double)OUT_POR,(double)OUT_INTEREST,bb.cpid.c_str()));
if(!fTestNet || badSignBlocksTestnet.count(pindex->GetBlockHash()) ==0)
{
return DoS(10,error("ConnectBlock[ResearchAge] : Researchers Reward Pays too much : Interest %f and Research %f and StakeReward %f, OUT_POR %f, with Out_Interest %f for CPID %s ",
(double)bb.InterestSubsidy,(double)bb.ResearchSubsidy,dStakeReward,(double)OUT_POR,(double)OUT_INTEREST,bb.cpid.c_str()));
}
else LogPrintf("WARNING: ignoring Researchers Reward Pays too Much on block %s", pindex->GetBlockHash().ToString());
}
}
}
Expand Down Expand Up @@ -5305,8 +5315,8 @@ bool WriteKey(std::string sKey, std::string sValue)
fWritten=true;
}
}
sLine = strReplace(sLine, "\r", "");
sLine = strReplace(sLine, "\n", "");
sLine = strReplace(sLine,"\r","");
sLine = strReplace(sLine,"\n","");
sLine += "\n";
sConfig += sLine;
}
Expand Down Expand Up @@ -7082,6 +7092,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
else if (neural_request=="neural_hash")
{
if(0==neural_request_id.compare(0,13,"supercfwd.rqa"))
{
std::string r_hash; vRecv >> r_hash;
supercfwd::SendResponse(pfrom,r_hash);
}
else
pfrom->PushMessage("hash_nresp", NN::GetNeuralHash());
}
else if (neural_request=="explainmag")
Expand All @@ -7094,6 +7110,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// 7-12-2015 Resolve discrepencies in w nodes to speak to each other
pfrom->PushMessage("quorum_nresp", NN::GetNeuralContract());
}
else if (neural_request=="supercfwdr")
{
// this command could be done by reusing quorum_nresp, but I do not want to confuse the NN
supercfwd::QuorumResponseHook(pfrom,neural_request_id);
}
}
else if (strCommand == "ping")
{
Expand Down Expand Up @@ -7179,6 +7200,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// nNeuralNonce must match request ID
pfrom->NeuralHash = neural_response;
if (fDebug10) LogPrintf("hash_Neural Response %s ",neural_response);

// Hook into miner for delegated sb staking
supercfwd::HashResponseHook(pfrom, neural_response);
}
else if (strCommand == "expmag_nresp")
{
Expand All @@ -7204,6 +7228,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
results = NN::ExecuteDotNetStringFunction("ResolveDiscrepancies",neural_contract);
if (fDebug && !results.empty()) LogPrintf("Quorum Resolution: %s ",results);
}

// Hook into miner for delegated sb staking
supercfwd::QuorumResponseHook(pfrom,neural_contract);
}
else if (strCommand == "ndata_nresp")
{
Expand Down Expand Up @@ -7621,13 +7648,13 @@ std::string strReplace(std::string& str, const std::string& oldStr, const std::s
{
assert(oldStr.empty() == false && "Cannot replace an empty string");

size_t pos = 0;
size_t pos = 0;
while((pos = str.find(oldStr, pos)) != std::string::npos)
{
str.replace(pos, oldStr.length(), newStr);
pos += newStr.length();
}
return str;
str.replace(pos, oldStr.length(), newStr);
pos += newStr.length();
}
return str;
}

std::string LowerUnderscore(std::string data)
Expand Down Expand Up @@ -7786,7 +7813,7 @@ void HarvestCPIDs(bool cleardata)
int64_t elapsed = GetTimeMillis()-nStart;
if (fDebug3)
LogPrintf("Enumerating boinc local project %s cpid %s valid %s, elapsed %" PRId64, structcpid.projectname, structcpid.cpid, YesNo(structcpid.Iscpidvalid), elapsed);

structcpid.rac = RoundFromString(rac,0);
structcpid.verifiedrac = RoundFromString(rac,0);
std::string sLocalClientEmailHash = RetrieveMd5(email);
Expand Down Expand Up @@ -8401,9 +8428,9 @@ bool MemorizeMessage(const CTransaction &tx, double dAmount, std::string sRecipi

if(fDebug)
WriteCache("TrxID;"+sMessageType,sMessageKey,tx.GetHash().GetHex(),nTime);
}
}
}
}

return fMessageLoaded;
}
Expand Down Expand Up @@ -8525,6 +8552,8 @@ int64_t ComputeResearchAccrual(int64_t nTime, std::string cpid, std::string oper
{
if(fDebug) LogPrintf("ComputeResearchAccrual: %s Block Span less than 10 (%d) -> Accrual 0 (would be %f)", cpid, iRABlockSpan, Accrual/(double)COIN);
if(fDebug2) LogPrintf(" pHistorical w %s", pHistorical->GetBlockHash().GetHex());

// Note that if the RA Block Span < 10, we want to return 0 for the Accrual Amount so the CPID can still receive an accurate accrual in the future
return 0;
}

Expand Down
Loading

0 comments on commit 61cf036

Please sign in to comment.