Skip to content

Commit

Permalink
Merge pull request #171 from enkayz/master
Browse files Browse the repository at this point in the history
FSPFS Update
  • Loading branch information
metaspartan authored Dec 6, 2018
2 parents c2a5f31 + f6a333d commit 574d0e9
Show file tree
Hide file tree
Showing 19 changed files with 175 additions and 90 deletions.
9 changes: 7 additions & 2 deletions denarius-qt.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = Denarius
VERSION = 3.2.0.0
VERSION = 3.2.5.0
INCLUDEPATH += src src/json src/qt src/tor src/qt/plugins/mrichtexteditor
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE
CONFIG += no_include_pwd
Expand Down Expand Up @@ -87,6 +87,11 @@ contains(USE_PROFILER, 1) {
QMAKE_CXXFLAGS += -pg
}

contains(USE_DEBUG_FLAGS, 1) {
QMAKE_LFLAGS += -Og
QMAKE_CXXFLAGS += -Og
}

# use: qmake "USE_UPNP=1" ( enabled by default; default)
# or: qmake "USE_UPNP=0" (disabled by default)
# or: qmake "USE_UPNP=-" (not supported)
Expand Down Expand Up @@ -207,7 +212,7 @@ contains(USE_O3, 1) {
QMAKE_CFLAGS += -msse2
}

QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector
QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wno-ignored-qualifiers -Wno-format -Wno-unused-parameter -Wstack-protector


# Input
Expand Down
4 changes: 2 additions & 2 deletions src/activefortunastake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void CActiveFortunastake::ManageStatus()

if(GetFortunaStakeVin(vin, pubKeyCollateralAddress, keyCollateralAddress)) {

if(GetInputAge(vin) < (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)){
printf("CActiveFortunastake::ManageStatus() - Input must have least %d confirmations - %d confirmations\n", (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS), GetInputAge(vin));
if(GetInputAge(vin, pindexBest) < (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)){
printf("CActiveFortunastake::ManageStatus() - Input must have least %d confirmations - %d confirmations\n", (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS), GetInputAge(vin, pindexBest));
status = FORTUNASTAKE_INPUT_TOO_NEW;
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ static const CRPCCommand vRPCCommands[] =
{ "repairwallet", &repairwallet, false, true},
{ "resendtx", &resendtx, false, true},
{ "makekeypair", &makekeypair, false, true},
{ "setdebug", &setdebug, true, false },
{ "sendalert", &sendalert, false, false},
{ "gettxout", &gettxout, true, false },
{ "importaddress", &importaddress, false, false },
Expand Down
1 change: 1 addition & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fH
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value setdebug(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getsubsidy(const json_spirit::Array& params, bool fHelp);
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 3
#define CLIENT_VERSION_MINOR 2
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_REVISION 5
#define CLIENT_VERSION_BUILD 0

// Converts the parameter X to a string after macro replacement on X has been performed.
Expand Down
69 changes: 49 additions & 20 deletions src/fortunastake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ void ProcessMessageFortunastake(CNode* pfrom, std::string& strCommand, CDataStre
return;
}

if(fDebug) printf("dsee - Got NEW fortunastake entry %s\n", addr.ToString().c_str());
if(fDebugFS) printf("dsee - Got NEW fortunastake entry %s\n", addr.ToString().c_str());

// make sure it's still unspent
// - this is checked later by .check() in many places and by ThreadCheckForTunaPool()
std::string vinError;
if(CheckFortunastakeVin(vin,vinError)){
if (fDebugNet) printf("dsee - Accepted input for fortunastake entry %i %i\n", count, current);

if(GetInputAge(vin) < (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)){
if(GetInputAge(vin, pindexBest) < (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)){
if (fDebugNet) printf("dsee - Input must have least %d confirmations\n", (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS));
Misbehaving(pfrom->GetId(), 20);
return;
Expand All @@ -199,12 +199,11 @@ void ProcessMessageFortunastake(CNode* pfrom, std::string& strCommand, CDataStre
if(count == -1 && !isLocal)
RelayForTunaElectionEntry(vin, addr, vchSig, sigTime, pubkey, pubkey2, count, current, lastUpdated, protocolVersion);

// mn.UpdateLastPaidBlock(pindex, 1000); // do a search back 1000 blocks when receiving a new fortunastake to find their last payment
int value;
int payments = mn.UpdateLastPaidAmounts(pindex, 1000, value); // do a search back 1000 blocks when receiving a new fortunastake to find their last payment, payments = number of payments received, value = amount
if (payments > 0) {
printf("Registered new fortunastake %s(%i/%i) - paid %d times for %f D\n", addr.ToString().c_str(), count, current, payments, value);
}
// no need to look up the payment amounts right now, they aren't eligible for payment now anyway
//int payments = mn.UpdateLastPaidAmounts(pindex, 1000, value); // do a search back 1000 blocks when receiving a new fortunastake to find their last payment, payments = number of payments received, value = amount

if (fDebugFS) printf("Registered new fortunastake %s (%i/%i)\n", addr.ToString().c_str(), count, current);

vecFortunastakes.push_back(mn);

} else {
Expand Down Expand Up @@ -327,11 +326,11 @@ void ProcessMessageFortunastake(CNode* pfrom, std::string& strCommand, CDataStre
if(vin == CTxIn()){
mn.Check(true);
if(mn.IsEnabled()) {
if(fDebug) printf("dseg - Sending fortunastake entry - %s \n", mn.addr.ToString().c_str());
if(fDebugFS && fDebugNet) printf("dseg - Sending fortunastake entry - %s \n", mn.addr.ToString().c_str());
pfrom->PushMessage("dsee", mn.vin, mn.addr, mn.sig, mn.now, mn.pubkey, mn.pubkey2, count, i, mn.lastTimeSeen, mn.protocolVersion);
}
} else if (vin == mn.vin) {
if(fDebug) printf("dseg - Sending fortunastake entry - %s \n", mn.addr.ToString().c_str());
if(fDebugFS && fDebugNet) printf("dseg - Sending fortunastake entry - %s \n", mn.addr.ToString().c_str());
pfrom->PushMessage("dsee", mn.vin, mn.addr, mn.sig, mn.now, mn.pubkey, mn.pubkey2, count, i, mn.lastTimeSeen, mn.protocolVersion);
printf("dseg - Sent 1 fortunastake entries to %s\n", pfrom->addr.ToString().c_str());
return;
Expand Down Expand Up @@ -432,11 +431,23 @@ struct CompareLastPay
bool operator()(const pair<int, CFortunaStake*>& t1,
const pair<int, CFortunaStake*>& t2) const
{
if (t2.second->nTimeRegistered > pindex->GetBlockHash()) return true;
return (t1.second->payValue == t2.second->payValue ? t1.second->CalculateScore(1, pindex->nHeight) > t2.second->CalculateScore(1, pindex->nHeight) : t1.second->payValue > t2.second->payValue);
}
CBlockIndex* pindex;
};

struct CompareSigTimeTo
{
CompareSigTimeTo(CBlockIndex* pindex) { this->pindex = pindex; }
bool operator()(const pair<int, CFortunaStake*>& t1,
const pair<int, CFortunaStake*>& t2) const
{
return (t2.second->nTimeRegistered > pindex->GetBlockTime() && t1.second->nTimeRegistered == t2.second->nTimeRegistered ? t1.second->CalculateScore(1, pindex->nHeight) > t2.second->CalculateScore(1, pindex->nHeight) : t2.second->nTimeRegistered > pindex->GetBlockTime());
}
CBlockIndex* pindex;
};

struct CompareLastPayValue
{
bool operator()(const pair<int, CFortunaStake*>& t1,
Expand Down Expand Up @@ -516,8 +527,10 @@ bool GetFortunastakeRanks(CBlockIndex* pindex)
if (!pindex || IsInitialBlockDownload() || pindex->GetBlockTime() < GetTime() - 30*nCoinbaseMaturity) return true;

vecFortunastakeScores.clear();
int i;
int i = 0;
if (vecFortunastakeScoresListHash == pindex->GetBlockHash()) {
// if ScoresList was calculated for the current pindex hash, then just use that list
// TODO: make a vector of these somehow
BOOST_FOREACH(CFortunaStake& mn, vecFortunastakeScoresList)
{
i++;
Expand All @@ -531,6 +544,10 @@ bool GetFortunastakeRanks(CBlockIndex* pindex)
mn.Check();
if(mn.protocolVersion < MIN_MN_PROTO_VERSION) continue;

// check the block time against the entry and don't use it if it's newer than the current block time + 600 secs
// stops new stakes from being calculated in rank lists until the time of their first seen broadcast
// if (mn.now > pindex->GetBlockTime()) continue;

int value = -1;
// CBlockIndex* pindex = pindexBest; // don't use the best chain, use the chain we're asking about!
int payments = mn.UpdateLastPaidAmounts(pindex, max(FORTUNASTAKE_FAIR_PAYMENT_MINIMUM, (int)mnCount) * FORTUNASTAKE_FAIR_PAYMENT_ROUNDS, value); // do a search back 1000 blocks when receiving a new fortunastake to find their last payment, payments = number of payments received, value = amount
Expand All @@ -545,17 +562,26 @@ bool GetFortunastakeRanks(CBlockIndex* pindex)
// NO MORE TODO: Store the Scores vector in a caching hash map, maybe need hashPrev as well to make sure it re calculates any different chains with the same end block?
//vecFortunastakeScoresCache.insert(make_pair(pindex->GetBlockHash(), vecFortunastakeScoresList));

sort(vecFortunastakeScores.rbegin(), vecFortunastakeScores.rend(), CompareLastPay(pindex)); // sort requires current pindex as pindexBest is different between clients

sort(vecFortunastakeScores.rbegin(), vecFortunastakeScores.rend(), CompareLastPay(pindex)); // sort requires current pindex for modulus as pindexBest is different between clients
// put mn's that are new to last rank
i = 0;
BOOST_FOREACH(CFortunaStake& mn, vecFortunastakeScoresList)
{
i++;
if (mn.nTimeRegistered > pindex->GetBlockTime()) {
vecFortunastakeScores.push_back(vecFortunastakeScores[i]);
vecFortunastakeScores.erase(vecFortunastakeScores.begin() + i);
}
}

return true;
}

int GetFortunastakeRank(CFortunaStake &tmn, int64_t nBlockHeight, int minProtocol)
int GetFortunastakeRank(CFortunaStake &tmn, CBlockIndex* pindex, int minProtocol)
{
if (IsInitialBlockDownload()) return 0;
LOCK(cs_fortunastakes);
GetFortunastakeRanks(pindexBest);
GetFortunastakeRanks(pindex);
unsigned int i = 0;

BOOST_FOREACH(PAIRTYPE(int, CFortunaStake*)& s, vecFortunastakeScores)
Expand Down Expand Up @@ -685,8 +711,10 @@ int CFortunaStake::GetPaymentAmount(const CBlockIndex *pindex, int nMaxBlocksToS
int matches = 0;
BOOST_FOREACH(PAIRTYPE(int, int64_t) &item, payData)
{
amount += item.second;
matches++;
if (item.first > pindex->nHeight - nMaxBlocksToScanBack) { // find payments in last scanrange
amount += item.second;
matches++;
}
}
//printf("done checking for matches: %d found with %s value\n", matches, FormatMoney(amount).c_str());
if (matches > 0) {
Expand Down Expand Up @@ -730,7 +758,9 @@ int CFortunaStake::GetPaymentAmount(const CBlockIndex *pindex, int nMaxBlocksToS
int CFortunaStake::UpdateLastPaidAmounts(const CBlockIndex *pindex, int nMaxBlocksToScanBack, int &value)
{
if (!pindex || IsInitialBlockDownload()) return 0;
if(!pindex) return 0;
if (now > pindex->GetBlockTime()) return 0; // don't update paid amounts for nodes before the block they broadcasted on

if (payData.size()) return 0; // let's only do the payData once, it is cleared if the chain is reorged

const CBlockIndex *BlockReading = pindex;
int scanBack = max(FORTUNASTAKE_FAIR_PAYMENT_MINIMUM, (int)mnCount) * FORTUNASTAKE_FAIR_PAYMENT_ROUNDS;
Expand All @@ -747,7 +777,6 @@ int CFortunaStake::UpdateLastPaidAmounts(const CBlockIndex *pindex, int nMaxBloc
// reset counts
payCount = 0;
payValue = 0;
payData.clear();

LOCK(cs_fortunastakes);
for (int i = 0; i < scanBack; i++) {
Expand Down Expand Up @@ -795,7 +824,7 @@ int CFortunaStake::UpdateLastPaidAmounts(const CBlockIndex *pindex, int nMaxBloc
// set the node's current 'reward rate' - pay value divided by rounds (3)
payRate = (payValue / scanBack)*100;

if (fDebug) printf("CFortunaStake::UpdateLastPaidAmounts -- MN %s in last %d blocks was paid %d times for %s D, rate:%s count:%d val:%s\n", address2.ToString().c_str(), scanBack, rewardCount, FormatMoney(rewardValue).c_str(), FormatMoney(payRate).c_str(), payCount, FormatMoney(payValue).c_str());
if (fDebugFS) printf("CFortunaStake::UpdateLastPaidAmounts -- MN %s in last %d blocks was paid %d times for %s D, rate:%s count:%d val:%s\n", address2.ToString().c_str(), scanBack, rewardCount, FormatMoney(rewardValue).c_str(), FormatMoney(payRate).c_str(), payCount, FormatMoney(payValue).c_str());

return rewardCount;
} else {
Expand Down
14 changes: 8 additions & 6 deletions src/fortunastake.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CFortunaStake
int nBlockLastPaid;
int64_t nTimeLastChecked;
int64_t nTimeLastPaid;
int64_t nTimeRegistered;


//the dsq count from the last dsq broadcast of this node
Expand All @@ -121,6 +122,7 @@ class CFortunaStake
nBlockLastPaid = 0;
nTimeLastChecked = 0;
nTimeLastPaid = 0;
nTimeRegistered = newNow;
}

uint256 CalculateScore(int mod=1, int64_t nBlockHeight=0);
Expand Down Expand Up @@ -167,16 +169,16 @@ class CFortunaStake
return enabled == 1;
}

int GetFortunastakeInputAge()
int GetFortunastakeInputAge(CBlockIndex* pindex=pindexBest)
{
if(pindexBest == NULL) return 0;
if(pindex == NULL) return 0;

if(cacheInputAge == 0){
cacheInputAge = GetInputAge(vin);
cacheInputAgeBlock = pindexBest->nHeight;
cacheInputAge = GetInputAge(vin, pindex);
cacheInputAgeBlock = pindex->nHeight;
}

return cacheInputAge+(pindexBest->nHeight-cacheInputAgeBlock);
return cacheInputAge+(pindex->nHeight-cacheInputAgeBlock);
}
};

Expand All @@ -186,7 +188,7 @@ class CFortunaStake
int GetCurrentFortunaStake(int mod=1, int64_t nBlockHeight=0, int minProtocol=CFortunaStake::minProtoVersion);

int GetFortunastakeByVin(CTxIn& vin);
int GetFortunastakeRank(CFortunaStake& tmn, int64_t nBlockHeight=0, int minProtocol=CFortunaStake::minProtoVersion);
int GetFortunastakeRank(CFortunaStake& tmn, CBlockIndex* pindex, int minProtocol=CFortunaStake::minProtoVersion);
int GetFortunastakeByRank(int findRank, int64_t nBlockHeight=0, int minProtocol=CFortunaStake::minProtoVersion);
bool GetFortunastakeRanks(CBlockIndex* pindex=pindexBest);

Expand Down
8 changes: 5 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,18 +568,20 @@ bool AppInit2()

fDebug = GetBoolArg("-debug");

// - debug implies fDebug*, unless otherwise specified
// - debug implies fDebug*, unless otherwise specified, except net/fs/smsg since they are -really- noisy.
if (fDebug)
{
SoftSetBoolArg("-debugnet", true);
SoftSetBoolArg("-debugsmsg", true);
SoftSetBoolArg("-debugnet", false);
SoftSetBoolArg("-debugfs", false);
SoftSetBoolArg("-debugsmsg", false);
SoftSetBoolArg("-debugchain", true);
SoftSetBoolArg("-debugringsig", true);
};

fDebugNet = GetBoolArg("-debugnet");
fDebugSmsg = GetBoolArg("-debugsmsg");
fDebugChain = GetBoolArg("-debugchain");
fDebugFS = GetBoolArg("-debugfs");
fDebugRingSig = GetBoolArg("-debugringsig");

fNoSmsg = GetBoolArg("-nosmsg");
Expand Down
Loading

0 comments on commit 574d0e9

Please sign in to comment.