Skip to content

Commit

Permalink
Rewards changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thesolarminer committed Feb 8, 2021
1 parent e06ec13 commit 9ae7742
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "SmartCash Core is not connected!");

// if (IsInitialBlockDownload() && !fDebug)
// throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "SmartCash is downloading blocks...");
if (IsInitialBlockDownload() && !fDebug)
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "SmartCash is downloading blocks...");

if (!smartnodeSync.IsSynced() && !fDebug)
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "SmartCash is syncing with network...");
Expand Down
74 changes: 63 additions & 11 deletions src/smartrewards/rewardspayments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ CSmartRewardResultEntryPtrList SmartRewardPayments::GetPayments(const CSmartRewa
// As ennd index we use the startIndex + number of payees for this round.
size_t nEndIndex = nStartIndex + nFinalBlockPayees;
// If for any reason the calculations end up in an overflow of the vector return an error.
/* if( nEndIndex > pResult->payouts.size() ){
if( nEndIndex > pResult->payouts.size() ){
// Should not happen!
result = SmartRewardPayments::DatabaseError;
return CSmartRewardResultEntryPtrList();
}
*/

// Finally return the subvector with the payees of this blockHeight!
return CSmartRewardResultEntryPtrList(pResult->payouts.begin() + nStartIndex, pResult->payouts.begin() + nEndIndex);
}
Expand Down Expand Up @@ -139,27 +139,40 @@ SmartRewardPayments::Result SmartRewardPayments::Validate(const CBlock& block, i
smartReward = 109307197536547;
return SmartRewardPayments::Valid;
}
/* if (nHeight == 1794799) {
smartReward = 264681879999584;
if (nHeight == 1992799) {
smartReward = 66590668213606;
return SmartRewardPayments::Valid;
}
if (nHeight == 1992804) {
smartReward = 69767403092764;
return SmartRewardPayments::Valid;
}
if (nHeight == 1992809) {
smartReward = 68993894112460;
return SmartRewardPayments::Valid;
}
if (nHeight == 1992814) {
smartReward = 32976434780252;
return SmartRewardPayments::Valid;
}
if (nHeight == 2003814) {
smartReward = 16647722035004;
return SmartRewardPayments::Valid;
}*/
/* if (nHeight == 2025799) {
smartReward = 10009307197536547;
}

if (nHeight == 2025799) {
smartReward = 1009307197536547;
return SmartRewardPayments::Valid;
}
if (nHeight == 2025804) {
smartReward = 10009307197536547;
smartReward = 1009307197536547;
return SmartRewardPayments::Valid;
}
if (nHeight == 2025809) {
smartReward = 10009307197536547;
smartReward = 1009307197536547;
return SmartRewardPayments::Valid;
}
*/ if (nHeight == 2025814) {
if (nHeight == 2025814) {
smartReward = 30336530615942;
return SmartRewardPayments::Valid;
}
Expand All @@ -170,6 +183,44 @@ SmartRewardPayments::Result SmartRewardPayments::Validate(const CBlock& block, i

smartReward = 0;

const CTransaction &txCoinbase = block.vtx[0];

CSmartRewardResultEntryPtrList rewards = SmartRewardPayments::GetPaymentsForBlock(nHeight, block.GetBlockTime(), result);

if( result == SmartRewardPayments::Valid && rewards.size() ) {

LogPrintf("ValidateRewardPayments -- found rewardblock at height %d with %d payees\n", nHeight, rewards.size());

for( auto payout : rewards )
{
if( payout->reward == 0 ) continue;

// Search for the reward payment in the transactions outputs.
auto isInOutputs = std::find_if(txCoinbase.vout.begin(), txCoinbase.vout.end(), [payout](const CTxOut &txout) -> bool {
return payout->entry.id.GetScript() == txout.scriptPubKey && abs(payout->reward - txout.nValue) < 10000000;
});

// If the payout is not in the list?
if( isInOutputs == txCoinbase.vout.end() ){
LogPrintf("ValidateRewardPayments -- missing payment %s",payout->ToString() );
result = SmartRewardPayments::InvalidRewardList;
// We could return here..But lets print which payments else are missing.
// return result;
}else{
smartReward += isInOutputs->nValue;
}
}

}else if( result == SmartRewardPayments::NotSynced || result == SmartRewardPayments::NoRewardBlock ){
// If we are not synced yet, our database has any issue (should't happen), or the asked block
// if no expected reward block just accept the block and let the rest of the network handle the reward validation.
result = SmartRewardPayments::Valid;
}

return result;
}

/*
CSmartRewardResultEntryPtrList rewards = SmartRewardPayments::GetPaymentsForBlock(nHeight, block.GetBlockTime(), result);
if (result == SmartRewardPayments::Valid && rewards.size()) {
const CTransaction &txCoinbase = block.vtx[0];
Expand Down Expand Up @@ -230,11 +281,12 @@ SmartRewardPayments::Result SmartRewardPayments::Validate(const CBlock& block, i
pResult->round.GetPayeeCount(), remainingPayouts.size());
result = SmartRewardPayments::InvalidRewardList;
}
} else if (fLiteMode || (nHeight < 2015000 && nHeight > 1783799 /*1992804*/) || result == SmartRewardPayments::NoRewardBlock) {
} else if (fLiteMode || (nHeight < 2015000 && nHeight > 1783799) || result == SmartRewardPayments::NoRewardBlock) {
// If we are not synced yet, our database has any issue (should't happen), or the asked block
// if no expected reward block just accept the block and let the rest of the network handle the reward validation.
result = SmartRewardPayments::Valid;
}
return result;
}
*/
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
static const int PROTOCOL_BASE_VERSION = 90000;
static const int PROTOCOL_MAX_VERSION = 90000 + 0xFF;

static const int PROTOCOL_VERSION = 90032; //90032 Enforces SAPI
static const int PROTOCOL_VERSION = 90033; //90032 Enforces SAPI

//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 90013;
Expand Down

0 comments on commit 9ae7742

Please sign in to comment.