Skip to content

Commit

Permalink
3.5.8.3-leisure
Browse files Browse the repository at this point in the history
Gridcoin Research 3.5.8.3/MSI=41.8
Leisure Upgrade

- Remove legacy hardcoded hashes and unused functions (lower memory
consumption), remove millisleeps (attempt to prevent UI blocks), remove
Option functions
- Add legacy code that allows 1000 blocks to be loaded (this is an
attempt to bring back our fast syncing) and to help the ARM sync
- Attempt to improve arm syncing
- Remove peek cache (lower memory consumption)
- Made magnitude vote weight Total Money Supply / 5.67 * Magnitude
  • Loading branch information
gridcoin committed Nov 21, 2016
1 parent 4fd5fa2 commit 957ab56
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 651 deletions.
2 changes: 1 addition & 1 deletion Makefile.Debug
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: gridcoinresearch
# Generated by qmake (2.01a) (Qt 4.8.4) on: Tue Nov 1 19:00:49 2016
# Generated by qmake (2.01a) (Qt 4.8.4) on: Mon Nov 21 07:13:32 2016
# Project: gridcoinresearch.pro
# Template: app
#############################################################################
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Release
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: gridcoinresearch
# Generated by qmake (2.01a) (Qt 4.8.4) on: Tue Nov 1 19:00:49 2016
# Generated by qmake (2.01a) (Qt 4.8.4) on: Mon Nov 21 07:13:34 2016
# Project: gridcoinresearch.pro
# Template: app
#############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@
"Manufacturer" = "8:GridcoinResearch"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
"Title" = "8:Gridcoin Research 41.7"
"Title" = "8:Gridcoin Research 41.8"
"Subject" = "8:"
"ARPCONTACT" = "8:The Gridcoin Developers"
"Keywords" = "8:Gridcoin Research"
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define CLIENT_VERSION_MAJOR 3
#define CLIENT_VERSION_MINOR 5
#define CLIENT_VERSION_REVISION 8
#define CLIENT_VERSION_BUILD 2
#define CLIENT_VERSION_BUILD 3

// Converts the parameter X to a string after macro replacement on X has been performed.
// Don't merge these into one macro!
Expand Down
506 changes: 106 additions & 400 deletions src/main.cpp

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ static const unsigned int MAX_STANDARD_TX_SIZE = MAX_BLOCK_SIZE_GEN/5;
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
/** The maximum number of orphan transactions kept in memory */
static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
/** The maximum number of orphan blocks kept in memory */
static const unsigned int MAX_ORPHAN_BLOCKS = 750;
/** The maximum number of entries in an 'inv' protocol message */
static const unsigned int MAX_INV_SZ = 50000;
/** Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) */
Expand Down Expand Up @@ -165,9 +163,9 @@ extern int64_t nTransactionFee;
extern int64_t nReserveBalance;
extern int64_t nMinimumInputValue;
extern int64_t nLastTallied;
extern int64_t nLastResync;
extern int64_t nLastPing;
extern int64_t nLastAskedForBlocks;
extern int64_t nBootup;
extern int64_t nLastCalculatedMedianTimePast;
extern double nLastBlockAge;
extern int64_t nLastCalculatedMedianPeerCount;
Expand Down Expand Up @@ -217,7 +215,6 @@ extern std::string msAttachmentGuid;

extern std::string msMiningErrorsIncluded;
extern std::string msMiningErrorsExcluded;
extern std::string msSuperBlockHashes;
extern std::string msContracts;

extern std::string msRSAOverview;
Expand Down
16 changes: 7 additions & 9 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int64_t* pFees)
if (!bNetAveragesLoaded)
{
if (fDebug10) printf("CNB: Net averages not yet loaded...");
MilliSleep(1000);
MilliSleep(1);
return NULL;
}

if (OutOfSyncByAgeWithChanceOfMining())
{
if (msPrimaryCPID != "INVESTOR") printf("Wallet out of sync - unable to mine...");
MilliSleep(500);
MilliSleep(1);
return NULL;
}

Expand Down Expand Up @@ -880,7 +880,7 @@ void StakeMiner(CWallet *pwallet)
{
nLastCoinStakeSearchInterval = 0;
fTryToSync = true;
MilliSleep(5000);
MilliSleep(1);
if (fShutdown)
{
printf("StakeMiner:Exiting(InitialBlockDownload)");
Expand All @@ -893,15 +893,13 @@ void StakeMiner(CWallet *pwallet)
fTryToSync = false;
if (vNodes.size() < 3 || nBestHeight < GetNumBlocksOfPeers())
{
if (fDebug10) printf("tryingtosync.");
MilliSleep(5000);
MilliSleep(1);
continue;
}
}
Begin:

if (GetArg("-fullbore", "false") != "true") MilliSleep(1000);


//
// Create new block
//
Expand All @@ -912,7 +910,7 @@ void StakeMiner(CWallet *pwallet)
{
//This can happen after reharvesting CPIDs... Because CreateNewBlock() requires a valid CPID.. Start Over.
if (fDebug10) printf(".StakeMiner Starting.");
MilliSleep(1000);
MilliSleep(1);
goto Begin;
}

Expand All @@ -922,7 +920,7 @@ void StakeMiner(CWallet *pwallet)
if (IsLockTimeWithinMinutes(nLastBlockSolved,5))
{
if (fDebug10) printf("=");
MilliSleep(500);
MilliSleep(1);
goto Begin;
}

Expand Down
9 changes: 4 additions & 5 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ std::string GetCommandNonce(std::string command)
void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd, bool fForce)
{
// The line of code below is the line of code that kept us from syncing to the best block (fForce forces the sync to continue).
if (!fForce && pindexBegin == pindexLastGetBlocksBegin && hashEnd == hashLastGetBlocksEnd) return; // Filter out duplicate requests
if (pindexBegin == pindexLastGetBlocksBegin && hashEnd == hashLastGetBlocksEnd) return; // Filter out duplicate requests
pindexLastGetBlocksBegin = pindexBegin;
hashLastGetBlocksEnd = hashEnd;
PushMessage("getblocks", CBlockLocator(pindexBegin), hashEnd);
Expand Down Expand Up @@ -2064,8 +2064,8 @@ void BusyWaitForTally()
int iTimeout = 0;
while(!bTallyFinished)
{
MilliSleep(10);
iTimeout+=10;
MilliSleep(1);
iTimeout+=1;
if (iTimeout > 15000) break;
}
nLastTallyBusyWait = GetAdjustedTime();
Expand Down Expand Up @@ -2116,8 +2116,7 @@ void ExecGridcoinServices(void* parg)
if (bExecuteGridcoinServices)
{
bExecuteGridcoinServices=false;
//GridcoinServices();
}
}
}
vnThreadsRunning[THREAD_SERVICES]--;
}
Expand Down
11 changes: 0 additions & 11 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,17 +740,6 @@ void CheckForUpgrade()
}


void BusyWait()
{
for (int x=0; x<50; x++)
{
if (bGlobalcomInitialized) return;
MilliSleep(100);
}

}


int64_t IsNeural()
{
if (!bGlobalcomInitialized) return 0;
Expand Down
183 changes: 3 additions & 180 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ extern bool UserAcknowledgedHoldHarmlessClause(std::string sAddress);
std::string ConvertBinToHex(std::string a);
std::string ConvertHexToBin(std::string a);
bool TallyResearchAverages(bool Forcefully);
void ReloadBlockIndexHot();
int RestartClient();
void SyncChain();
extern bool VerifyUnderlyingPrice(double UL, int64_t timestamp);
std::vector<unsigned char> StringToVector(std::string sData);
extern std::string SignBlockWithCPID(std::string sCPID, std::string sBlockHash);
Expand Down Expand Up @@ -1915,16 +1913,6 @@ Value execute(const Array& params, bool fHelp)
entry.push_back(Pair("Result",fResult));
results.push_back(entry);
}
else if (sItem == "syncchain")
{
SyncChain();
entry.push_back(Pair("SyncChain",1));
results.push_back(entry);
}
else if (sItem == "reloadblockindex")
{
ReloadBlockIndexHot();
}
else if (sItem=="burn")
{
if (params.size() < 5)
Expand Down Expand Up @@ -2781,38 +2769,6 @@ Value execute(const Array& params, bool fHelp)
}
}

}
else if (sItem == "scholes")
{
if (params.size() != 6)
{
entry.push_back(Pair("Error","You must specify Underlying Price, Strike, Type, Days, Volatility; For example: scholes 1880 300 put 365 .30"));
results.push_back(entry);
}
else
{
double UL = cdbl(params[1].get_str(),2);
double strike = cdbl(params[2].get_str(),0);
std::string sType = params[3].get_str();
double days = cdbl(params[4].get_str(),0);
double volatility = cdbl(params[5].get_str(),6);

if (strike == 0 || ( sType != "c" && sType != "p" ) || days == 0 || UL == 0 || volatility == 0)
{
entry.push_back(Pair("Error","You must specify a strike, a c or p, days, underlying price and volatility."));
results.push_back(entry);
}
double fractional_year = days/365;
double price = BlackScholes(sType, UL, strike, fractional_year, nRiskFreeRate, volatility);
double delta = GetDelta(sType, UL, strike, fractional_year, nRiskFreeRate, volatility);
entry.push_back(Pair("Price",price));
entry.push_back(Pair("Delta",delta));
std::string sHistory = "1900;3000;2900;2800;2700;2300;1900;1880;1880;1800;1780";
double dVol = GetVolatility(sHistory);
entry.push_back(Pair("Volatility",dVol));
results.push_back(entry);
}

}
else if (sItem == "addpoll")
{
Expand Down Expand Up @@ -4242,7 +4198,9 @@ double PollCalculateShares(std::string contract, double sharetype, double MoneyS
if (sharetype==2) return balance/VoteAnswerCount;
if (sharetype==3)
{
double UserWeightedMagnitude = MoneySupplyFactor*magnitude;
// https://github.com/gridcoin/Gridcoin-Research/issues/87#issuecomment-253999878
// Researchers weight is Total Money Supply / 5.67 * Magnitude
double UserWeightedMagnitude = (MoneySupplyFactor/5.67) * magnitude;
return (UserWeightedMagnitude+balance) / VoteAnswerCount;
}
if (sharetype==4)
Expand Down Expand Up @@ -4525,141 +4483,6 @@ Array GetJSONPollsReport(bool bDetail, std::string QueryByTitle, std::string& ou
}


int ValidateContract(int64_t iPurchaseTime, std::string sType, std::string sSerialNo,
double dPurchasePrice, std::string sOptionType, double UL, double dStrike, double dOptionLength, double dSingleOption)
{
//1-17-2016
// Validate the original option purchase price against original fair value
// -4 = Invalid UL Price at time Option was Purchased
// -3 = Invalid Reverse Engineered Price
// -2 = Burn sent to wrong address
// -1 = Purchase price differs from contract price
// 0 = Valid
std::string sRecipient = ReadCache(sType, sSerialNo + ";Recipient");
double dBurnAmount = cdbl(ReadCache(sType, sSerialNo + ";BurnAmount"),0);
dPurchasePrice = cdbl(RoundToString(dPurchasePrice,0),0);
// First verify they actually burned the amount paid for the option
if (dBurnAmount != dPurchasePrice) return -1;
// Verify the Paid GRC went to the Burn address
if (sRecipient != GetBurnAddress()) return -2;
double dTimeAnnualized = dOptionLength/365;
// Verify the UL price of GRC the date they purchased the contract
bool bPriceVerified = VerifyUnderlyingPrice(UL, iPurchaseTime);
if (!bPriceVerified) return -4;
// Next reverse engineer the option and verify they bought the option they paid for
double dHistoricalPrice = BlackScholes(sOptionType, UL, dStrike, dTimeAnnualized, nRiskFreeRate, nVolatility);
if (!(dSingleOption > dHistoricalPrice-5 && dSingleOption < dHistoricalPrice+5)) return -3; // Invalid Price
return 0; // Success
}




Array GetOptionsExposureReport()
{
Array results;
Object entry;
entry.push_back(Pair("Report","Options Exposure 1.0"));
std::string datatype="option_buy";
std::string rows = "";
std::string row = "";
StructCPID stNet = mvNetwork["NETWORK"];
double UL = stNet.GRCQuote/10000000000 * 100000000;
entry.push_back(Pair("GRC UL",UL));
double dTotalDelta = 0;
double dTotalPL = 0;
double dTotalContracts = 0;

for(map<string,string>::iterator ii=mvApplicationCache.begin(); ii!=mvApplicationCache.end(); ++ii)
{
std::string key_name = (*ii).first;
if (key_name.length() > datatype.length())
{
if (key_name.substr(0,datatype.length())==datatype)
{
std::string contract = mvApplicationCache[(*ii).first];
std::string contract_serial = key_name.substr(datatype.length()+1,key_name.length()-datatype.length()-1);
std::string subkey = key_name.substr(datatype.length()+1,key_name.length()-datatype.length()-1);
printf(" opra %s",contract_serial.c_str());

//Verify contract is not expired, and is valid
int64_t iPurchaseTime = mvApplicationCacheTimestamp[key_name];
double dExpiration = cdbl(ExtractXML(contract,"<EXPIRATION>","</EXPIRATION>"),0);
std::string sOpra = ExtractXML(contract,"<SHORTOPRA>","</SHORTOPRA>");
std::string sAddress = ExtractXML(contract,"<GRCADDRESS>","</GRCADDRESS>");

printf(" addr %s opra %s expir %f pt %f ",sAddress.c_str(),sOpra.c_str(),(double)dExpiration,(double)iPurchaseTime);

double dDays = cdbl(ExtractXML(contract,"<DAYS>","</DAYS>"),4);
double dTimeLeft = (dExpiration - GetAdjustedTime())/86400;
double dTimeAnnualized = dTimeLeft/365;

bool bExpired = (dTimeLeft < 0);
std::string sType = ExtractXML(contract,"<TYPE>","</TYPE>");
printf(" days %f, Type %s, Time %f Time %f ",dDays,sType.c_str(),dTimeLeft,dTimeAnnualized);

double dStrike = cdbl(ExtractXML(contract,"<STRIKE>","</STRIKE>"),0);
std::string sAction = ExtractXML(contract,"<ACTION>","</ACTION>");
double dQuantity = cdbl(ExtractXML(contract,"<QUANTITY>","</QUANTITY>"),0);
std::string sExpiration = ExtractXML(contract,"<HREXPIRATION>","</HREXPIRATION>");
// calculate current delta based on current market conditions
double dPrice = cdbl(ExtractXML(contract,"<PRICE>","</PRICE>"),4);

printf(" price %f , strike %f action %s qty %f sexpiry %s",dPrice,dStrike,sAction.c_str(),dQuantity,sExpiration.c_str());

if (dPrice != 0 && !sOpra.empty())
{

printf(" delta 1 ");
double delta = -100 * (GetDelta(sType, UL, dStrike, dTimeAnnualized, nRiskFreeRate, nVolatility));
printf(" bs 1 ");
double dCurrentPrice = BlackScholes(sType, UL, dStrike, dTimeAnnualized, nRiskFreeRate, nVolatility);
printf (" bs 2 ");
double dPL = -1 * ( dCurrentPrice - dPrice );

entry.push_back(Pair("OPRA",sOpra));
entry.push_back(Pair("Strike",dStrike));
entry.push_back(Pair("Type",sType));
entry.push_back(Pair("Quantity",dQuantity));
entry.push_back(Pair("Expiration",dExpiration));
entry.push_back(Pair("HR Expiration",sExpiration));
entry.push_back(Pair("Purchase Price",dPrice));
entry.push_back(Pair("Delta",delta));
entry.push_back(Pair("Total Delta",delta*dQuantity));
entry.push_back(Pair("Expired",bExpired));

entry.push_back(Pair("Current Price",dCurrentPrice));
entry.push_back(Pair("PL",dPL));
entry.push_back(Pair("Total PL",dPL*dQuantity));
entry.push_back(Pair("TimeLeft",dTimeLeft));

std::string sRecipient = ReadCache(datatype,subkey + ";Recipient");
double dBurnAmount = cdbl(ReadCache(datatype,subkey + ";BurnAmount"),4);
entry.push_back(Pair("Recipient",sRecipient));
entry.push_back(Pair("Burnt",dBurnAmount));
printf(" validating ");

int valid = ValidateContract(iPurchaseTime,datatype,subkey,dPrice*dQuantity,sType,UL,dStrike,dDays,dPrice);
printf(" validated ");
entry.push_back(Pair("Valid",valid));
entry.push_back(Pair("",""));

dTotalDelta += (delta*dQuantity);
dTotalPL += (dPL*dQuantity);
dTotalContracts += dQuantity;
}

}
}
}
entry.push_back(Pair("Total Contracts",dTotalContracts));
entry.push_back(Pair("Total PL",dTotalPL));
entry.push_back(Pair("Total Deltas",dTotalDelta));

results.push_back(entry);
return results;

}



Expand Down
Loading

0 comments on commit 957ab56

Please sign in to comment.